Youku Video Absolute Address acquisition method detailed _php Tutorial

Source: Internet
Author: User
A series of studies on video sites have been conducted in the last few years to study knlivecommentary. Since knlivecommentary needs to be able to get enough video sources for testing, we have chosen Youku (Youku) as a larger video site for testing.
In fact, began to study the resolution of the absolute address is also to study Youku's own player, the way to remove ads or something. Later, we put Youku's player ASV6 (ActionScript Viewer 6) "decompile" for a bit, and achieved amazing results.

Youku Video takes the encryption + dynamic access, the video address needs to access the site dynamic acquisition, and the results will have to be decrypted and other operations.
Copy CodeThe code is as follows:
$base _url = ' http://v.youku.com/player/getPlayList/VideoIDS/'; Get the address of the video message base site
$_video_id = $_get[' vid ']; Extract the video ID from the get
if ($_video_id== ")
$_video_id = ' xmjy0ode1mda0 '; I was lazy, and I fixed a test.
$ch = Curl_init (); Turn on Curl Object
curl_setopt ($ch, Curlopt_url, $base _url. $_video_id); Get the address of the information for this video
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); /* Parse below */
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);//Calculates a new seed based on the old seed and returns the proportional position of a Seed [0,1]
}
function Cg_hun () {//estimate This is called "CG Mix", anyway the ASV solution is the name
$this->cg_str= "";
$sttext = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz/\:._-1234567890 '; Default string (max)
$len = strlen ($sttext); Get its length
for ($i =0; $i < $len; $i + +) {
$cuch = (int) ($this->ran () *strlen ($sttext)); Gets the character subscript of the string seed scale position
$this->cg_str.= $sttext [$cuch]; Read the letters.
$sttext = Str_replace ($sttext [$cuch], ", $sttext); Delete the read-out letter (stop at 0)
}
}
function decode ($string) {
$output = "";
$this->cg_hun ();
$EXPL = Explode (' * ', $string); Break the 1*23*34*45*56* string
for ($i =0; $i $output. = $this->cg_str[(int) $EXPL [$i]]; Gets the number bit represented by the Cg_hun scrambled string character, since this decryption is complete
}
return $output; OK pull
}
function Decode_key ($key 1, $key 2) {
$key = Hexdec ($key 1); Two keys are hex
$key = $key ^-1520786011; This is also a 8-bit hex, then I used the calculator to calculate the value, because it is convenient for PHP bit operation
Return $key 2. Dechex ($key); Composite 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, calculate//address contains
$s 7 = substr ($fileid, 10,strlen ($fileid));
$s 5 = substr ($fileid, 0,8);
$s 6 = substr ($fileid, 6,2);
Open $S4 = ' 00′;//Note This is a HEX value, which means that 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 (in fact it won't 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;
And finally the address output

Please note that since the method above in the Youku replacement algorithm/format cannot handle all cases, let me describe the current process:
1. Visit Http://v.youku.com/player/getplaylist/videoids/[id]
2. Obtain the file while parsing "Streamfileids": {"flv": "Encrypted Address", "Mp4″:" Encrypted address "," etc. ":" Encrypted Address "
3. Follow the above method to crack the encrypted address
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. The address is synthesized, but each segment of K uses the new K obtained above

http://www.bkjia.com/PHPjc/327891.html www.bkjia.com true http://www.bkjia.com/PHPjc/327891.html techarticle A series of studies on video sites have been conducted in the last few years to study knlivecommentary. Since knlivecommentary needs to be able to get enough video sources for testing, we choose ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.