Files
Inside4ndroid 2c9a2cabbf Add new providers for streaming services and utility functions
- Implement StreamFlix provider for fetching movie and episode streams.
- Add VaPlayer provider to retrieve streaming URLs for movies and TV shows.
- Introduce ZXCStreams provider for accessing various streaming links.
- Create utility functions for fetching episode counts from Cinemeta.
- Develop a title matching system for improved search results.
- Implement TMDB title to IMDB ID resolution for better integration with TMDB API.
2026-08-19 23:35:13 +01:00

39 lines
1.5 KiB
JavaScript

const fetch = (...args) => import('node-fetch').then(m => m.default(...args));
const { getTmdbApiKey } = require('./tmdbKey');
const cache = {
imdbByTmdb: new Map(),
details: new Map(),
};
const TTL_MS = 6 * 60 * 60 * 1000;
function isFresh(entry) { return entry && (Date.now() - entry.ts) < TTL_MS; }
async function tmdbFetchJson(url) {
const apiKey = getTmdbApiKey();
if (!apiKey) throw new Error('TMDB_API_KEY missing');
const sep = url.includes('?') ? '&' : '?';
const full = `${url}${sep}api_key=${apiKey}`;
const res = await fetch(full, { timeout: 15000 });
if (!res.ok) throw new Error(`TMDB request failed ${res.status}`);
return res.json();
}
async function getExternalIds(type, tmdbId) {
const key = `${type}:${tmdbId}`;
const cached = cache.imdbByTmdb.get(key);
if (isFresh(cached)) return cached.data;
const json = await tmdbFetchJson(`https://api.themoviedb.org/3/${type}/${tmdbId}/external_ids`);
cache.imdbByTmdb.set(key, { data: json, ts: Date.now() });
return json;
}
async function getDetails(type, tmdbId) {
const key = `${type}:${tmdbId}:details`;
const cached = cache.details.get(key);
if (isFresh(cached)) return cached.data;
const json = await tmdbFetchJson(`https://api.themoviedb.org/3/${type}/${tmdbId}`);
cache.details.set(key, { data: json, ts: Date.now() });
return json;
}
async function resolveImdbId(type, tmdbId) {
try { const ext = await getExternalIds(type, tmdbId); return ext.imdb_id || null; } catch { return null; }
}
module.exports = { getExternalIds, getDetails, resolveImdbId };