Reputation: 470
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
$output = shell_exec('youtube-dl -J https://www.youtube.com/playlist?list=PLANMHOrJaFxPCjR2enLZBRgtZgjtXJ0MJ' );
$youtubeId = json_decode($output);
$youtubeId = $youtubeId->webpage_url;
echo $youtubeId;
Upvotes: 2
Views: 5871
Reputation: 958
For a playlist and the -J
option, you must loop through the 'entries' array.
$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.
You may use --playlist-items 1-3
to restrict grabbed videos to e.g. the 1st through 3rd vids of a playlist.
For all available command line options see here.
Upvotes: 2