本帖最后由 qqincai 于 2025-9-23 17:22 编辑
<?php
///huyatl.php?id=11342386
error_reporting(0);
date_default_timezone_set('PRC');
get_ts();
function get_ts()
{
if(strpos($_GET["id"],"-")!== false){
$id=$_GET["id"];
}else{
$idall=file_get_contents("hyid.txt");
$str=strchr($idall,$_GET["id"]);
if (!empty($str)){
$arr = explode(",", $str);
$id=$arr[1];
}else{
$id=getlid($_GET["id"],"hyid.txt");
}
}
$host='http://hs.hls.huya.com/src/';
$url=$host.$id.".m3u8";
start:
$mediaurl=get_data($url);
$count=mb_substr_count($mediaurl,"EXTINF");
$str=strchr($mediaurl,".ts");
$str1=strchr($mediaurl,"ENDLIST");
if((!empty($str))&&(empty($str1))){
$mediaurl=str_replace(",\n",",\n".$host, $mediaurl);
$mediaurl=str_replace("#EXT-X-DISCONTINUITY-SEQUENCE:1","", $mediaurl);
$mediaurl=str_replace("#EXT-X-DISCONTINUITY-SEQUENCE:0","", $mediaurl);
$mediaurl=str_replace(".ts?",".ts?wsSecret=".md5(time()).'&wsTime='.dechex(time()).'&', $mediaurl);
header('Content-Type: application/vnd.apple.mpegurl');
header("Content-Disposition: attachment; filename=".$id.".m3u8");
echo $mediaurl;exit;
}
elseif(empty($str)){
goto start;
}
exit;
}
function get_data($url)
{
if ($host == null) {
$host='hs.hls.huya.com';
}
$User_Agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/".rand(101,555).".".rand(11,99)." (KHTML, like Gecko) Chrome/".rand(46,109).".0.0.0 Safari/".rand(101,555).".".rand(11,99);
$headers = [
"Accept-Encoding: identity;q=1;q=0",
"Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Cookie:__yamid_tt1=0.9751904498082955; __yamid_new=C9DDE2458320000123C78D2BADF09750; SoundValue=0.50; udb_guiddata=7425fb2f5e0c40e98d94ee0f698b4b32; udb_deviceid=w_713164655948267520; alphaValue=0.80; game_did=Q5bu4zij-T19KG62gqVMPFrFzPJBlKexXM7; __yasmid=0.9751904498082955; _yasids=__rootsid=CA9615A6014000011F801CC918305B00; udb_passdata=3; guid=0adb302aec836b645401a19ba29b7adf; sdidshorttest=test; Hm_lvt_51700b6c722f5bb4cf39906a596ea41f=1704978875; videoBitRate=2000; sdid=0UnHUgv0_qmfD4KAKlwzhqQSZpsKOshsUdOs4kv1Sn1vXPU0QJ_mkVorWgKmSDI04dloDxWm9ui9yBc1w0bkrHR3mp_jhixkCCGDJg2KMfOXWVkn9LtfFJw_Qo4kgKr8OZHDqNnuwg612sGyflFn1dsyOTymh3Du1ZCGGV6X0sfvTd0jo-3kppP8w3lS5EZTW; sdidtest=0UnHUgv0_qmfD4KAKlwzhqQSZpsKOshsUdOs4kv1Sn1vXPU0QJ_mkVorWgKmSDI04dloDxWm9ui9yBc1w0bkrHR3mp_jhixkCCGDJg2KMfOXWVkn9LtfFJw_Qo4kgKr8OZHDqNnuwg612sGyflFn1dsyOTymh3Du1ZCGGV6X0sfvTd0jo-3kppP8w3lS5EZTW; isInLiveRoom=; Hm_lpvt_51700b6c722f5bb4cf39906a596ea41f=".time()."; huya_flash_rep_cnt=48; _rep_cnt=4; huya_web_rep_cnt=158; huyawap_rep_cnt=56",
"DNT: 1",
"Host: ".$host,
"Pragma: no-cache",
"Range: bytes=0-",
"Referer: https://m.huya.com/",
"Sec-Fetch-Dest: video",
"Sec-Fetch-Mode: no-cors",
"Sec-Fetch-Site: same-site",
"User-Agent: ".$User_Agent,
"X-FORWARDED-FOR:'.'127.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255),'CLIENT-IP:'.'127.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255)",
];
$ch=curl_init();
$Referer_Url="https://m.huya.com/";
$timeout=1;
$timeout_ms=900;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_NOSIGNAL,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT_MS,$timeout_ms);
curl_setopt($ch,CURLOPT_TIMEOUT_MS, $timeout_ms);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_USERAGENT,$User_Agent);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
$chr=curl_exec($ch);
curl_close($ch);
return $chr;
}
function getlid($id,$txt){
$URL = "https://mp.huya.com/cache.php?m=Live&do=profileRoom&roomid=".$id;
$UAgent="Mozilla/5.0 (Linux; Android 6.0; HTC) AppleWebKit/".rand(101,555).".".rand(11,99)." (KHTML, like Gecko) Chrome/".rand(46,109).".0.0.0 Safari/".rand(101,555).".".rand(11,99);
$ch=curl_init();
$timeout=5;
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_TIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_USERAGENT,$UAgent);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-FORWARDED-FOR:'.'127.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255),'CLIENT-IP:'.'127.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255)));
$data=curl_exec($ch);
curl_close($ch);
$json = json_decode($data);
$bStreamLst = $json->data->stream->baseSteamInfoList[1];
$sStreamName = $bStreamLst->sStreamName;
$name = $json->data->liveData->introduction;
$ids=$id.",".$sStreamName.",".$name;
file_put_contents($txt,$ids."\r\n",FILE_APPEND);
return $sStreamName;
}
?>
|