/**
- * Get the final address of Youku video
- * Edit by Bbs.it-home.org
- * At:2013-10-2
- */
- Class youkuflv{
- static Private $error = "";
- static private $result = Array ();
- static public Function getyoukuflv ($url) {
- Get Youkuid from URL
- if (! $id = Self::getyoukuid ($url)) {
- return false;
- }
- Get Youku Video Details
- $content = self::get_curl_contents ("http://v.youku.com/player/getPlayList/VideoIDS/". $id);
- $data = Json_decode ($content);
- if (!isset ($data->data[0]->streamfileids)) {
- Self:: $error = "Cannot find this video";
- return false;
- }
- foreach ($data->data[0]->streamfileids as $k = + $v) {
- if ($k = = ' flv ' | | $k = = ' mp4 ') {
- Sid
- $sid = Self::getsid ();
- Fileid
- $fileid = Self::getfileid ($v, $data->data[0]->seed);
- $one = ($data->data[0]->segs-> $k);
- Self:: $result [$k] = "http://f.youku.com/player/getflvpath/sid/{$sid}_00/st/{$k}/fileid/{$fileid}? k={$one [0]->k} ";
- }
- }
- if (Empty (self:: $result)) {
- Self:: $error = "This viod was not in MP4 OR FLV FORMAT";
- return false;
- }else{
- return true;
- }
- }
- static public Function error () {
- Return self:: $error;
- }
- static public Function result () {
- Return self:: $result;
- }
- Static Private Function Getyoukuid ($url) {
- The URL cannot be empty
- if ($url = = "" | | substr ($url, 0,)! = "Http://v.youku.com/v_show/id_") {
- Self:: $error = "URL is Error";
- return false;
- }
- Return substr ($url, 29,-5);
- }
- Static Private Function Get_curl_contents ($url, $second = 5) {
- if (!function_exists (' Curl_init ')) die (' php.ini not turned on 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);
- Curl_close ($c);
- return $cnt;
- }
- Static Private Function GetSID () {
- $sid = Time (). (Rand (0,9000) +10000);
- return $sid;
- }
- Static Private Function Getfileid ($fileId, $seed) {
- $mixed = self::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;
- }
- Static Private 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;
- }
- }
- if (youkuflv::getyoukuflv ("http://v.youku.com/v_show/id_XNjEyOTE4NTEy_ev_1.html")) {
- Print_r (Youkuflv::result ());
- }else{
- Echo Youkuflv::error ();
- }
?>
Copy CodeAnother way to call: http://player.youku.com/player.php/sid/xmji0mdiwndc2/v.swfhttp://player.youku.com/player.php/sid/{$id }/v.swf |