Reputation: 374
How to get live video id from YouTube channel using simple HTML dom parser or any other method rather than YouTube api?
https://www.youtube.com/embed/live_stream?channel=UC8Z-VjXBtDJTvq6aqkIskPg&autoplay=1
Because YouTube api does not work to get live video id.
Upvotes: 2
Views: 612
Reputation: 374
Finaly i fund answer
function getvideourl($chid)
{
$videoId = null;
// Fetch the livestream page
if($data = file_get_contents('https://www.youtube.com/embed/live_stream?
channel='.$chid))
{
// Find the video ID in there
if(preg_match('/\'VIDEO_ID\': \"(.*?)\"/', $data, $matches))
$videoId = $matches[1];
else
$videoId ="";
}
else
throw new Exception('Couldn\'t fetch data');
$video_url = "https://www.youtube.com/embed/".$videoId;
return $video_url;
}
Upvotes: 1