mirror of
https://gitlab.com/vyla-entertainment/sdk.git
synced 2026-11-13 21:57:27 -05:00
94 lines
2.8 KiB
JavaScript
94 lines
2.8 KiB
JavaScript
const BASE_URL = 'https://vidoraplayer.duckdns.org';
|
|
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36';
|
|
|
|
const HEADERS = {
|
|
'User-Agent': UA,
|
|
Referer: `${BASE_URL}/`,
|
|
Origin: BASE_URL,
|
|
Accept: 'application/x-ndjson, text/plain, */*',
|
|
'Accept-Language': 'en-US,en;q=0.9',
|
|
};
|
|
|
|
function parseNdjson(text) {
|
|
if (!text) return [];
|
|
const normalized = text.replace(/\}\s*\{/g, '}\n{');
|
|
const lines = normalized.split('\n');
|
|
const items = [];
|
|
for (const raw of lines) {
|
|
const line = raw.trim();
|
|
if (!line) continue;
|
|
try {
|
|
items.push(JSON.parse(line));
|
|
} catch { }
|
|
}
|
|
return items;
|
|
}
|
|
|
|
export async function getStream(args) {
|
|
const { id, s, e } = args || {};
|
|
const isTv = s != null && e != null;
|
|
|
|
const query = isTv
|
|
? `type=tv&id=${id}&season=${s}&episode=${e}`
|
|
: `type=movie&id=${id}`;
|
|
|
|
const urls = [
|
|
`${BASE_URL}/api/sources?${query}`,
|
|
`${BASE_URL}/api/sources?${query}&gen=2`,
|
|
];
|
|
|
|
const responses = await Promise.all(
|
|
urls.map(url =>
|
|
fetch(url, { headers: HEADERS })
|
|
.then(r => (r.ok ? r.text() : ''))
|
|
.catch(() => '')
|
|
)
|
|
);
|
|
|
|
const allUrls = [];
|
|
const seen = new Set();
|
|
|
|
for (const text of responses) {
|
|
const events = parseNdjson(text);
|
|
for (const item of events) {
|
|
const list = [];
|
|
if (item?.event === 'source' && item?.source) {
|
|
list.push(item.source);
|
|
} else if (item?.event === 'done' && Array.isArray(item?.sources)) {
|
|
list.push(...item.sources);
|
|
} else if (item?.url) {
|
|
list.push(item);
|
|
}
|
|
|
|
for (const src of list) {
|
|
if (!src?.url) continue;
|
|
const fullUrl = src.url.startsWith('http')
|
|
? src.url
|
|
: `${BASE_URL}${src.url.startsWith('/') ? '' : '/'}${src.url}`;
|
|
|
|
if (!seen.has(fullUrl)) {
|
|
seen.add(fullUrl);
|
|
allUrls.push({
|
|
url: fullUrl,
|
|
server: `Vidora - ${src.label || src.server || src.providerGroup || 'Default'}`,
|
|
quality: src.quality || 'Auto',
|
|
type: src.type || (fullUrl.includes('.m3u8') ? 'hls' : 'mp4'),
|
|
headers: {
|
|
Referer: `${BASE_URL}/`,
|
|
Origin: BASE_URL,
|
|
'User-Agent': UA,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!allUrls.length) return null;
|
|
|
|
return {
|
|
url: allUrls[0].url,
|
|
headers: allUrls[0].headers,
|
|
allUrls,
|
|
};
|
|
} |