PHP obtains the actual flv file address of the youku video ,. PHP obtains the real flv file address of a youku video. This document describes how PHP obtains the real flv file address of a youku video. Share it with you for your reference. The specific analysis is as follows: PHP uses the method to obtain the actual flv file address of the youku video,
This example describes how to use PHP to obtain the actual flv file address of a youku video. Share it with you for your reference. The specific analysis is as follows:
A webmaster asked me to help him develop a real flv address that can automatically test the youku video website. below I sorted it out and solved this problem very well. you can refer to it.
The code is as follows:
The code is as follows:
<? Php
$ Videourl = 'http: // v.youku.com/v_show/id_xmja5mjq0otq0.html ';
Function get_content ($ url, $ data ){
If (is_array ($ data )){
$ Data = http_build_query ($ data ,'','&');
}
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data );
$ Result = curl_exec ($ ch );
Return $ result;
}
$ Str = get_content ('http: // developer.pengyou.com/json.php? Mod = usershare & act = geturlinfo ', array ('URL' => $ videourl ));
$ Str = json_decode ($ str );
Var_dump ($ str );
?>
This test shows that the swf file is not the flv file we need. later, we improved the method by referring to a Webmaster. the core code is as follows:
The code is as follows:
<? Php
Function fetch_youku_flv ($ 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 "response }? K = {$ one [0]-> k }";
Continue;
}
}
Function get_curl_contents ($ url, $ second = 5 ){
If (! Function_exists ('curl _ init ') die ('php. ini has not enabled 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 (10000) + );
Return $ sid;
}
Function getkey ($ key1, $ key2 ){
$ A = hexdec ($ key1 );
$ B = $ a ^ 0xA55AA5A5;
$ B = dechex ($ B );
Return $ key2. $ 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;
}
?>
The code is as follows:
The code is as follows:
$ Url = 'http: // v.youku.com/v_show/id_xmzg2otq3mjq1_html ';
Echo fetch_youku_flv ($ url );
Access:
The code is as follows:
Http://xiaomizhou.net/demo/flv.php? Url = http://v.youku.com/v_show/id_XMzg2OTQ3MjQw.html
The output result is:
The code is as follows:
Http://f.youku.com/player/getFlvPath/sid/138035737110468_00/st/flv/fileid/03000201004F97EF4A2E350467A09DB266E872-5522-225F-DC45-40B4E1F9BE49? K = c2a4327df2bb5a65261d40ea
This can be downloaded directly.
I hope this article will help you with php programming.
Examples: This article describes how PHP can obtain the actual flv file address of a youku video. Share it with you for your reference. The specific analysis is as follows :...