有没有办法使用 youtube-dl 获取特定格式的 audio/video 文件大小
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
...
<?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
...