1
我使用exec
php函數來運行腳本,以mp3格式抓取YouTube視頻(使用youtube-dl
)。PHP執行 - 如何只顯示最後一個命令的結果
在這個腳本的末尾,我做了一個echo
,這是我想要的結果。
但是當我啓動我的php頁面時,輸出是由所有youtbe-dl
組成的。這樣的:
[youtube] zTkS9SvhHUI: Downloading webpage
[youtube] zTkS9SvhHUI: Downloading video info webpage
[youtube] zTkS9SvhHUI: Extracting video information
[youtube] zTkS9SvhHUI: Downloading js player en_US-vflgFv_Kx
[youtube] zTkS9SvhHUI: Downloading js player en_US-vflgFv_Kx
[download] Destination: /var/www/xxx/mp3dl/Kaskade - Whatever Ft KOLAJ (NEUS Remix).webm
[download] 0.0% of 3.84MiB at 10.17KiB/s ETA 06:26
[download] 0.1% of 3.84MiB at 30.44KiB/s ETA 02:09
[. . .]
[download] 100.0% of 3.84MiB at 4.01MiB/s ETA 00:00
[download] 100% of 3.84MiB in 00:00
[ffmpeg] Destination: /var/www/xxx/mp3dl/Kaskade - Whatever Ft KOLAJ (NEUS Remix).mp3
Deleting original file /var/www/xxx/mp3dl/Kaskade - Whatever Ft KOLAJ (NEUS Remix).webm (pass -k to keep)
/var/www/xxx/mp3dl/Kaskade - Whatever Ft KOLAJ (NEUS Remix).mp3
我唯一需要的是:
/var/www/xxx/mp3dl/Kaskade - Whatever Ft KOLAJ (NEUS Remix).mp3
我怎麼能這樣做?有什麼我不明白的嗎?
編輯:有我的PHP代碼:
$url = htmlspecialchars($_POST['url']);
$choice1 = $_POST['choice1'];
$output = exec('sh scripts/ytdlmp3_direct.sh "'.$url.'"');
if(isset($_POST['action'])){
if(empty($url)) {
print("<div class='card-panel yellow'>Please add a URL</div>") ;
} else {
if($choice1 == "download") {
print $output;
} elseif($choice1 == "store") {
print "Soon";
}
}
}
謝謝! 〜昆汀