经过研究,我如何从StackOverflow
获得此代码并运作良好
对于此视频ID = 6chhghoMGVQ
,但是当我将此T系列VFTSW817JlI
的视频ID放入时,出现错误消息Status => UNPLAYABLE
这是此视频ID = 6chhghoMGVQ
的有效代码链接
signature issue when I want to get a direct URL from YouTube via PHP
最后,我在此链接https://www.youtube.com/get_video_info?sts=18177&video_id=$v&asv=3&el=detailpage&hl=en_US&eurl=https://youtube.googleapis.com/v/$v
上做了一些更改
代替此链接https://www.youtube.com/get_video_info?video_id=$v
更改链接I Got Status For Video UNPLAYABLE TO OK
但是现在我无法获取URL,因为如果我更改了URL名称,cipher
就是
"url" => $array["streamingData"]["formats"][$a]["url"],
[“ url”]加密我得到URL但不能播放URL得到错误消息403
我有旧的密码签名解码器代码,但无法正常工作
这是我尝试过的代码。
<?php
function YT_IN_DX($url){
$cookie_file_path = "cookies.txt";
$agent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/46.0";
$ch = curl_init();
$headers[] = "Connection: Keep-Alive";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_URL, $url);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
function YT_V_INFO($v){
$url = "https://www.youtube.com/get_video_info?sts=18177&video_id=$v&asv=3&el=detailpage&hl=en_US&eurl=https://youtube.googleapis.com/v/$v";
$html = urldecode(YT_IN_DX($url));
$video_links = Explode_Content('playabilityStatus', 'adSafetyReason', $html);
$json = str_replace("\u0026", "&", $video_links);
$json = '{"playabilityStatus' . $json . 'adSafetyReason":{"isEmbed":true}}';
$array = json_decode($json, true);
if (isset($array["playabilityStatus"]["status"]) && $array["playabilityStatus"]["status"] == "UNPLAYABLE") {
$data = array("error" => $array["playabilityStatus"]["status"]);
}else{
$formats = $array["streamingData"]["formats"];
for ($a = 0; $a <= (count($formats) - 1); $a++){
$data[] = array(
"url" => $array["streamingData"]["formats"][$a]["url"],
"mimeType" => $array["streamingData"]["formats"][$a]["mimeType"],
"quality" => $array["streamingData"]["formats"][$a]["quality"],
"qualityLabel" => $array["streamingData"]["formats"][$a]["qualityLabel"],
"width" => $array["streamingData"]["formats"][$a]["width"],
"height" => $array["streamingData"]["formats"][$a]["height"],
"audioQuality" => $array["streamingData"]["formats"][$a]["audioQuality"],
"approxDurationMs" => $array["streamingData"]["formats"][0]["approxDurationMs"]
);
}
}
return $data;
}
function Explode_Content($first, $last, $string)
{
$exp = explode($first, $string);
$exp = explode($last, $exp[1]);
return $exp[0];
}
// $videoinfo=YT_V_INFO("sJsoyuQAepQ");
$videoinfo = YT_V_INFO("VFTSW817JlI");
echo '<pre>';
print_r($videoinfo);
?>
这是签名解码器
function decrypt_sig($s,$algo) {
$method = explode(" ",$algo);
foreach($method as $m)
{
if($m == 'r')
$s = strrev($s);
else if( substr($m,0,1) == 's')
$s = substr($s, (int) substr($m,1) );
else if( substr($m,0,1) == 'w')
$s = swap($s, (int) substr($m,1));
}
return $s;
}
function swap($a, $b) {
$c = $a[0];
$a[0] = $a[$b % strlen($a)];
$a[$b] = $c;
return $a;
}
算法键:{"sts":"18177","algo":"r w22 s3 w42 r"}