Skip to content

Commit 4f03011

Browse files
committed
Update code to version 1.4.0
1 parent ce9f6bd commit 4f03011

1 file changed

Lines changed: 30 additions & 30 deletions

File tree

1.4.0/index.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ const PROXY_DOMAINS = [
100100
'[^/]+\\.pki\\.goog(:\\d+)?',
101101
'thetv-ts\\.wx\\.sb',
102102
'[^/]+\\.v2h-cdn\\.com(:\\d+)?',
103-
'v12.thetvapp.to'
103+
'v12.thetvapp.to',
104+
'thetvapp\\.to'
104105
];
105106

106107
if (CUSTOM_M3U_PROXY && CUSTOM_M3U_PROXY_HOST) {
107108
PROXY_DOMAINS.push(CUSTOM_M3U_PROXY_HOST);
108109
}
110+
109111
// Define source addresses
110112
const SRC = [
111113
...EXTRA_M3U_URLS,
@@ -169,12 +171,10 @@ function identity(it) { return it; }
169171
function addProxyHeader(originalUrl, encodeUrl = false) {
170172
if (!originalUrl) return originalUrl;
171173

172-
// 更严格的检查,如果已经包含代理头,直接返回
173174
if (originalUrl.includes(`${VPS_HOST}/${SECURITY_TOKEN}/proxy/`)) {
174175
return originalUrl;
175176
}
176177

177-
// 检查是否匹配代理域名
178178
for (const dom of PROXY_DOMAINS) {
179179
const regex = new RegExp(`^https?://${dom}`, 'i');
180180
if (regex.test(originalUrl)) {
@@ -187,7 +187,6 @@ function addProxyHeader(originalUrl, encodeUrl = false) {
187187

188188
function proxify(it) {
189189
return it.replace(/https?:\/\/[^\s"']*/g, (match) => {
190-
// 如果已经有代理前缀,直接返回
191190
if (match.startsWith(`${VPS_HOST}/${SECURITY_TOKEN}/proxy/`)) {
192191
return match;
193192
}
@@ -279,7 +278,6 @@ async function handleList(req, res) {
279278
logDebug(`Filtered ${src.name || 'Extra M3U'}: ${beforeLen} -> ${afterLen} channels`);
280279
}
281280

282-
// 只对非VPS源应用代理修改
283281
if (src.mod && !src.noProxy) {
284282
const noproxy = req.url.indexOf('noproxy') > -1;
285283
logDebug(`Applying ${noproxy ? 'direct' : 'proxy'} modifications to ${src.name || 'Extra M3U'}`);
@@ -315,7 +313,6 @@ async function handleProxy(req, res) {
315313
const headers = new Headers(req.headers);
316314
headers.delete('host');
317315

318-
// 特别处理 TheTV 的请求
319316
if (targetUrl.includes('v12.thetvapp.to')) {
320317
headers.set('Referer', 'https://v12.thetvapp.to/');
321318
headers.set('Origin', 'https://v12.thetvapp.to');
@@ -325,10 +322,9 @@ async function handleProxy(req, res) {
325322
method: req.method,
326323
headers: headers,
327324
body: req.method !== 'GET' && req.method !== 'HEAD' ? req : undefined,
328-
redirect: 'manual' // 手动处理重定向
325+
redirect: 'manual'
329326
});
330327

331-
// 处理重定向
332328
if ([301, 302, 303, 307, 308].includes(response.status)) {
333329
const location = response.headers.get('location');
334330
if (location) {
@@ -345,7 +341,6 @@ async function handleProxy(req, res) {
345341
const contentType = response.headers.get('content-type');
346342

347343
if (targetUrl.includes('/thetv/drm')) {
348-
// DRM 请求直接转发,无需代理
349344
const drmResponse = await fetch(targetUrl, {
350345
method: req.method,
351346
headers: headers
@@ -359,28 +354,33 @@ async function handleProxy(req, res) {
359354

360355
for (const line of m3u8Lines) {
361356
if (line.startsWith('#EXT-X-KEY')) {
362-
// 处理 KEY 行,将相对路径的 URI 转换为完整 URL
363-
let modifiedLine = line.replace(
364-
/URI="([^"]+)"/,
365-
(match, uri) => {
366-
if (uri.startsWith('/')) {
367-
// 相对路径转换为完整 URL
368-
const fullUrl = new URL(uri, targetUrl).href;
369-
return `URI="${fullUrl}"`;
357+
let modifiedLine = line.replace(
358+
/URI="([^"]+)"/,
359+
(match, uri) => {
360+
if (uri.includes('thetv')) {
361+
let fullUrl;
362+
if (uri.startsWith('http')) {
363+
fullUrl = uri;
364+
} else if (uri.startsWith('/')) {
365+
fullUrl = new URL(uri, 'https://thetvapp.to').href;
366+
} else {
367+
fullUrl = new URL(uri, targetUrl).href;
368+
}
369+
return `URI="${addProxyHeader(fullUrl)}"`;
370+
}
371+
return `URI="${uri}"`;
370372
}
371-
return `URI="${uri}"`;
372-
}
373-
);
374-
modifiedLines.push(modifiedLine);
375-
} else if (line.trim().startsWith('http')) {
376-
const proxiedUrl = addProxyHeader(line.trim());
377-
modifiedLines.push(proxiedUrl);
378-
} else if (!line.startsWith('#') && line.trim().endsWith('.ts')) {
379-
const absoluteUrl = new URL(line.trim(), targetUrl).href;
380-
const proxiedUrl = addProxyHeader(absoluteUrl);
381-
modifiedLines.push(proxiedUrl);
382-
} else {
383-
modifiedLines.push(line);
373+
);
374+
modifiedLines.push(modifiedLine);
375+
} else if (line.trim().startsWith('http')) {
376+
const proxiedUrl = addProxyHeader(line.trim());
377+
modifiedLines.push(proxiedUrl);
378+
} else if (!line.startsWith('#') && line.trim()) {
379+
const absoluteUrl = new URL(line.trim(), targetUrl).href;
380+
const proxiedUrl = addProxyHeader(absoluteUrl);
381+
modifiedLines.push(proxiedUrl);
382+
} else {
383+
modifiedLines.push(line);
384384
}
385385
}
386386

0 commit comments

Comments
 (0)