For a while, a series of research on video sites was conducted to study knlivecommentary. Since knlivecommentary need to be able to get enough video sources to test, we chose Youku (Youku) a larger video site to test.
In fact, the beginning of the study to resolve the absolute address is also to study the Youku of the player, by the way to remove ads or something. Later, we put the Youku player ASV6 (ActionScript Viewer 6) "decompile" a bit, to achieve amazing results.
Youku video to take the encryption + dynamic access, video addresses need to access the Web site dynamic acquisition, and the results also need to be decrypted and other operations.
Copy Code code as follows:
$base _url = ' http://v.youku.com/player/getPlayList/VideoIDS/'; To get the video information from the address base site
$_video_id = $_get[' vid ']; Extract the video ID from the
if ($_video_id== ')
$_video_id = ' xmjy0ode1mda0 '; I'm lazy, I fixed a
on the test.
$ch = Curl_init (); Open Curl Object
curl_setopt ($ch, Curlopt_url, $base _url. $_video_id); Get the information for this video address
curl_setopt ($ch, Curlopt_header, 1); To HEADER
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_referer, ' http://v.youku.com/v_show/id_ '. $_video_id); Give a fake "REFERER"
.
curl_setopt ($ch, curlopt_useragent, $_server[' http_user_agent ']); Pass the current browser user agent to the server
curl_setopt ($ch, curlopt_nobody, 0);
$content = curl_exec ($ch); Perform!!!
curl_close ($ch); /* Below analysis * *
Preg_match (' ~ "Seed" s*:s* (d+) S*,~ius ', $content, $seed);
preg_match (' ~{s* "(flv|mp4)" s*:s* "(. *)" S*}~ius ", $content, $encoded);
Preg_match (' ~ "key1″s*:s*" (. *) "S*,~ius", $content, $key 1);
Preg_match (' ~ "key2″s*:s*" (. *) "S*,~ius", $content, $key 2);
//Extract the necessary information from the returned JSON string seed, Encoded_url, Key1, Key2
class decoder{
var $randomSeed = 0;
var $cg _str= "";
function __construct ($seed) {
$this->randomseed = $seed;
}
function Ran () {
$this->randomseed = ($this->randomseed * 211) +30031)%65536;
Return ($this->randomseed/65536);//The new seed is computed from the old seed, and the proportional position of a seed is returned [0,1)
}
function Cg_hun () {//* This is called "CG Mix", anyway, the ASV solution is this name
$this->cg_str= "";
$sttext = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/:._-1234567890 '; Default string (max)
$len = strlen ($sttext); Gets its length
for ($i =0; $i < $len; $i + +) {
$cuch = (int) ($this->ran () *strlen ($sttext)); Gets the character Poute of the string seed proportional position
$this->cg_str.= $sttext [$cuch]; Read the letters out
$sttext = Str_replace ($sttext [$cuch], ", $sttext); Remove the Read letter (stop at 0)
}
}
function decode ($string) {
$output = "";
$this->cg_hun ();
$expl = Explode (' * ', $string); Break 1*23*34*45*56* This string
for ($i =0 $i <count ($EXPL)-1; $i + +) {
$output. = $this->cg_str[(int) $EXPL [$i]]; Gets the numeric bit represented by the Cg_hun to disrupt the string character, from which the decryption completes
}
return $output; Ok la
}
function Decode_key ($key 1, $key 2) {
$key = Hexdec ($key 1); Two key is Hex
$key = $key ^-1520786011; This turns out to be a 8-bit hex, and then I used the calculator to calculate the value, because this is convenient for PHP bit operations
return $key 2. Dechex ($key); Synthetic final Key
}
}//decryption class, with this very convenient $new = new Decoder ((int) $seed [1]);
$fileid = $new->decode ($encoded [2]);
$key = $new->decode_key ($key 1[1], $key 2[1]);
//Feed the data, the calculation//address contains the composition
$s 7 = substr ($fileid, 10,strlen ($fileid));
$s 5 = substr ($fileid, 0,8);
$s 6 = substr ($fileid, 6,2);
//disassemble $S4 = ' 00′;//Note that this is a HEX value, that is, 00 represents the first segment of the video, 01 the second 0f 15th ... And so on $sid = time (). Mt_rand (10,99). ' 1000′. Mt_rand (30,80). ' 00′;//gets a random SID to the server (which will not actually be checked)
$d _addr = ' Http://f.youku.com/player/getFlvPath/sid/'. $sid. ‘_'. $s 4. '/st/'. $encoded [1]. '/fileid/'. $file _id;
Echo $d _addr. ‘? K= '. $key;
//Finally the address output
Please note that since the Youku replacement algorithm/format has not been able to handle all cases, let me describe the current process:
1. Visit Http://v.youku.com/player/getplaylist/videoids/[id]
2. Get the file and resolve "Streamfileids": {"flv": "Encrypted Address", "Mp4″:" Encrypted address, "etc.": "Encrypted Address"
3. To crack the encrypted address according to the above method
4. Get the number of segments and K
{"mp4″:[{" no ":" 0 "," Size ":" 18367795″, "Seconds": "421″," K ":" 281ff2875db680bb261c02ce "},{" No ":" 1 "," Size ":" 19045091 ″, "Seconds": "421″," K ":" 45398cdd4aa44968261c02ce "},
......
5. Synthetic address, but each section K is the new K obtained above