当我使用-get-id时,我怎样才能从json youtube-dl获取信息?

时间:2020-12-07 21:14:56

i have problem when i try to get the information from json file ($output) When i use youtube-dl . i need webpage_url from my json file my code is

当我使用youtube-dl时试图从json文件($output)获取信息时,我遇到了问题。我需要从我的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;

1 个解决方案

#1


1  

For a playlist and the -J option, you must loop through the 'entries' array.

对于播放列表和-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;
}

Each element therein contains the properties you expect, like webpage_url, as each element is a video.

其中的每个元素都包含您期望的属性,如webpage_url,因为每个元素都是一个视频。

You may use --playlist-items 1-3 to restrict grabbed videos to e.g. the 1st through 3rd vids of a playlist.

你可以使用-播放列表1-3来限制抓取视频,例如播放列表的1-3个视频。

For all available command line options see here.

对于所有可用的命令行选项,请参见这里。

#1


1  

For a playlist and the -J option, you must loop through the 'entries' array.

对于播放列表和-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;
}

Each element therein contains the properties you expect, like webpage_url, as each element is a video.

其中的每个元素都包含您期望的属性,如webpage_url,因为每个元素都是一个视频。

You may use --playlist-items 1-3 to restrict grabbed videos to e.g. the 1st through 3rd vids of a playlist.

你可以使用-播放列表1-3来限制抓取视频,例如播放列表的1-3个视频。

For all available command line options see here.

对于所有可用的命令行选项,请参见这里。