正文
PPTV解析源码
PPTV解析源码
- <?php
- require_once(“../include/global.inc.php");
- $host = GlobalBase::is_https().$_SERVER[“HTTP_HOST"];
- if(isset($_REQUEST['url’])){
- $url = $_REQUEST['url’];
- $content = preg_replace(“#(getPlayEncode\(|\);)#",“",file_get_contents($url));
- $root = json_decode($content,true)[“childNodes"];
- //print_r($content);exit;
- $token = PPTVToKey::token();
- $videos = array();
- foreach ($root as $key => $value) {
- $tagName = $value[“tagName"];// “dt"
- if($tagName==“channel"){
- foreach ($value[“childNodes"] as $_key => $_value) {
- if($_value[“tagName"]==“file"){
- foreach ($_value[“childNodes"] as $__key => $__value) {
- $rid = $__value[“rid"];//视频文件名
- $ft = $__value[“ft"];//视频类型
- switch ($ft) {
- case 0:$def = “流畅"; break;//480X270
- case 1:$def = “高清"; break;//720X404
- case 2:$def = “超清"; break;//1280X720
- case 3:$def = “蓝光"; break;//1920X1080
- case 4:$def = “原画"; break;//1920X1080
- }
- $videos[$ft][“rid"] = str_replace(“.mp4",“",$rid);
- $videos[$ft][“def"] = $def;
- }
- }
- }
- }else if($tagName==“dt"){
- $ft = $value[“ft"];
- foreach ($value[“childNodes"] as $_key => $_value) {
- $_tagName = $_value[“tagName"];
- switch ($_tagName) {
- case 'sh’:$sh = $_value[“childNodes"][0];break;
- case 'key’:$key = $_value[“childNodes"][0];break;
- }
- }
- $videos[$ft][“sh"] = $sh;
- $videos[$ft][“key"] = $key;
- }
- }
- //if(count($videos)==5){//移除原画质
- // array_splice($videos,4,1);
- //}
- array_splice($videos,0,1); //移除流畅
- foreach ($videos as $key => $value) {
- $xml = curl(“http://drag.synacast.com/".$value[“rid"].“.mp40drag");
- preg_match_all('#duration=“(.*?)"#’,$xml,$duration);
- preg_match_all('#filesize=“(\d+)"#’,$xml,$filesize);
- $videos[$key][“dragdata"][“dur"] = $duration[1];//分段时间
- $videos[$key][“dragdata"][“fs"] = $filesize[1];//分段文件大小
- }
- $data[“data"] = $videos;
- $data[“token"] = $token;
- echo json_encode($data);
- }
- if(isset($_REQUEST['data’])&&isset($_REQUEST['vid’])){
- $data = json_encode(json_decode(base64_decode($_REQUEST['data’])));
- //print_r($_REQUEST['data’]);exit;
- file_put_contents(PPTV_TEMP_PATH.$_REQUEST['vid’].“.json",$data);
- echo “./video/pptv.php?vid=".$_REQUEST['vid’];
- }elseif(isset($_REQUEST['vid’])){
- $file = PPTV_TEMP_PATH.$_REQUEST['vid’].“.json";
- //print_r($file.’ddddddddddddddddddd’);exit;
- $data = file_get_contents($file);
- unlink($file);
- echo $data;
- }
- 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);
- }
- class PPTVToKey
- {
- public static function string($abyte2) {
- $k = “";
- for ($i=0; $i < count($abyte2); $i++) $k .= chr($abyte2[$i]);
- return trim($k);
- }
- public static function timeArray() {
- $i = 0;
- $abyte = array();
- $time = $_SERVER['REQUEST_TIME’] + 300;
- while ($i < 16) {
- $bytes;
- $abyte[$i] = 0xf & $time >> 28 – 4 * ($i % 8);
- $byte = $abyte[$i];
- if ($abyte[$i] > 9) $bytes = 87; else $bytes = 48;
- $abyte[$i] = $byte + $bytes;
- if ($i > 7 || $abyte[$i] == 0) {
- $abyte[$i] = mt_rand(1, 256);
- }
- $i++;
- }
- return $abyte;
- }
- public static function token() {
- $keyArray = array();
- $tmAray = self::timeArray();
- $tmCode = array(113, 113, 113, 113, 113, 119, 119, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- $tmAray = self::encrypt_a($tmAray, 16, $tmCode);
- $keyArray = self::encrypt_b($tmAray, 16, $keyArray, 33);
- return self::string($keyArray);
- }
- public static function keyCode($tmCode) {
- $k = 0;
- for ($i=0; $i < 16; $i++) {
- $k ^= $tmCode[$i] << 8 * ($i % 4);
- }
- return $k;
- }
- public static function b($num) {
- $a = 0xffffffff & $num;
- $b = sprintf(“%u", $a);
- return $b * 1;
- }
- public static function encrypt_a($tmArray, $i, $tmCode) {
- $l = self::keyCode($tmCode);
- $l1 = $l << 8 | $l >> 24;
- $l2 = $l << 16 | $l >> 16;
- $l3 = $l << 24 | $l >> 8;
- for ($k = 0; $k + 16 <= $i; $k += 16) {
- $l4 = 0;
- $l5 = 0;
- $l6 = 0;
- for ($i1 = 0; $i1 < 4; $i1++) {
- $l4 |= (0xff & $tmArray[$k + $i1]) << $i1 * 8;
- $l5 |= (0xff & $tmArray[4 + ($k + $i1)]) << $i1 * 8;
- }
- for ($j1 = 0; $j1 < 32; $j1++) {
- $l6 = self::b($l6 – 0x61c88647);
- $a1 = self::b($l5 << 4);
- $a2 = self::b($l + $a1);
- $a3 = self::b($l5 + $l6);
- $a4 = self::b($a2 ^ $a3);
- $a5 = self::b($l5 >> 5);
- $a6 = self::b($l1 + $a5);
- $l4 = self::b($l4 + ($a4 ^ $a6));
- $b1 = self::b($l4 << 4);
- $b2 = self::b($l2 + $b1);
- $b3 = self::b($l4 + $l6);
- $b4 = self::b($b2 ^ $b3);
- $b5 = self::b($l4 >> 5);
- $b6 = self::b($l3 + $b5);
- $l5 = self::b($l5 + ($b4 ^ $b6));
- }
- for ($k1 = 0; $k1 < 4; $k1++) {
- $tmArray[$k + $k1] = (255 & $l4 >> $k1 * 8);
- $tmArray[4 + ($k + $k1)] = (255 & $l5 >> $k1 * 8);
- }
- }
- return $tmArray;
- }
- public static function encrypt_b($tmAray, $i, $keyArray, $j) {
- for ($k = 0; $k < $i; $k++) {
- $keyArray[$k * 2] = (0xf & $tmAray[$k]);
- $keyArray[1 + $k * 2] = (0xf & $tmAray[$k] >> 4);
- }
- $l = 0;
- while ($l < $i * 2) {
- $byte1;
- $byte0 = $keyArray[$l];
- if ($keyArray[$l] > 9) {
- $byte1 = 87;
- } else {
- $byte1 = 48;
- }
- $keyArray[$l] = $byte0 + $byte1;
- $l++;
- }
- $keyArray[$i * 2] = 0;
- return $keyArray;
- }
- }
- ?>