getaudio.php 版本 1
<?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");
passthru("youtube-dl -f 140 -o - $youtubeUrl");
?>
getaudio.php 版本 2
<?php
$youtubeUrl = $_GET['url'];
$file = shell_exec("youtube-dl -f 140 --get-filename $youtubeUrl ");
header("Content-Disposition: attachment; filename=\"$file\"" );
header("Content-Type: application/octet-stream");
passthru("youtube-dl -f 140 -o - $youtubeUrl");
?>
如果 url = https://www.youtube.com/watch?v=bvYtKY-UMxA那么我们得到$file = Deewana Kar Raha Hai Full Song 1080p HD Raaz 3 2012 YouTube-bvYtKY-UMxA.m4a
我的问题是getaudio.php 版本 1工作正常,但getaudio.php 版本 2不是......
getaudio.php 版本 2正在下载,但文件已损坏....
当两个 php 文件的$file相同时,第二个文件怎么可能不起作用
提示:下载youtube-dl.exe(适用于 windows)并将其与两个 php文件放在一起并在 localhost 中运行