只提供参考,自行测试更多资源交流群516722628
<?php
$vid = CCTV::parse($url);
echo json_encode(CCTV::get_video_info($vid));
/**
*
*/
class CCTV
{
public static function parse($url)
{
$content = self::curl($url);
preg_match('#"videoCenterId","(\w+)"#',$content,$id);
$vid = $id[1];
return $vid;
}
public static function get_video_info($vid)
{
$api = "http://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid={$vid}";
$content = self::curl($api);
preg_match('#"hls_url":"(.*?)"#',$content,$data);
$hls_url = $data[1];
preg_match('#"totalLength":\s*"[\d.]+",(.*),"validChapterNum"#',$content,$video_arr);
$json = json_decode("{".$video_arr[1]."}",true);
$videos = array();
foreach ($json as $key => $value) {
if($key=="lowChapters"||$key=="chapters"){//过滤
continue;
}
switch ($key) {
case 'lowChapters':$def = "流畅";break;
case 'chapters':$def = "标清";break;
case 'chapters2':$def = "高清";break;
case 'chapters3':$def = "超清";break;
case 'chapters4':$def = "原画";break;
}
$videos_flash = array();
foreach ($value as $_key => $_value) {
$video["file"] = $_value["url"];//分段视频地址
$video["duration"] = $_value["duration"];//分段视频时间
$video["bytesTotal"] = intval("");
$videos_flash[count($videos_flash)] = $video;
}
$video_flash["video"] = $videos_flash;
$video_flash["type"] = "mp4";
$video_flash["weight"] = $key == "chapters2"?10:0;
$video_flash["definition"] = $def;
$videos[count($videos)] = $video_flash;
}
if (GlobalBase::is_ipad()) {
$videoinfo['code'] = 200;
$videoinfo['play'] = 'hls';
$videoinfo['type'] = 'cctv';
$videoinfo["data"]["url"] = self::get_video_m3u8($hls_url);
}else{
if (isset($_GET['pangu']) && $_GET['pangu']=='parse') {
$videoinfo["flashplayer"] = true;
$videoinfo["video"] = $videos;
} else {
$videoinfo['code'] = 200;
$videoinfo["data"]["flashplayer"] = true;
$videoinfo["data"]["video"] = $videos;
}
}
return $videoinfo;
}
public static function get_video_m3u8($hls_url)
{
$content = self::curl($hls_url);
$lines = preg_split('/[\r\n]+/s', $content);//按行进行分割字符串
$domain = "http://cntv.hls.cdn.myqcloud.com";
$videos = array();
foreach ($lines as $value) {
if(!empty($value)&&substr($value,0,1)!="#"){
$main = explode("/", $value);
switch ($main[3]) {
case 200:$def = "流畅";break;#320x180
case 450:$def = "标清";break;#480x270
case 850:$def = "高清";break;#640x360
case 1200:$def = "超清";break;#1280x720
case 2000:$def = "原画";break;#1280x720
}
if($main[3]==850){
$vurl = $domain.$value;
break;
}
/* $video[0] = $domain.$value;
$video[1] = "video/m3u8";
$video[2] = $def;
$video[3] = 0;
$videos[count($videos)] = $video;*/
}
}
return $vurl;
}
public static function curl($url)
{
$params["ua"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36";
return GlobalBase::curl($url,$params);
}
}
?>
5 条评论
求教这个文件的用法?
厉害
需要
正好需要
你这些就是从一次解析里扒出来的吧