Youku video absolute address acquisition method details
- 2020-06-22 23:59:11
- OfStack
In order to study KnLiveCommentary, I conducted a series of researches on video sites a while ago. Since KnLiveCommentary needs to be able to obtain sufficient video sources for testing, we select a large video website of Youku (Youku) for testing.
In fact, the beginning of the study of parsing absolute address is also to study the Youku's own player, by the way, remove advertising and so on. Later, we "decompiled" Youku's player with ASV6 (ActionScript Viewer 6) for 1 and achieved amazing results.
The video of Youku adopts the method of encryption + dynamic acquisition, the video address needs to visit the website to obtain dynamically, and the results need to be decrypted and other operations.
Please note that since the Youku replacement algorithm/format above can no longer handle all cases, Let me describe the current process:
1. Visit http: / / v youku. com player/getPlayList VideoIDS / [ID]
2. Get file and parse "streamfileids" : {" flv ":" address ", "mp4" : encryption "address", "and so on, such as:" encryption "address"
3. Follow the above method to crack the encrypted address
4. Get the number of segments and K
{" mp4 ": [{" no" : "0" and "size" : "18367795", "seconds" : "421", "k" : "281 ff2875db680bb261c02ce"}, {" no ":" 1 ", "size" : "19045091", "seconds" : "421", "k" : "45398 cdd4aa4496 8261 c02ce "},
...
5. Composite address, but K for each segment takes the new K obtained above
In fact, the beginning of the study of parsing absolute address is also to study the Youku's own player, by the way, remove advertising and so on. Later, we "decompiled" Youku's player with ASV6 (ActionScript Viewer 6) for 1 and achieved amazing results.
The video of Youku adopts the method of encryption + dynamic acquisition, the video address needs to visit the website to obtain dynamically, and the results need to be decrypted and other operations.
$base_url = 'http://v.youku.com/player/getPlayList/VideoIDS/'; // The address to get the video information Base address
$_VIDEO_ID = $_GET['vid']; // from GET Inside the Video Id extract
if($_VIDEO_ID=='')
$_VIDEO_ID = 'XMjY0ODE1MDA0'; // I'm lazy when it comes to testing Wait is fixed 1 a
$ch = curl_init(); // open 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); // to 1 A false "REFERER"
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // Put the current browser User Agent Pass to server
curl_setopt($ch, CURLOPT_NOBODY, 0);
$content = curl_exec($ch); // Execute!!
curl_close($ch); /* The following resolution */
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,$key1);
preg_match( ' ~ " key2 " \s*:\s* " (.*) " \s*,~iUs',$content,$key2);
// From the returned JSON Extract the necessary information from the 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);// According to the old Seed Calculate the new Seed And return 1 a Seed Proportional position of [0,1)
}
function cg_hun(){ // I guess this is called " CG Fuck. "Anyway ASV The function of the solution is called that
$this->cg_str="";
$sttext = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/\:._-1234567890'; // Default string (maximum)
$len = strlen($sttext); // Get its length
for($i=0;$i<$len;$i++){
$cuch = (int)($this->ran()*strlen($sttext)); // Get string Seed The proportion The character subscript of a position
$this->cg_str.=$sttext[$cuch]; // Read the letters out
$sttext = str_replace($sttext[$cuch], " ,$sttext); // Delete the read letter (to 0 Stop)
}
}
function decode($string){
$output= " ";
$this->cg_hun();
$expl = explode( ' *',$string); // the 1*23*34*45*56* This string splits
for($i=0;$i<count($expl)-1;$i++){
$output.=$this->cg_str[(int)$expl[$i]]; // Gets the digits represented by cg_hun Scramble string characters and decrypt from there
}
return $output; //OK la
}
function decode_key($key1,$key2){
$key = hexdec($key1); // two Key Are all HEX
$key = $key ^ -1520786011; // This turned out to be a 8 position HEX And then I used a calculator to do the Numbers because it was convenient PhP An operation
return $key2 . dechex($key); // Synthesis of the final Key
}
}// Decrypt class, which is very handy to use $new = new decoder((int)$seed[1]);
$fileid = $new->decode($encoded[2]);
$key = $new->decode_key($key1[1],$key2[1]);
// Feed the data in, calculate it // Address load constitution
$s7 = substr($fileid,10,strlen($fileid));
$s5 = substr($fileid,0,8);
$s6 = substr($fileid,6,2);
// apart $s4 = '00 ' ;// Note that this is 1 a HEX Values, i.e., 00 Represent video control 1 A section, 01 The first 2 a 0f The first 105 A... And so on $sid = time() . mt_rand(10,99) . '1000 ' . mt_rand(30,80) . '00 ' ;// To obtain 1 A random SID , to the server (which is not actually checked)
$d_ADDR = ' http://f.youku.com/player/getFlvPath/sid/ ' . $sid . ' _'. $s4 . ' /st/' . $encoded[1] . ' /fileid/' . $file_id;
echo $d_ADDR . ' ?K=' . $key;
// Finally, output the address
Please note that since the Youku replacement algorithm/format above can no longer handle all cases, Let me describe the current process:
1. Visit http: / / v youku. com player/getPlayList VideoIDS / [ID]
2. Get file and parse "streamfileids" : {" flv ":" address ", "mp4" : encryption "address", "and so on, such as:" encryption "address"
3. Follow the above method to crack the encrypted address
4. Get the number of segments and K
{" mp4 ": [{" no" : "0" and "size" : "18367795", "seconds" : "421", "k" : "281 ff2875db680bb261c02ce"}, {" no ":" 1 ", "size" : "19045091", "seconds" : "421", "k" : "45398 cdd4aa4496 8261 c02ce "},
...
5. Composite address, but K for each segment takes the new K obtained above