Copy Code code as follows:
<?php
--Invoke Method/demo.php?url=http://v.youku.com/v_show/id_xmzkyoda2ntey.html
echo getyoukuflv ($_get[' url '));
function getyoukuflv ($url) {
Preg_match ("#id_ (. *?) \.html# ", $url, $out);
$id = $out [1];
$content =get_curl_contents (' http://v.youku.com/player/getPlayList/VideoIDS/'. $id);
$data =json_decode ($content);
foreach ($data->data[0]->streamfileids as $k => $v) {
$sid =getsid ();
$fileid =getfileid ($v, $data->data[0]->seed);
$one = ($data->data[0]->segs-> $k);
if ($k = = ' flv ' | | | | $k = = ' mp4 ') return "http://f.youku.com/player/getflvpath/sid/{$sid}_00/st/{$k}/fileid/{$fileid}? k={$one [0]->k}];
Continue
}
}
function get_curl_contents ($url, $second = 5) {
if (!function_exists (' Curl_init ')) die (' PHP.ini not open php_curl.dll ');
$c = Curl_init ();
curl_setopt ($c, Curlopt_url, $url);
$UserAgent =$_server[' http_user_agent '];
curl_setopt ($c, curlopt_useragent, $UserAgent);
curl_setopt ($c, curlopt_header,0);
curl_setopt ($c, Curlopt_timeout, $second);
curl_setopt ($c, Curlopt_returntransfer, true);
$cnt = curl_exec ($c);
$cnt =mb_check_encoding ($cnt, ' Utf-8 ')? Iconv (' GBK ', ' Utf-8//ignore ', $cnt): $cnt; Character encoding Conversion
Curl_close ($c);
return $cnt;
}
function GetSID () {
$sid = Time (). (Rand (0,9000) +10000);
return $sid;
}
function Getkey ($key 1, $key 2) {
$a = Hexdec ($key 1);
$b = $a ^ 0xa55aa5a5;
$b = Dechex ($b);
Return $key 2. $b;
}
function Getfileid ($fileId, $seed) {
$mixed = getmixstring ($seed);
$ids = Explode ("*", $fileId);
Unset ($ids [Count ($ids)-1]);
$realId = "";
for ($i =0; $i < count ($ids); + + $i) {
$idx = $ids [$i];
$realId. = substr ($mixed, $IDX, 1);
}
return $realId;
}
function getmixstring ($seed) {
$mixed = "";
$source = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/\\:._-1234567890";
$len = strlen ($source);
for ($i =0; $i < $len; + + $i) {
$seed = ($seed * 211 + 30031)% 65536;
$index = ($seed/65536 * strlen ($source));
$c = substr ($source, $index, 1);
$mixed. = $c;
$source = Str_replace ($c, "", $source);
}
return $mixed;
}
?>