腾讯视频解析带分段

不能解析VIP,不能解析VIP,不能解析VIP。重要的事情说三遍,如果像看VIP碰巧您的爱机又是安卓的话可以看看:火眼视频APP

<?php
//error_reporting(0);
$vid = $_GET['vid'];
$platforms = [11];
$options = array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    )
);
$arrInfo = [];
foreach ($platforms as $platform) {
    $info_api = "http://vv.video.qq.com/getinfo?otype=json&appver=3.2.19.333&platform={$platform}&defnpayver=1&defn=shd&vid={$vid}";
    $info = file_get_contents($info_api, false, stream_context_create($options));
    preg_match_all("/{.*}/", $info, $arr);
    if (!empty($arr[0][0])) {
        $arrInfo = json_decode($arr[0][0],true);
        if (!empty($arrInfo['msg'])) {
            echo json_encode([
                'code' => 0,
                'msg' => $arrInfo['msg']
            ]);
            die();
        }
    }
}

$fn_pre = $arrInfo['vl']['vi'][0]['lnk'];
$title = $arrInfo['vl']['vi'][0]['ti'];
$host = $arrInfo['vl']['vi'][0]['ul']['ui'][0]['url'];
$seg_cnt = $fc_cnt = $arrInfo['vl']['vi'][0]['cl']['fc'];
$filename = $arrInfo['vl']['vi'][0]['fn'];

if ($seg_cnt == 0) {
    $seg_cnt = 1;
}else{
    list($fn_pre, $magic_str, $video_type) = explode(".", $filename);
}
$part_urls = [];
$total_size = 0;

$urls = [];

for ($part = 1; $part < $seg_cnt + 1; $part++) {
    if ($fc_cnt == 0) {
        $part_format_id = end(explode('.', $arrInfo['vl']['vi'][0]['cl']['keyid']));
    }else{
        $part_format_id = explode(".", $arrInfo['vl']['vi'][0]['cl']['ci'][$part - 1]['keyid'])[1];
        $filename = implode('.', [$fn_pre, $magic_str, $part, $video_type]);
    }

    $key_api = "http://vv.video.qq.com/getkey?otype=json&platform=11&format={$part_format_id}&vid={$vid}&filename={$filename}&appver=3.2.19.333";
    $part_info = file_get_contents($key_api, false, stream_context_create($options));
    preg_match_all("/{.*}/", $part_info, $part_arr_str);
    $part_arr = json_decode($part_arr_str[0][0], true);
    if (empty($part_arr['key'])) {
        $vkey = $arrInfo['vl']['vi'][0]['fvkey'];
        $url = "{$arrInfo['vl']['vi'][0]['ul']['ui'][0]['url']}{$fn_pre}.mp4?vkey={$vkey}";
    } else {
        $vkey = $part_arr['key'];
        $url = "{$host}{$filename}?vkey={$vkey}";
    }
    $urls[] = $url;
}

$data = [
    'title' => $title,
    'urls' => $urls,
];
//echo "<video src=\"{$urls[0]}\" controls></video>";
echo json_encode($data);