fixed vixsrc audio

This commit is contained in:
2026-10-05 20:49:23 -07:00
parent d1fad8d9d0
commit 6d9ffdc7b6
2 changed files with 37 additions and 35 deletions

View File

@@ -52,8 +52,8 @@ export async function getStream({ id, s, e, absoluteBase }) {
playlist = `${BASE_URL}${playlist}`; playlist = `${BASE_URL}${playlist}`;
} }
const lang = extract(/lang(?:uage)?["']\s*:\s*["']([a-z]{2,5})/i, html) || 'en'; const defaultLang = extract(/lang(?:uage)?["']\s*:\s*["']([a-z]{2,5})/i, html) || 'en';
const rawMasterUrl = `${playlist}${playlist.includes('?') ? '&' : '?'}token=${token}&expires=${expires}&h=1&lang=${lang}`; const rawMasterUrl = `${playlist}${playlist.includes('?') ? '&' : '?'}token=${token}&expires=${expires}&h=1&lang=${defaultLang}`;
const masterProxy = absoluteBase && absoluteBase !== '/' const masterProxy = absoluteBase && absoluteBase !== '/'
? `${absoluteBase.replace(/^https:\/\/(localhost|127\.0\.0\.1)/, 'http://$1')}/api?url=${encodeURIComponent(rawMasterUrl)}&proxyHeaders=${encodeURIComponent(JSON.stringify({ ...HEADERS, Referer: embedUrl }))}` ? `${absoluteBase.replace(/^https:\/\/(localhost|127\.0\.0\.1)/, 'http://$1')}/api?url=${encodeURIComponent(rawMasterUrl)}&proxyHeaders=${encodeURIComponent(JSON.stringify({ ...HEADERS, Referer: embedUrl }))}`
@@ -62,50 +62,52 @@ export async function getStream({ id, s, e, absoluteBase }) {
const playlistText = await fetchText(masterProxy, { headers: { ...HEADERS, 'Referer': embedUrl } }).catch(() => null); const playlistText = await fetchText(masterProxy, { headers: { ...HEADERS, 'Referer': embedUrl } }).catch(() => null);
if (!playlistText?.includes('#EXTM3U')) return null; if (!playlistText?.includes('#EXTM3U')) return null;
let finalUrl = null;
let bestHeight = 0;
const lines = playlistText.split('\n'); const lines = playlistText.split('\n');
const audioTracks = [];
const seen = new Set();
for (let i = 0; i < lines.length; i++) { for (const line of lines) {
const line = lines[i]; if (line.startsWith('#EXT-X-MEDIA') && line.includes('TYPE=AUDIO')) {
if (!line.startsWith('#EXT-X-STREAM-INF')) continue; const name = line.match(/NAME=["']([^"']+)["']/)?.[1] || 'Default';
const height = parseInt(line.match(/RESOLUTION=\d+x(\d+)/)?.[1] || '0', 10); const rendition = line.match(/rendition=([a-zA-Z0-9_-]+)/)?.[1]
let next = lines[i + 1]?.trim(); || line.match(/LANGUAGE=["']([^"']+)["']/)?.[1]
if (!next || next.startsWith('#')) continue; || name;
const key = rendition.toLowerCase();
if (height > bestHeight) { if (!seen.has(key)) {
bestHeight = height; seen.add(key);
finalUrl = next; audioTracks.push({ name, lang: rendition });
}
} }
} }
if (!finalUrl) finalUrl = rawMasterUrl; const allUrls = [];
if (!finalUrl.startsWith('http')) { if (audioTracks.length > 0) {
const baseMatch = rawMasterUrl.match(/^(https?:\/\/[^\/]+)/); for (const track of audioTracks) {
const base = baseMatch ? baseMatch[1] : BASE_URL; const streamUrl = `${playlist}${playlist.includes('?') ? '&' : '?'}token=${token}&expires=${expires}&h=1&lang=${track.lang}`;
if (finalUrl.startsWith('/')) { allUrls.push({
finalUrl = `${base}${finalUrl}`; url: streamUrl,
server: `VixSrc (${track.name})`,
skipProxy: true,
headers: {
...HEADERS,
'Referer': `${BASE_URL}/`
}
});
}
} else { } else {
const pathParts = rawMasterUrl.split('/'); allUrls.push({
pathParts.pop(); url: rawMasterUrl,
finalUrl = `${pathParts.join('/')}/${finalUrl}`;
}
}
return {
allUrls: [
{
url: finalUrl,
server: 'VixSrc', server: 'VixSrc',
skipProxy: true, skipProxy: true,
headers: { headers: {
...HEADERS, ...HEADERS,
'Referer': `${BASE_URL}/` 'Referer': `${BASE_URL}/`
} }
});
} }
]
}; return { allUrls };
} catch (err) { } catch (err) {
return null; return null;
} }

View File

@@ -13,7 +13,7 @@ const CONFIG = {
TV_ID: "37854", // TV TMDB ID to test, for anime I recommend using a random ID like 37854 TV_ID: "37854", // TV TMDB ID to test, for anime I recommend using a random ID like 37854
TV_SEASON: "1", // TV Season to test TV_SEASON: "1", // TV Season to test
TV_EPISODE: "1", // TV Episode to test TV_EPISODE: "1", // TV Episode to test
STREAM_SOURCE: "", // Source key to test STREAM_SOURCE: "vixsrc", // Source key to test
TEST_SUBTITLE: false, // Toggle subtitle testing TEST_SUBTITLE: false, // Toggle subtitle testing
TEST_DOWNLOAD: false, // Toggle download testing TEST_DOWNLOAD: false, // Toggle download testing