/**
* Example script for downloading recording files
*/
using System;
using System.Collections.Generic;
using Plivo;
using Plivo.Exception;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace PlivoExamples
{
internal class Program
{
private const string AUTH_ID = "<auth_id>";
private const string AUTH_TOKEN = "<auth_token>";
public static async Task Main(string[] args)
{
var api = new PlivoApi(AUTH_ID,AUTH_TOKEN);
try
{
var response = api.Recording.List(
addTime_Gt: DateTime.Parse("2023-04-01 00:00:00"),
addTime_Lt: DateTime.Parse("2023-04-30 00:00:00"),
limit:5,
offset:0
);
Console.WriteLine($"Found {response.Objects.Count} recordings.");
// Directory where the recordings will be saved
string dir = "./recordings";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
foreach (var recording in response.Objects)
{
string recordingUrl = recording.RecordingUrl;
string recordingId = recording.RecordingId;
string format = recording.RecordingFormat;
Console.WriteLine("Downloading recording: " + recordingUrl);
string outputFilePath = Path.Combine(dir, recordingId + "." + format);
// Download the file
using (var httpClient = new HttpClient())
{
var fileBytes = await httpClient.GetByteArrayAsync(recordingUrl);
await File.WriteAllBytesAsync(outputFilePath, fileBytes);
}
Console.WriteLine("Downloaded file to: " + outputFilePath);
}
}
catch (PlivoRestException e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
}
}