源码说明

本代码可实现通过解析官网视频链接,如腾讯、爱奇艺、优酷、乐视等等,自动去调用对应资源站相关视频,实现 json输出,可以用于各大解析系统,目前支持 爱奇艺,腾讯等规则,也可以直接搜索电影名称!

代码如下,也可直接下载附件:

<?php
/**
 * @Auth: cloudhai 
 * @Param: url 视频链接 name 视频名称

 * 例如 /?url=视频地址 /?name=视频名称
 */
header('Access-Control-Allow-Origin:*'); // *代表允许任何网址请求
if($_GET['url']){
    start($_GET['url']);
}elseif($_GET['name']){
    $data = [
        'name' => $_GET['name'],
        'js'   => $_GET['js'] ? $_GET['js'] : $_GET['js'] = '',
    ];
    getzyw($data);
}else{
    die('??????');
}

/**
 * @函数:获取标题信息
 */
function start($url){
    $video = getName($url);
    getzyw($video);
}

function getName($url)
{
    if(strstr($url,'v.qq.com')){
        $data = httpget($url,$_SERVER['HTTP_REFERER']);
        return tx($data);
    }elseif (strstr($url,'iqiyi.com')) {
        $data = httpget($url,$_SERVER['HTTP_REFERER']);
        return iqiyi($data);
    }elseif (strstr($url,'youku.com')) {
        $referer = 'v.youku.com';
        $data = httpget($url,$referer);
        return youku($data);
    }
}

/**
 * @规则:腾讯
 */
function tx($data){
    preg_match_all("/<title>(.*)<\/title>/", $data, $wdata);
    $str = $wdata[1][0];
    $srtay = explode('_',$str);
    preg_match("/(\d{1,4})[集|期]/",$srtay[0],$arr);
    $video['name'] = $srtay[0];
    if(preg_match("/\((.*)\)/",$video['name'],$d)){
        $video['name'] = str_replace($d[0],'',$video['name']);
    }
    if(explode("第",$video['name'])){
        $cd = explode("第",$video['name']);
        $video['name'] = $cd[0];
    }
    if($arr[1]){
        $title = explode(' ',$video['name']);
        $video['name'] = $title[0];
        $video['js'] = (int)$arr[1];
    }
    return $video;
}

/**
 * @规则:爱奇艺
 */
function iqiyi($data){
    preg_match_all("/<title>(.*)<\/title>/", $data, $wdata);
    $str = $wdata[1][0];
    $srtay = explode('-',$str);
    $video['name'] = $srtay[0];
    preg_match("/(\d{1,4})[集|期]/",$srtay[0],$arr);
    if($arr[1]){
        $title = explode('第',$video['name']);
        $video['name'] = $title[0];
        $video['js'] = (int)$arr[1];
    }
    return $video;
}

/**
 * @函数:请求资源网
 */
function getzyw($video){    
    $wd = $video['name'];
    //此处设置苹果cms资源网!
    $url = "http://v2.cqzyw.net:11222/api.php/provide/vod/at/json/?ac=videolist&wd=$wd";
    $data = httpget($url);
    $json = json_decode($data,true);
    $json = getvideo($json);
    if($json['code'] == 200){
        if($video['js']){
            $videoname = $json['video'][0]['name'].'第'.$video['js'].'集';
            $videourl = $json['video'][0]['url'][$video['js']];
            if(strstr($videourl,'.m3u8')){
                $videotype = 'm3u8';
            }elseif(strstr($videourl,'.mp4')){
                $videotype = 'mp4';
            }else{
                $videotype = 'h5';
            }
        }else{
            $videourl = $json['video'][0]['url'][1];
            $videoname = $json['video'][0]['name'];
            if(strstr($videourl,'.m3u8')){
                $videotype = 'm3u8';
            }elseif(strstr($videourl,'.mp4')){
                $videotype = 'mp4';
            }else{
                $videotype = 'h5';
            }
        }
        $videodata = [
            'code' => 200,
            'msg'  => 'success',
            'name' => $videoname,
            'type' => $videotype,
            'url'  => $videourl,
        ];
    }else{
        $videodata = [
            'code' => 404,
            'msg'  => '未找到相关资源',
        ];
    }
    
    die(json_encode($videodata,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
}

/**
 * @函数:分析json
 */
function getvideo($data){
     if($data['total']){
        foreach($data['list'] as $k=>$v){
            $video[$k]['name']  = $v['vod_name'];
            $video[$k]['pic']   = $v['vod_pic'];
            $video[$k]['actor'] = $v['vod_actor'];
            $video[$k]['blurb'] = $v['vod_blurb'];
            $video[$k]['type']  = $v['vod_remarks'];
            $videonum = substr_count($v['vod_play_url'],'$');
            if($videonum>1){
                $url = array();
                $vipurl = explode('#',$v['vod_play_url']);
                foreach ($vipurl as $key=>$value){
                    $value = explode('$',$value);
                    $url[$key+1] = $value[1];
                }
            }else{
                $url = array();
                $vip = explode('$',$v['vod_play_url']);
                $url['vip'] = $vip[1];
            }
            $video[$k]['url'] = $url;
        }
        $json = [
                'code'  => 200,
                'msg'   => '一共找到'.count($data['list']).'条资源',
                'num'   => count($data['list']),
                'video' => $video,
        ];
    }else{
        $json = [
            'code'  => 404,
            'msg'   => '没有找到该资源',
        ];
    }
    return $json;
}

/**
 * @函数:http 请求
 */
function httpget($url)
{
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt( $ch, CURLOPT_REFERER, 'https://v.youku.com');
    curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5' );
    // curl_setopt( $ch, CURLOPT_POST, 1); //设置为POST方式
    // curl_setopt( $ch, CURLOPT_POSTFIELDS, array()); //数据传输
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 ); //解决重定向问题
    curl_setopt( $ch, CURLOPT_COOKIE, 'redirectLogin=3;t=1766da7fa03df9fdb66af1ebaa160ecc;');
    $contents = curl_exec($ch);
    $error = curl_error($ch);
    if($error){
        $error = 'Error: '.$error;
        file_put_contents('./Error.txt',$error);
    }
    // 关闭一个curl会话
    curl_close($ch);
    return $contents;
}

调用方式

域名调用  http://你的域名/v.php?url=

名称调用  http://你的域名/v.php?name=

相关应用

[ri-post id="9016" thumb="left"] [ri-post id="23142" thumb="left"]
1.使用本站下载的源码仅限于个人学习和非商业用途。
2.禁止将本站下载的源码用于搭建或支持任何违法、淫秽、暴力或侵犯他人合法权益的网站或应用。
3.使用本站下载的源码需遵守国家法律法规及相关规定,不得从事任何违法活动。
4.如若本站内容侵犯了原著者的合法权益,请联系我们进行处理。