add download feature
This commit is contained in:
@@ -406,4 +406,67 @@ function getVideoComments($videoId) {
|
||||
|
||||
return $response['data'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les options de téléchargement pour une vidéo
|
||||
* @param string $videoId ID de la vidéo
|
||||
* @return array Options de téléchargement
|
||||
*/
|
||||
function getVideoDownloadOptions($videoId) {
|
||||
// Récupérer les informations complètes de la vidéo
|
||||
$videoData = callPeerTubeApi('videos/' . $videoId);
|
||||
|
||||
$downloadOptions = [];
|
||||
|
||||
// Ajouter les fichiers directs s'ils existent
|
||||
if (isset($videoData['files']) && !empty($videoData['files'])) {
|
||||
foreach ($videoData['files'] as $file) {
|
||||
if (isset($file['fileDownloadUrl']) && !empty($file['fileDownloadUrl'])) {
|
||||
$downloadOptions[] = [
|
||||
'type' => 'direct',
|
||||
'url' => PEERTUBE_URL . $file['fileDownloadUrl'],
|
||||
'resolution' => isset($file['resolution']['label']) ? $file['resolution']['label'] : 'Original',
|
||||
'size' => isset($file['size']) ? formatFileSize($file['size']) : 'Inconnu'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter les playlists de streaming s'ils existent
|
||||
if (isset($videoData['streamingPlaylists']) && !empty($videoData['streamingPlaylists'])) {
|
||||
foreach ($videoData['streamingPlaylists'] as $playlist) {
|
||||
if (isset($playlist['files']) && !empty($playlist['files'])) {
|
||||
foreach ($playlist['files'] as $file) {
|
||||
if (isset($file['fileDownloadUrl']) && !empty($file['fileDownloadUrl'])) {
|
||||
$downloadOptions[] = [
|
||||
'type' => 'hls',
|
||||
'url' => $file['fileDownloadUrl'],
|
||||
'resolution' => isset($file['resolution']['label']) ? $file['resolution']['label'] : 'Original',
|
||||
'size' => isset($file['size']) ? formatFileSize($file['size']) : 'Inconnu'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $downloadOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formate la taille d'un fichier en format lisible
|
||||
* @param int $bytes Taille en octets
|
||||
* @return string Taille formatée
|
||||
*/
|
||||
function formatFileSize($bytes) {
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
$bytes = max($bytes, 0);
|
||||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
||||
$pow = min($pow, count($units) - 1);
|
||||
|
||||
$bytes /= (1 << (10 * $pow));
|
||||
|
||||
return round($bytes, 2) . ' ' . $units[$pow];
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user