Btjson博客 Btjson博客

CCTV解析源码(参考)

in 技术文章 read (582) 文章转载请注明来源!

只提供参考,自行测试更多资源交流群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);
    }
}
?>
jrotty WeChat Pay

微信打赏

jrotty Alipay

支付宝打赏

文章二维码

扫描二维码,在手机上阅读!

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

技术文章
发表新评论
仅有 1 条评论
  1. 天仙婆婆
    天仙婆婆 7搜狗浏览器
    回复

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

博客已萌萌哒运行
© 2019 由 Typecho 强力驱动.Theme by btjson
PREVIOUS NEXT
雷姆
拉姆