<?php
/**
* Example script for downloading recording files
*/
require '../../vendor/autoload.php';
use Plivo\RestClient;
use Plivo\Exceptions\PlivoRestException;
use GuzzleHttp\Client;
$AUTH_ID = "<auth_id>";
$AUTH_TOKEN = "<auth_token>";
$client = new RestClient($AUTH_ID,$AUTH_TOKEN);
try {
$response = $client->recordings->list(
[
'add_time__gt' => "2023-04-01 00:00:00",
'add_time__lt' => "2023-04-30 00:00:00",
'limit' => 5,
'offset' => 0
]
);
echo "Found " . count($response->resources) . " recordings." . PHP_EOL;
// Directory where the recordings will be saved
$dir = "./recordings";
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$http = new Client();
foreach ($response as $recording) {
$recording_url = $recording->recordingUrl;
$recording_id = $recording->recordingId;
$format = $recording->recordingFormat;
echo "Downloading recording: " . $recording_url . PHP_EOL;
$output_file = $dir . "/" . $recording_id . "." . $format;
// Download the file
$http->get($recording_url, ['sink' => $output_file]);
echo "Downloaded file to: " . $output_file . PHP_EOL;
}
}
catch (PlivoRestException $ex) {
print_r($ex);
}