<?php |
$id = 'HKxxUAaa4uE'; |
$url = "http://www.youtube.com/get_video_info?video_id={$id}&asv=3&&el=detailpage&sts=16708"; |
$ch = curl_init($url); |
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36'); |
curl_setopt($ch, CURLOPT_HEADER, false); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
curl_setopt($ch, CURLOPT_ENCODING, ""); |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); |
|
|
$content = curl_exec($ch); |
curl_close($ch); |
parse_str($content, $data); |
|
$links = []; |
foreach(explode(',', $data['url_encoded_fmt_stream_map']) as $str) { |
parse_str($str, $array); |
//var_dump($array); |
$itag = $array['itag']; |
if (@$array['signature']) { |
$url = $array['url'] .'&signature='. $links[$itag]['signature']; |
} elseif (@$array['sig']) { |
$url = $array['url'] .'&signature='. $links[$itag]['sig']; |
} elseif(@$array['s']) { |
$sig = decSig($array['s']); |
|
$url = "{$array['url']}&signature={$sig}"; |
|
} else { |
$url = $array['url']; |
} |
$ch = curl_init($url); |
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36'); |
curl_setopt($ch, CURLOPT_HEADER, true); |
curl_setopt($ch, CURLOPT_NOBODY, true); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
curl_setopt($ch, CURLOPT_ENCODING, ""); |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); |
|
|
$content = curl_exec($ch); |
echo $content; |
|
$links[$array['itag']] = $array; |
} |
function decSig($s) { |
//$list = ["16708", [["swap",19],["splice",2],["reverse",null],["splice",2],["swap",48],["reverse",null],["splice",2],["reverse",null]] ]; |
$list = [["swap",19],["splice",2],["reverse",null],["splice",2],["swap",48],["reverse",null],["splice",2],["reverse",null]]; |
$actionList = [ |
'slice' => function (&$a, &$b) { |
$a = array_slice($a, 2); |
}, |
'splice' => function (&$a, $b) { |
array_splice ($a, 0, $b); |
}, |
'reverse' => function (&$a) { |
$a = array_reverse($a); |
}, |
'swap' => function (&$a, &$b) { |
$c = $a[0]; |
$a[0] = $a[$b % count($a)]; |
$a[$b] = $c; |
} |
]; |
$s = str_split($s); |
|
for ($i = 0, $item; (isset($list[$i]) && $item = $list[$i]); $i++) { |
$actionList[$item[0]]($s, $item[1]); |
|
} |
return implode('', $s); |
} |