fix
This commit is contained in:
+47
-1
@@ -226,7 +226,53 @@ async function extractStreamUrl(url) {
|
||||
|
||||
if (file) {
|
||||
const titleMap = { sub: "Hardsub English", softsub: "Original audio", dub: "Dubbed English" };
|
||||
streams.push({ title: titleMap[type] || type, streamUrl: "https://1anime.app/api/m3u8-proxy?url=" + file });
|
||||
let pushedQualities = 0;
|
||||
const baseTitle = titleMap[type] || type;
|
||||
|
||||
try {
|
||||
const proxyReqUrl = "https://1anime.app/api/m3u8-proxy?url=" + encodeURIComponent(file);
|
||||
const m3u8Response = await fetchv2(proxyReqUrl);
|
||||
const m3u8Text = await m3u8Response.text();
|
||||
const lines = m3u8Text.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i].trim();
|
||||
if (line.startsWith('#EXT-X-STREAM-INF:')) {
|
||||
const resolutionMatch = line.match(/RESOLUTION=(\d+x\d+)/);
|
||||
const nameMatch = line.match(/NAME="([^"]+)"/i) || line.match(/BANDWIDTH=(\d+)/i);
|
||||
|
||||
let quality = 'Unknown';
|
||||
if (resolutionMatch) {
|
||||
const [width, height] = resolutionMatch[1].split('x');
|
||||
quality = `${height}p`;
|
||||
} else if (nameMatch && nameMatch[1]) {
|
||||
quality = nameMatch[1];
|
||||
}
|
||||
|
||||
if (i + 1 < lines.length) {
|
||||
let streamPath = lines[i + 1].trim();
|
||||
let absolutePath;
|
||||
if (streamPath.startsWith('/api/')) {
|
||||
absolutePath = 'https://1anime.app' + streamPath;
|
||||
} else if (streamPath.startsWith('http')) {
|
||||
absolutePath = 'https://1anime.app/api/m3u8-proxy?url=' + encodeURIComponent(streamPath);
|
||||
} else {
|
||||
const baseUrl = file.substring(0, file.lastIndexOf('/') + 1);
|
||||
absolutePath = 'https://1anime.app/api/m3u8-proxy?url=' + encodeURIComponent(baseUrl + streamPath);
|
||||
}
|
||||
streams.push({
|
||||
title: `${quality} - ${baseTitle}`,
|
||||
streamUrl: absolutePath
|
||||
});
|
||||
pushedQualities++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Failed to extract qualities:", e);
|
||||
}
|
||||
if (pushedQualities === 0) {
|
||||
streams.push({ title: baseTitle, streamUrl: "https://1anime.app/api/m3u8-proxy?url=" + encodeURIComponent(file) });
|
||||
}
|
||||
}
|
||||
|
||||
for (const track of tracks) {
|
||||
|
||||
Reference in New Issue
Block a user