Refactored Source to Url association, no longer breaks if domain changes

This commit is contained in:
Paradox-77
2024-03-15 00:18:30 +05:30
parent fed8678ef1
commit bd0f1e2ddc

View File

@@ -33,7 +33,7 @@ const universalScraper = async (ctx: ShowScrapeContext | MovieScrapeContext): Pr
if (sources.status !== 200) throw new Error('No sources found'); if (sources.status !== 200) throw new Error('No sources found');
const embeds: SourcererEmbed[] = []; const embeds: SourcererEmbed[] = [];
const embedUrls = []; const embedArr = [];
for (const source of sources.result) { for (const source of sources.result) {
const sourceRes = await ctx.proxiedFetcher<SourceResult>(`/ajax/embed/source/${source.id}`, { const sourceRes = await ctx.proxiedFetcher<SourceResult>(`/ajax/embed/source/${source.id}`, {
baseUrl: vidSrcToBase, baseUrl: vidSrcToBase,
@@ -42,28 +42,26 @@ const universalScraper = async (ctx: ShowScrapeContext | MovieScrapeContext): Pr
}, },
}); });
const decryptedUrl = decryptSourceUrl(sourceRes.result.url); const decryptedUrl = decryptSourceUrl(sourceRes.result.url);
embedUrls.push(decryptedUrl); embedArr.push({ source: source.title, url: decryptedUrl });
} }
// Originally Filemoon does not have subtitles. But we can use the ones from Vidplay. // Originally Filemoon does not have subtitles. But we can use the ones from Vidplay.
const urlWithSubtitles = embedUrls.find((v) => v.includes('sub.info')); const urlWithSubtitles = embedArr.find((v) => v.url.includes('sub.info'))?.url;
let subtitleUrl: string | null = null; let subtitleUrl: string | null = null;
if (urlWithSubtitles) subtitleUrl = new URL(urlWithSubtitles).searchParams.get('sub.info'); if (urlWithSubtitles) subtitleUrl = new URL(urlWithSubtitles).searchParams.get('sub.info');
for (const source of sources.result) { for (const embedObj of embedArr) {
if (source.title === 'Vidplay') { if (embedObj.source === 'Vidplay') {
const embedUrl = embedUrls.find((v) => v.match(/https:\/\/(?:[a-zA-Z0-9]{10})\./)); const fullUrl = new URL(embedObj.url);
if (!embedUrl) continue; if (subtitleUrl) fullUrl.searchParams.set('sub.info', subtitleUrl);
embeds.push({ embeds.push({
embedId: 'vidplay', embedId: 'vidplay',
url: embedUrl, url: fullUrl.toString(),
}); });
} }
if (source.title === 'Filemoon') { if (embedObj.source === 'Filemoon') {
const embedUrl = embedUrls.find((v) => v.includes('kerapoxy')); const fullUrl = new URL(embedObj.url);
if (!embedUrl) continue;
const fullUrl = new URL(embedUrl);
if (subtitleUrl) fullUrl.searchParams.set('sub.info', subtitleUrl); if (subtitleUrl) fullUrl.searchParams.set('sub.info', subtitleUrl);
embeds.push({ embeds.push({
embedId: 'filemoon', embedId: 'filemoon',