CCTV解析源码(参考)

代码相关 CCTV解析源码 CCTV解析 2018-12-4 阅读:1585

只提供参考,自行测试更多资源交流群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);
    }
}
?>
生成海报
版权声明

本文基于《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
文章链接:https://www.pohaier.com/2018/12/04/135.html (转载时请注明本文出处及文章链接)

如果觉得我的文章对你有用,请随意赞赏

5条评论

    heudxk

    求教这个文件的用法?

    用户 Windows10 64 天前回复

    爱看云主机

    厉害

    游客 安卓派 106 天前回复

    li9876

    需要

    游客 Windows10 147 天前回复

    Vxuan

    正好需要

    游客 Windows7 283 天前回复

    天仙婆婆

    你这些就是从一次解析里扒出来的吧

    游客 Windows7 427 天前回复