-
Notifications
You must be signed in to change notification settings - Fork 0
/
mytv.txt
110 lines (99 loc) · 3.28 KB
/
mytv.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
error_reporting(E_ALL);
header('Content-Type: application/json;charset=UTF-8');
date_default_timezone_set("Asia/Shanghai");
function msseg($id)
{
$a = dirname(__FILE__);
$b = $a . '/dl/' . $id;
if (!is_dir($b)) {
mkdir($b, 0777, true);
}
return $b . '/';
}
$ip = '127.0.0.1';
$header = array(
"CLIENT-IP:" . $ip,
"X-FORWARDED-FOR:" . $ip,
);
$name = isset($_GET["id"]) ? preg_replace("/[^a-zA-Z0-9_\-]/", "", $_GET["id"]) : '';
$port = getenv('STREAM_SERVER_PORT') ?: '198.16.100.186:8278';
$nn = msseg($name);
$ts = isset($_GET["ts"]) ? basename($_GET["ts"]) : null;
$url = "http://" . $port . "/" . $name . "/playlist.m3u8?tid={TID}&tsum={TSUM}";
if ($ts && strstr($ts, ".ts")) {
$ch = curl_init();
$msg = $nn . $name . ".Host";
if (is_readable($msg)) {
$hots = file_get_contents($msg);
$url = $hots . $ts;
} else {
exit(json_encode(array("error" => "Host file not found")));
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$tsData = curl_exec($ch);
if (curl_errno($ch)) {
exit(json_encode(array("error" => curl_error($ch))));
}
curl_close($ch);
if (strlen($tsData) > 300) {
header("Content-Type: video/mp2t");
header('Content-Length: ' . strlen($tsData));
header("Content-Disposition: attachment; filename=" . $name . ".ts");
echo $tsData;
exit(0);
}
} else {
$heade = array(
"CLIENT-IP:" . $ip,
"X-FORWARDED-FOR:" . $ip,
"User-Agent: Dalvik/2.1.0 (Linux; U; Android 12; 22101316C Build/SP1A.210812.016)",
"Connection: Keep-Alive",
"Accept-Encoding: gzip"
);
$seed = "tvata nginx auth module";
$uri = preg_replace(array("/^.*url=/", "/^.+?\\:\/\/.+?\\//", "/\\?.+$/"), array("", "/", ""), $url);
$tid = "mc42afe745533";
$t = strval(intval(time() / 150));
$str = $seed . $uri . $tid . $t;
$tsum = md5($str);
$link = "ct=" . $t . "&tsum=" . $tsum;
$url = preg_replace("/\\{TID\\}/", $tid, $url);
$url = preg_replace("/[tsi]sum=\\{[TSI]SUM\\}/", $link, $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$m3u8 = curl_exec($ch);
if (curl_errno($ch)) {
exit(json_encode(array("error" => curl_error($ch))));
}
curl_close($ch);
if (strpos($m3u8, "EXTM3U") !== false) {
$m3u8s = explode("\n", $m3u8);
$m3u8 = '';
foreach ($m3u8s as $v) {
$v = str_replace("\r", '', $v);
if (strpos($v, ".ts") !== false) {
$m3u8 .= "Smartv.php?id=" . $name . "&ts=" . $v . "\n";
} else {
if ($v !== '') {
$m3u8 .= $v . "\n";
}
}
}
}
$msg = $nn . $name . ".m3u8";
file_put_contents($msg, $m3u8);
$msg = $nn . $name . ".Host";
$ser = "http://" . $port . "/" . $name . "/";
file_put_contents($msg, $ser);
header("Content-Type: application/vnd.apple.mpegurl");
header('Content-Length: ' . strlen($m3u8));
header("Content-Disposition: attachment; filename=" . $name . ".m3u8");
echo $m3u8;
exit(0);
}
?>