Update index.php
Browse files
index.php
CHANGED
@@ -1,16 +1,141 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
$
|
6 |
-
$
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
$
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
+
date_default_timezone_set("Asia/Shanghai");
|
3 |
+
$type = empty($_GET['type']) ? "nodisplay" : trim($_GET['type']);
|
4 |
+
$id = empty($_GET['id']) ? "shangdi" : trim($_GET['id']);
|
5 |
+
$cdn = empty($_GET['cdn']) ? "hwcdn" : trim($_GET['cdn']);
|
6 |
+
$media = empty($_GET['media']) ? "flv" : trim($_GET['media']);
|
7 |
+
$roomurl = "https://m.huya.com/" . $id;
|
8 |
|
9 |
+
function get_content($apiurl, $flag)
|
10 |
+
{
|
11 |
+
if ($flag == "mobile") {
|
12 |
+
$headers = array(
|
13 |
+
'Content-Type: application/x-www-form-urlencoded',
|
14 |
+
'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1'
|
15 |
+
);
|
16 |
+
} else {
|
17 |
+
$arr = [
|
18 |
+
"appId" => 5002,
|
19 |
+
"byPass" => 3,
|
20 |
+
"context" => "",
|
21 |
+
"version" => "2.4",
|
22 |
+
"data" => new stdClass(),
|
23 |
+
];
|
24 |
+
$postData = json_encode($arr);
|
25 |
+
$headers = array(
|
26 |
+
'Content-Type: application/json',
|
27 |
+
'Content-Length: ' . strlen($postData),
|
28 |
+
'upgrade-insecure-requests: 1',
|
29 |
+
'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
|
30 |
+
);
|
31 |
+
}
|
32 |
+
$ch = curl_init();
|
33 |
+
curl_setopt($ch, CURLOPT_URL, $apiurl);
|
34 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
35 |
+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
36 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
37 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
38 |
+
if ($flag == "uid") {
|
39 |
+
curl_setopt($ch, CURLOPT_POST, 1);
|
40 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
41 |
+
}
|
42 |
+
$data = curl_exec($ch);
|
43 |
+
curl_close($ch);
|
44 |
+
return $data;
|
45 |
+
}
|
46 |
+
|
47 |
+
function aes_decrypt($ciphertext, $key, $iv)
|
48 |
+
{
|
49 |
+
return openssl_decrypt($ciphertext, 'AES-256-CBC', $key, 0, $iv);
|
50 |
+
}
|
51 |
+
|
52 |
+
$key = "abcdefghijklmnopqrstuvwxyz123456";
|
53 |
+
$iv = "1234567890123456";
|
54 |
+
$mediaurl = aes_decrypt("vcnTSiZsSUWtlZRxx+FuRnM7F1b1FlSVueFKcxewvKVbe9bXE49HXuq1dHha2K7cSic4yOuClWpau1RibQeO2g==", $key, $iv);
|
55 |
+
|
56 |
+
$uid = json_decode(get_content("https://udblgn.huya.com/web/anonymousLogin", "uid"), true)["data"]["uid"];
|
57 |
+
|
58 |
+
function get_uuid()
|
59 |
+
{
|
60 |
+
$now = intval(microtime(true) * 1000);
|
61 |
+
$rand = rand(0, 1000) | 0;
|
62 |
+
return intval(($now % 10000000000 * 1000 + $rand) % 4294967295);
|
63 |
+
}
|
64 |
+
|
65 |
+
function process_anticode($anticode, $uid, $streamname)
|
66 |
+
{
|
67 |
+
parse_str($anticode, $q);
|
68 |
+
$q["ver"] = "1";
|
69 |
+
$q["sv"] = "2110211124";
|
70 |
+
$q["seqid"] = strval(intval($uid) + intval(microtime(true) * 1000));
|
71 |
+
$q["uid"] = strval($uid);
|
72 |
+
$q["uuid"] = strval(get_uuid());
|
73 |
+
$ss = md5("{$q["seqid"]}|{$q["ctype"]}|{$q["t"]}");
|
74 |
+
$q["fm"] = base64_decode($q["fm"]);
|
75 |
+
$q["fm"] = str_replace(["$0", "$1", "$2", "$3"], [$q["uid"], $streamname, $ss, $q["wsTime"]], $q["fm"]);
|
76 |
+
$q["wsSecret"] = md5($q["fm"]);
|
77 |
+
unset($q["fm"]);
|
78 |
+
if (array_key_exists("txyp", $q)) {
|
79 |
+
unset($q["txyp"]);
|
80 |
+
}
|
81 |
+
return http_build_query($q);
|
82 |
+
}
|
83 |
+
|
84 |
+
function format($livearr, $uid)
|
85 |
+
{
|
86 |
+
$stream_info = ['flv' => [], 'hls' => []];
|
87 |
+
$cdn_type = ['HY' => 'hycdn', 'AL' => 'alicdn', 'TX' => 'txcdn', 'HW' => 'hwcdn', 'HS' => 'hscdn', 'WS' => 'wscdn'];
|
88 |
+
foreach ($livearr["roomInfo"]["tLiveInfo"]["tLiveStreamInfo"]["vStreamInfo"]["value"] as $s) {
|
89 |
+
if ($s["sFlvUrl"]) {
|
90 |
+
$stream_info["flv"][$cdn_type[$s["sCdnType"]]] = $s["sFlvUrl"] . '/' . $s["sStreamName"] . '.' . $s["sFlvUrlSuffix"] . '?' . process_anticode($s["sFlvAntiCode"], $uid, $s["sStreamName"]);
|
91 |
+
}
|
92 |
+
if ($s["sHlsUrl"]) {
|
93 |
+
$stream_info["hls"][$cdn_type[$s["sCdnType"]]] = $s["sHlsUrl"] . '/' . $s["sStreamName"] . '.' . $s["sHlsUrlSuffix"] . '?' . process_anticode($s["sHlsAntiCode"], $uid, $s["sStreamName"]);
|
94 |
+
}
|
95 |
+
}
|
96 |
+
return $stream_info;
|
97 |
+
}
|
98 |
+
|
99 |
+
$res = get_content($roomurl, "mobile");
|
100 |
+
$reg = "/\<script\> window.HNF_GLOBAL_INIT = (.*) \<\/script\>/i";
|
101 |
+
preg_match($reg, $res, $realres);
|
102 |
+
$realdata = json_decode($realres[1], true);
|
103 |
+
|
104 |
+
if (in_array(0, $realdata) or in_array(1, $realdata)) {
|
105 |
+
header('location:' . $mediaurl);
|
106 |
+
exit();
|
107 |
+
} elseif ($realdata["roomInfo"]["eLiveStatus"] == 2) {
|
108 |
+
$realurl = format($realdata, $uid);
|
109 |
+
if ($type == "display") {
|
110 |
+
print_r($realurl);
|
111 |
+
exit();
|
112 |
+
}
|
113 |
+
if ($media == "flv") {
|
114 |
+
switch ($cdn) {
|
115 |
+
case $cdn:
|
116 |
+
$mediaurl = $realurl["flv"][$cdn];
|
117 |
+
break;
|
118 |
+
default:
|
119 |
+
$mediaurl = $realurl["flv"]["hwcdn"];
|
120 |
+
break;
|
121 |
+
}
|
122 |
+
}
|
123 |
+
if ($media == "hls") {
|
124 |
+
switch ($cdn) {
|
125 |
+
case $cdn:
|
126 |
+
$mediaurl = $realurl["hls"][$cdn];
|
127 |
+
break;
|
128 |
+
default:
|
129 |
+
$mediaurl = $realurl["hls"]["hwcdn"];
|
130 |
+
break;
|
131 |
+
}
|
132 |
+
}
|
133 |
+
header('location:' . $mediaurl);
|
134 |
+
exit;
|
135 |
+
} elseif ($realdata["roomInfo"]["eLiveStatus"] == 3) {
|
136 |
+
header('location:' . "http:" . base64_decode($realdata["roomProfile"]["liveLineUrl"]));
|
137 |
+
exit();
|
138 |
+
} else {
|
139 |
+
header('location:' . $mediaurl);
|
140 |
+
exit();
|
141 |
+
}
|