php - 如何从 youtube 频道 html 获取实时视频 ID
问题描述
如何使用简单的 HTML dom 解析器或任何其他方法而不是 YouTube api 从 YouTube 频道获取实时视频 ID?
https://www.youtube.com/embed/live_stream?channel=UC8Z-VjXBtDJTvq6aqkIskPg&autoplay=1
因为 YouTube api 无法获取实时视频 ID。
解决方案
最后我资助答案
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;
}
推荐阅读
- java - 从groovy中的JSON数组中提取特定数据
- oracle - SQL获取列的总数或总和
- c++ - 无法访问公共功能?没有成员命名?
- python - 如何从每行中的字符串中提取年份并使用这些年份生成新行
- cookies - 与 PC 上的所有用户共享 Win10 IE 11 cookie
- r - 我需要帮助弄清楚为什么我的正则表达式与我正在寻找的内容不匹配
- javascript - 如何断言复制到剪贴板的值是正确的?
- amazon-web-services - 为什么将我的云形成设计器保存到 S3 存储桶会挂起?
- matlab - S-Function Level 2 C Simulink (R2006b) , 从参数中获取字符串
- javascript - 具有高阶函数的递归