function yk_list_begin($vid) { $url = API . $vid . APP; $ur = API . $vid; $bhtml = getbody($ur); $bjson = json_decode($bhtml); $bdata = $bjson->data[0]; $html = getbody($url); $json = json_decode($html); $data = $json->data[0]; $second = $data->seconds; $fileids = $data->streamfileids; if (property_exists($fileids, 'mp4')) { $format = 'mp4'; } else { $format = 'flv'; } $fileid = $fileids->{$format}; $segs = $data->segs->{$format}; $bsegs = $bdata->segs->{$format}; $bytes = $data->streamsizes->{$format}; $fileid = yk_file_id($fileid, $data->seed); $fileid_1 = substr($fileid, 0, 8); $fileid_2 = substr($fileid, 10); list($sid, $token) = explode('_', yk_e('becaf9be', yk_na($data->ep))); $xmls = '<m starttype="0" label="" type="2" bytes="' . $bytes . '" duration="' . $second . '" bg_video="{xywh:[0,0,100P,100P]}">' . ' '; $xml = ''; foreach ($segs as $k => $v) { $hex = strtoupper(dechex($k)) . ''; if (strlen($hex) < 2) { $hex = '0' . $hex; } $fileid = $fileid_1 . $hex . $fileid_2; $key = $v->k; if (!$key || $key == '' || $key == '-1') { $key = $bsegs[$k]->k; } $ep = urlencode(iconv('gbk', 'UTF-8', yk_d(yk_e('bf7e5f01', $sid . '_' . $fileid . '_' . $token)))); $tvaddr = KUR . $sid . '_00/st/' . $format . '/fileid/' . $fileid . '?K=' . $key . '&hd=1&myp=0&ts='; $tvaddr .= $v->seconds . '&ypp=0&ctype=12&ev=1&token=' . $token . '&oip=' . $data->ip . '&ep=' . $ep; $xml .= '<u bytes="' . $v->size . '" duration="' . $v->seconds . '" src="' . $tvaddr . '" label="' . $k . '" />' . ' '; } if ($xml !== '') { header('Content-type:text/xml;charset=utf-8'); return $xmls . $xml . '</m>'; } }
function getyk($vid, $qxd) { $api = "http://play.youku.com/play/get.json"; $app = "&ran="; $ctype = "&ct=" . chr(dechex(bindec(X))) . chr(dechex(bindec(Y))); $kurl = "http://k.youku.com/player/getFlvPath/sid/"; $url = $api . "?vid=" . $vid . $ctype . $app . rand(0, 9999); $html = get_curl_contents($url); $jdata = json_decode($html); $jdata1 = $jdata->data; $oip = $jdata1->security->ip; $ep = $jdata1->security->encrypt_string; if ($ep == "") { return "视频不存在!"; exit; } $stream = $jdata1->stream; $st = explode('_', yk_e('becaf9be', yk_na($ep))); $sid = $st[0]; $token = $st[1]; if ($sid == "") { echo "sidnull"; return; } if ($token == "") { echo "tokennull"; return; } $definition = $stream; // 当没有传指定清晰度的值的时候,默认输出最高清晰度,所以需要循环视频所有清晰度,然后再取最后一个清晰度。 // 定义一个数组用来存放清晰度数据 $types = array(); // 用foreach循环来把获得的清晰度数据加入到指定数组中 可以用来智能识别清晰度的值 foreach ($definition as $key => $v) { $stream_type = $v->stream_type; $audio_lang = $v->audio_lang; if ($stream_type == "3gphd") { //3gp清晰度一般用不到,因为是分段的,改成手机端也放不了,所以这里直接跳过 continue; } if ($audio_lang == "default" || $audio_lang == "guoyu") { array_push($types, $stream_type); } } $xhcs = count($types); $hden2 = array("bq", "gq", "cq", "hd2"); if ($qxd == "") { $vtype = $hden2[count($types) - 1]; $qxurl = $vtype . SG . $vid . HZ; $vtype = $types[count($types) - 1]; } else { $vtype2 = $qxd; $qxurl = $vtype2 . SG . $vid . HZ; } // 判断是否存在该清晰度 // 重置清晰度的值 将传过来的参数cq/gq/bq/转化成原始清晰度数据 /*如果传的参数含有清晰度则需要进一步判断*/ // 加个if判断,提高效率,如果不加if不管参数是否带清晰度都会执行一次。 if ($vtype2 != "") { for ($i = 0; $i < count($types); $i++) { if ($hden2[$i] == $vtype2) { $num = $i; $vtype = $types[$num]; break; } } // 判断是否存在该清晰度 if ($vtype == "") { $vtype = $types[count($types) - 1]; //如果不存在指定的清晰度,则默认输出该视频存在的最高清晰度 } } $yktypes = array("flvhd", "mp4hd", "mp4hd2", "mp4hd3"); $ykhd = array("0", "1", "2", "3"); $ykformatname = array("flv", "mp4", "flv", "flv"); $ykclear = array("标清", "高清", "超清", "1080"); $ykarr = array("type" => $yktypes, "hd" => $ykhd, "fn" => $ykformatname, "cl" => $ykclear); $title = $jdata1->show->title; if ($title == "") { $title = $jdata1->video->title; } $xml["data"]["qxurl"] = $qxurl; $xml["data"]["defa"] = getdefa($xhcs, $vid); $xml["data"]["deft"] = getdeft($xhcs); $xml["data"]["phpself"] = $_SERVER['PHP_SELF']; $xml["data"]["title"] = $title; foreach ($stream as $key => $v) { $stream_fileid = $v->stream_fileid; $stream_type = $v->stream_type; if ($stream_type == $vtype) { $segs = $v->segs; $fileid_1 = substr($stream_fileid, 0, 8); $fileid_2 = substr($stream_fileid, 10); for ($i = 0; $i < count($types); $i++) { if ($stream_type == $ykarr["type"][$i]) { $hd = $ykarr["hd"][$i]; $formatname = $ykarr["fn"][$i]; $clear = $ykarr["cl"][$i]; break; } } $xml["data"]["clear"] = $clear; foreach ($segs as $k => $value) { $hex = strtoupper(dechex($k)) . ""; if (strlen($hex) < 2) { $hex = '0' . $hex; } $fileid = $fileid_1 . $hex . $fileid_2; $ep1 = urlencode(iconv("gbk", "UTF-8", yk_d(yk_e('bf7e5f01', $sid . '_' . $fileid . '_' . $token)))); $key = $value->key; $ts = $value->total_milliseconds_video; $downlink = $kurl . $sid . "_" . $hex . "/st/" . $formatname . "/fileid/" . $fileid . "?K=" . $key . "&hd=" . $hd . "&myp=0&ts=" . intval($ts / 1000.0) . "&ypp=0&ymovie=1&ctype=" . str_replace("&ct=", "", $ctype) . "&ev=1&token=" . $token . "&oip=" . $oip . "&ep=" . $ep1; $xml["data"]["url"][$k]["downlink"] = $downlink; $xml["data"]["url"][$k]["size"] = $value->size; $xml["data"]["url"][$k]["ts"] = intval($ts / 1000.0); } return $xml; } } return; }
} $charCode[$key] = unpack('C*', $str); return $charCode[$key][$index]; } function charAt($str, $index = 0) { return substr($str, $index, 1); } $vid = $_GET['vid']; if (!empty($vid)) { $link = 'http://v.youku.com/player/getPlaylist/VideoIDS/' . $vid . '/source/out/Pf/4/ctype/12/ev/1/Sc/2'; $retval = _cget($link); if (!empty($retval)) { $rs = json_decode($retval, true); $seed = $rs['data'][0]['seed']; if (!empty($seed)) { $ip = $rs['data'][0]['ip']; $videoid = $rs['data'][0]['videoid']; list($sid, $token) = explode('_', yk_e('becaf9be', yk_na($rs['data'][0]['ep']))); $ep = urlencode(iconv('gbk', 'UTF-8', yk_d(yk_e('bf7e5f01', $sid . '_' . $videoid . '_' . $token)))); $final_url = 'http://pl.youku.com/playlist/m3u8?ctype=12&ep=' . $ep . '&ev=1&keyframe=1&oip=' . $ip . '&sid=' . $sid . '&token=' . $token . '&vid=' . $videoid . '&type=mp4'; echo $final_url; } else { echo 'Invalid vid.'; } } else { echo 'Error fetching.'; } } else { echo 'No input.'; }