如何使用简单的HTML dom解析器或任何其他方法而不是YouTube api从YouTube频道获取直播视频id?
https://www.youtube.com/embed/live_stream?channel=UC8Z-VjXBtDJTvq6aqkIskPg&autoplay=1因为YouTube接口无法获取直播视频id。
发布于 2019-09-23 14:29:58
最后我给出了答案
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;
}https://stackoverflow.com/questions/58040154
复制相似问题