$output = shell_exec('youtube-dl -J https://www.youtube.com/playlist?list=PLANMHOrJaFxPCjR2enLZBRgtZgjtXJ0MJ' );
$youtubeId = json_decode($output);
$youtubeId = $youtubeId->webpage_url;
echo $youtubeId;
答案 0 :(得分:1)
对于播放列表和-J
选项,您必须遍历'entries'数组。
$output = shell_exec('youtube-dl -J --playlist-items 1-3 https://www.youtube.com/playlist?list=PLANMHOrJaFxPCjR2enLZBRgtZgjtXJ0MJ' );
$playlist = json_decode($output);
foreach ($playlist->entries as $vid) {
$youtubeId = $vid->webpage_url;
echo $youtubeId;
}
其中的每个元素都包含您期望的属性,例如webpage_url
,因为每个元素都是视频。
您可以使用--playlist-items 1-3
将抓取的视频限制为例如播放列表的第1到第3个视频。
对于所有可用的命令行选项,请参阅here。