有没有办法使用 youtube-dl 获取特定格式的音频/视频文件大小


Is there a way to get the audio/video file size for a particular format using youtube-dl

<?php
    $youtubeUrl =  $_GET['url'];
    $content = shell_exec("youtube-dl -j $youtubeUrl "); 
    $meta=json_decode($content);  
    $file= $meta->{'_filename'};
    $fileWithoutExtension = explode(".",$file)[0];
    $extension = ".m4a";
    $file = $fileWithoutExtension . $extension;   
    header("Content-Disposition: attachment; filename='"$file'"" );
    header("Content-Type: application/octet-stream");
// $fize = shell_exec("youtube-dl -f 141 --get-size $URL");
// header("Content-Length: " . $fsize);
    passthru("youtube-dl -f 140 -o - $youtubeUrl");
?>

请参阅注释的行。我需要这两行。其余代码工作正常。此文件从YouTube下载音频。但是我在下载时看不到任何文件大小

因为youtube-dl没有显示大小的选项,所以你可能想看看ytdl,它可以给你所有的元数据,比如文件大小。

要安装:

$ pip install pafy
...
$ ytdl [url]
Stream Type    Format Quality         Size            
------ ----    ------ -------         ----            
1      normal  webm   [640x360]       21 MB           
2      normal  mp4    [640x360]       24 MB           
3      normal  flv    [320x240]       19 MB           
4      normal  3gp    [320x240]       15 MB           
5      normal  3gp    [176x144]        5 MB 
...

(https://pypi.python.org/pypi/pafy (