mirror of
https://gitlab.com/vyla-entertainment/sdk.git
synced 2026-11-16 23:27:31 -05:00
organized/fixed streams
This commit is contained in:
@@ -1,28 +1,8 @@
|
||||
import { getUA } from '../utils/helpers.js';
|
||||
import { getTmdbMetadata, getUA, resolveTmdbKey } from '../utils/helpers.js';
|
||||
|
||||
const BASE_URL = 'https://dulo.mov';
|
||||
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
async function resolveDetails(sdk, id, isTv) {
|
||||
const apiKey = sdk?.tmdbApiKey || process.env.TMDB_API_KEY;
|
||||
if (!apiKey) return null;
|
||||
const type = isTv ? 'tv' : 'movie';
|
||||
try {
|
||||
const res = await fetch(`https://api.themoviedb.org/3/${type}/${id}?api_key=${apiKey}`, {
|
||||
signal: AbortSignal.timeout(6000),
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json();
|
||||
const title = isTv ? data.name : data.title;
|
||||
const releaseDate = isTv ? data.first_air_date : data.release_date;
|
||||
const year = releaseDate ? releaseDate.split('-')[0] : '';
|
||||
const runtime = isTv ? (data.episode_run_time?.[0] || 24) : (data.runtime || 90);
|
||||
return { title, year, runtime };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
async function fetchSource(url, headers) {
|
||||
try {
|
||||
@@ -37,15 +17,17 @@ async function fetchSource(url, headers) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStream({ id, s, e, sdk }) {
|
||||
const isTv = Boolean(s && e);
|
||||
export async function getStream(args) {
|
||||
const { id, s, e, sdk } = args || {};
|
||||
const isTv = s != null && e != null;
|
||||
const mediaType = isTv ? 'tv' : 'movie';
|
||||
const apiKey = resolveTmdbKey(args, sdk);
|
||||
const ua = getUA();
|
||||
|
||||
const details = await resolveDetails(sdk, id, isTv);
|
||||
const title = details?.title || '';
|
||||
const year = details?.year || '';
|
||||
const runtime = details?.runtime || '';
|
||||
const meta = await getTmdbMetadata(id, isTv, apiKey);
|
||||
const title = meta?.title || '';
|
||||
const year = meta?.year || '';
|
||||
const runtime = meta?.runtime || '';
|
||||
|
||||
const referer = isTv
|
||||
? `${BASE_URL}/watch/tv/${id}/${s}/${e}`
|
||||
@@ -97,7 +79,7 @@ export async function getStream({ id, s, e, sdk }) {
|
||||
|
||||
while (pendingUrls.length > 0 && Date.now() < maxPollTime) {
|
||||
const results = await Promise.all(
|
||||
pendingUrls.map((url) => fetchSource(url, defaultHeaders))
|
||||
pendingUrls.map(url => fetchSource(url, defaultHeaders))
|
||||
);
|
||||
|
||||
const nextPending = [];
|
||||
@@ -119,7 +101,10 @@ export async function getStream({ id, s, e, sdk }) {
|
||||
|
||||
allUrls.push({
|
||||
url: streamUrl,
|
||||
server: src.label || 'Dulo',
|
||||
label: src.label || 'Dulo',
|
||||
quality: 'Auto',
|
||||
type: streamUrl.includes('.m3u8') ? 'hls' : 'mp4',
|
||||
headers: {
|
||||
'User-Agent': ua,
|
||||
Referer: referer,
|
||||
@@ -144,7 +129,7 @@ export async function getStream({ id, s, e, sdk }) {
|
||||
|
||||
return {
|
||||
url: allUrls[0].url,
|
||||
allUrls,
|
||||
headers: allUrls[0].headers,
|
||||
allUrls,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user