2

当我尝试从 json 文件 ($output) 获取信息时遇到问题当我使用 youtube-dl 时。我需要我的json文件中的webpage_url 我的代码是

$output = shell_exec('youtube-dl -J https://www.youtube.com/playlist?list=PLANMHOrJaFxPCjR2enLZBRgtZgjtXJ0MJ' );
$youtubeId = json_decode($output);
$youtubeId = $youtubeId->webpage_url;

echo $youtubeId;
4

1 回答 1

1

对于播放列表和-J选项,您必须遍历“条目”数组。

$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 个视频。

有关所有可用的命令行选项,请参见此处

于 2017-06-16T00:55:33.473 回答