Skip to content

Commit bb8c8e2

Browse files
committed
Idk
1 parent 2e72844 commit bb8c8e2

File tree

9 files changed

+91
-11
lines changed

9 files changed

+91
-11
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
CORS_PROXY="https://cors.eltik.net"
2-
WEB_SERVER_URL="https://m3u8.eltik.net"
2+
WEB_SERVER_URL="http://localhost:3030"
33
WEB_SERVER_PORT="3030"

built/libraries/M3U8Proxy.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export default class M3U8Proxy extends API {
44
private corsProxy;
55
constructor(url: string);
66
proxy(headers: any, reply: any): Promise<void>;
7+
proxyTs(headers: any, reply: any): Promise<void>;
78
}

built/libraries/M3U8Proxy.js

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

built/libraries/M3U8Proxy.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

built/server.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

built/server.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
</style>
2626
</head>
2727
<body>
28+
<h1>Very bad playground design but its fine</h1>
29+
<p>basically put in an m3u8 for the url, and put stringified headers into the headers section. yeah thats it.</p>
2830
<label for="url">URL</label>
29-
<input type="text" placeholder="https://geok.vizcloud.club/simple/EqPFJvkQWADtjDlGha7rC8cuqVxau_ftCE17rqk+wYMnU94US2El_Po4w12g/br/list.m3u8" id="url" />
30-
<textarea id="headers" placeholder='{"Referer": "https://9anime.pl"}'></textarea>
31+
<input type="text" id="url" value="https://wkmq.vizcloud.club/simple/EqPFIfMQWADtjDlGha7rC5AuoFwHuLmxQwN7rqk+wYMnU94US2El_Po4w12g/br/list.m3u8#.mp4" />
32+
<label for="headers">Headers</label>
33+
<textarea id="headers">{"Referer": "https://9anime.pl"}</textarea>
34+
<button onclick="test()">Test</button>
3135
<video id="hls" controls></video>
3236
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
3337
<script>
@@ -42,13 +46,16 @@
4246
alert("Invalid headers. Set headers to {}.");
4347
}
4448

49+
console.log("Using URL " + url);
50+
console.log("Using headers " + JSON.stringify(headers));
51+
4552
if (Hls.isSupported()) {
4653
var video = document.getElementById('hls');
4754
var hls = new Hls();
48-
hls.loadSource(`http://localhost:3060/m3u8_proxy?url=${encodeURIComponent(url)}&headers=${encodeURIComponent(JSON.stringify(headers))}`);
55+
hls.loadSource(`/m3u8_proxy?url=${encodeURIComponent(url)}&headers=${encodeURIComponent(JSON.stringify(headers))}`);
4956
hls.attachMedia(video);
5057
hls.on(Hls.Events.MANIFEST_PARSED, function() {
51-
console.log(`http://localhost:3060/m3u8_proxy?url=${encodeURIComponent(url)}&headers=${encodeURIComponent(JSON.stringify(headers))}`)
58+
console.log(`/m3u8_proxy?url=${encodeURIComponent(url)}&headers=${encodeURIComponent(JSON.stringify(headers))}`)
5259
});
5360
}
5461
}

src/libraries/M3U8Proxy.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { writeFileSync } from "fs";
12
import API from "../API";
23

34
export default class M3U8Proxy extends API {
@@ -23,7 +24,7 @@ export default class M3U8Proxy extends API {
2324
newLines.push(line);
2425
} else {
2526
const url = new URL(line, this.url);
26-
newLines.push(`${this.config.web_server.url + "/m3u8_proxy?url=" + encodeURIComponent(url.href) + "&headers=" + JSON.stringify(encodeURIComponent(headers))}`);
27+
newLines.push(`${this.config.web_server.url + "/m3u8_proxy?url=" + encodeURIComponent(url.href) + "&headers=" + encodeURIComponent(JSON.stringify(headers))}`);
2728
}
2829
}
2930
reply.header('Content-Type', 'application/vnd.apple.mpegurl');
@@ -41,7 +42,9 @@ export default class M3U8Proxy extends API {
4142
newLines.push(line);
4243
} else {
4344
const url = new URL(line, this.url);
44-
newLines.push(`${this.corsProxy + "/" + url.href}`);
45+
//newLines.push(`${this.corsProxy + "/" + url.href}`);
46+
//newLines.push(`${this.corsProxy}/${this.config.web_server.url + "/ts_proxy?url=" + encodeURIComponent(url.href) + "&headers=" + encodeURIComponent(JSON.stringify(headers))}`)
47+
newLines.push(`${this.config.web_server.url + "/ts_proxy?url=" + encodeURIComponent(url.href) + "&headers=" + encodeURIComponent(JSON.stringify(headers))}`);
4548
}
4649
}
4750
reply.header('Content-Type', 'application/vnd.apple.mpegurl');
@@ -52,4 +55,22 @@ export default class M3U8Proxy extends API {
5255
return;
5356
}
5457
}
58+
59+
public async proxyTs(headers:any, reply:any) {
60+
const res = await this.fetch(this.url, {
61+
headers: headers,
62+
});
63+
const data = res.raw();
64+
reply.header('Content-Type', data.headers['content-type'] ?? 'video/mp2t');
65+
66+
if (data.headers["content-length"]) {
67+
reply.header('Content-Length', data.headers["content-length"]);
68+
}
69+
if (data.headers["content-range"]) {
70+
reply.header('Content-Range', data.headers["content-range"]);
71+
}
72+
73+
reply.send(data.data);
74+
return;
75+
}
5576
}

src/server.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ fastify.get("/m3u8_proxy*", async(req, res) => {
6565
await m3u8Proxy.proxy(headers, res);
6666
})
6767

68+
fastify.get("/ts_proxy*", async(req, res) => {
69+
const url = req.query["url"]
70+
let headers = decodeURIComponent(req.query["headers"]);
71+
try {
72+
headers = JSON.parse(headers);
73+
} catch {
74+
res.type("application/json").code(400);
75+
return { error: "Invalid headers." };
76+
}
77+
if (!url || url.length === 0) {
78+
res.type("application/json").code(400);
79+
return { error: "Invalid URL." };
80+
}
81+
const m3u8Proxy = new M3U8Proxy(url);
82+
await m3u8Proxy.proxyTs(headers, res);
83+
})
84+
6885
// temp
6986
fastify.get("/test", (req, res) => {
7087
const file = readFileSync(join(__dirname, "../index.html"));

0 commit comments

Comments
 (0)