From a2c8784369166b16e3819cf74ff8edd5652a5901 Mon Sep 17 00:00:00 2001 From: TPN Date: Sun, 8 Dec 2024 12:01:29 +0000 Subject: [PATCH] Fix warezcdn --- src/providers/sources/warezcdn/common.ts | 6 +- src/providers/sources/warezcdn/index.ts | 134 +++++++++++------------ src/providers/sources/warezcdn/types.ts | 30 +++-- 3 files changed, 83 insertions(+), 87 deletions(-) diff --git a/src/providers/sources/warezcdn/common.ts b/src/providers/sources/warezcdn/common.ts index 182b2b6..c63c257 100644 --- a/src/providers/sources/warezcdn/common.ts +++ b/src/providers/sources/warezcdn/common.ts @@ -1,8 +1,8 @@ import { ScrapeContext } from '@/utils/context'; -export const warezcdnBase = 'https://embed.warezcdn.com'; -export const warezcdnApiBase = 'https://warezcdn.com/embed'; -export const warezcdnPlayerBase = 'https://warezcdn.com/player'; +export const warezcdnBase = 'https://embed.warezcdn.link'; +export const warezcdnApiBase = 'https://warezcdn.link/embed'; +export const warezcdnPlayerBase = 'https://warezcdn.link/player'; export const warezcdnWorkerProxy = 'https://workerproxy.warezcdn.workers.dev'; export async function getExternalPlayerUrl(ctx: ScrapeContext, embedId: string, embedUrl: string) { diff --git a/src/providers/sources/warezcdn/index.ts b/src/providers/sources/warezcdn/index.ts index a119f8f..15b0f54 100644 --- a/src/providers/sources/warezcdn/index.ts +++ b/src/providers/sources/warezcdn/index.ts @@ -1,15 +1,51 @@ -import { load } from 'cheerio'; - import { flags } from '@/entrypoint/utils/targets'; import { SourcererEmbed, makeSourcerer } from '@/providers/base'; import { mixdropScraper } from '@/providers/embeds/mixdrop'; import { warezcdnembedHlsScraper } from '@/providers/embeds/warezcdn/hls'; import { warezcdnembedMp4Scraper } from '@/providers/embeds/warezcdn/mp4'; import { warezPlayerScraper } from '@/providers/embeds/warezcdn/warezplayer'; +import { ScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; -import { getExternalPlayerUrl, warezcdnBase } from './common'; -import { SerieAjaxResponse } from './types'; +import { warezcdnBase } from './common'; +import { cachedSeasonsRes } from './types'; + +async function getEmbeds(id: string, servers: string, ctx: ScrapeContext): Promise { + const embeds: SourcererEmbed[] = []; + + for (const server of servers.split(',')) { + if (server === 'warezcdn') { + embeds.push( + { embedId: warezcdnembedHlsScraper.id, url: id }, + { embedId: warezcdnembedMp4Scraper.id, url: id }, + { embedId: warezPlayerScraper.id, url: id }, + ); + } else if (server === 'mixdrop') { + // Without this req, the next one fails + await ctx.proxiedFetcher(`/getEmbed.php`, { + baseUrl: warezcdnBase, + headers: { + Referer: `${warezcdnBase}/getEmbed.php?${new URLSearchParams({ id, sv: 'mixdrop' })}`, + }, + method: 'HEAD', + query: { id, sv: 'mixdrop' }, + }); + + const embedPage = await ctx.proxiedFetcher(`/getPlay.php`, { + baseUrl: warezcdnBase, + headers: { + Referer: `${warezcdnBase}/getEmbed.php?${new URLSearchParams({ id, sv: 'mixdrop' })}`, + }, + query: { id, sv: 'mixdrop' }, + }); + + const url = embedPage.match(/window.location.href\s*=\s*"([^"]+)"/)?.[1]; + if (url) embeds.push({ embedId: mixdropScraper.id, url }); + } + } + + return embeds; +} export const warezcdnScraper = makeSourcerer({ id: 'warezcdn', @@ -18,44 +54,14 @@ export const warezcdnScraper = makeSourcerer({ flags: [flags.CORS_ALLOWED], scrapeMovie: async (ctx) => { if (!ctx.media.imdbId) throw new NotFoundError('This source requires IMDB id.'); - const serversPage = await ctx.proxiedFetcher(`/filme/${ctx.media.imdbId}`, { baseUrl: warezcdnBase, }); - const $ = load(serversPage); - const embedsHost = $('.hostList.active [data-load-embed]').get(); + const [, id, servers] = serversPage.match(/let\s+data\s*=\s*'\[\s*\{\s*"id":"([^"]+)".*?"servers":"([^"]+)"/)!; + if (!id || !servers) throw new NotFoundError('Failed to find episode id'); - const embeds: SourcererEmbed[] = []; - - embedsHost.forEach(async (element) => { - const embedHost = $(element).attr('data-load-embed-host')!; - const embedUrl = $(element).attr('data-load-embed')!; - - if (embedHost === 'mixdrop') { - const realEmbedUrl = await getExternalPlayerUrl(ctx, 'mixdrop', embedUrl); - if (!realEmbedUrl) throw new Error('Could not find embed url'); - embeds.push({ - embedId: mixdropScraper.id, - url: realEmbedUrl, - }); - } else if (embedHost === 'warezcdn') { - embeds.push( - { - embedId: warezcdnembedHlsScraper.id, - url: embedUrl, - }, - { - embedId: warezcdnembedMp4Scraper.id, - url: embedUrl, - }, - { - embedId: warezPlayerScraper.id, - url: embedUrl, - }, - ); - } - }); + const embeds: SourcererEmbed[] = await getEmbeds(id, servers, ctx); return { embeds, @@ -63,54 +69,38 @@ export const warezcdnScraper = makeSourcerer({ }, scrapeShow: async (ctx) => { if (!ctx.media.imdbId) throw new NotFoundError('This source requires IMDB id.'); - const url = `${warezcdnBase}/serie/${ctx.media.imdbId}/${ctx.media.season.number}/${ctx.media.episode.number}`; - const serversPage = await ctx.proxiedFetcher(url); - const episodeId = serversPage.match(/\$\('\[data-load-episode-content="(\d+)"\]'\)/)?.[1]; + const seasonsApi = serversPage.match(/var\s+cachedSeasons\s*=\s*"([^"]+)"/)?.[1]; + if (!seasonsApi) throw new NotFoundError('Failed to find data'); - if (!episodeId) throw new NotFoundError('Failed to find episode id'); - - const streamsData = await ctx.proxiedFetcher(`/serieAjax.php`, { - method: 'POST', + const streamsData = await ctx.proxiedFetcher(seasonsApi, { baseUrl: warezcdnBase, - body: new URLSearchParams({ - getAudios: episodeId, - }), headers: { - Origin: warezcdnBase, Referer: url, 'X-Requested-With': 'XMLHttpRequest', }, }); - const streams: SerieAjaxResponse = JSON.parse(streamsData); - const list = streams.list['0']; - const embeds: SourcererEmbed[] = []; + const season = Object.values(streamsData.seasons).find((s) => s.name === ctx.media.season.number.toString()); + if (!season) throw new NotFoundError('Failed to find season id'); + const episode = Object.values(season.episodes).find((e) => e.name === ctx.media.season.number.toString())?.id; + if (!episode) throw new NotFoundError('Failed to find episode id'); - // 3 means ok - if (list.mixdropStatus === '3') { - const realEmbedUrl = await getExternalPlayerUrl(ctx, 'mixdrop', list.id); - if (!realEmbedUrl) throw new Error('Could not find embed url'); - embeds.push({ - embedId: mixdropScraper.id, - url: realEmbedUrl, - }); - } + const episodeData = await ctx.proxiedFetcher('/core/ajax.php', { + baseUrl: warezcdnBase, + headers: { + Referer: url, + 'X-Requested-With': 'XMLHttpRequest', + }, + query: { audios: episode }, + }); - if (list.warezcdnStatus === '3') { - embeds.push( - { - embedId: warezcdnembedHlsScraper.id, - url: list.id, - }, - { - embedId: warezcdnembedMp4Scraper.id, - url: list.id, - }, - ); - } + const [, id, servers] = episodeData.replace(/\\"/g, '"').match(/"\[\s*\{\s*"id":"([^"]+)".*?"servers":"([^"]+)"/)!; + if (!id || !servers) throw new NotFoundError('Failed to find episode id'); + + const embeds: SourcererEmbed[] = await getEmbeds(id, servers, ctx); return { embeds, diff --git a/src/providers/sources/warezcdn/types.ts b/src/providers/sources/warezcdn/types.ts index 38711ff..0bd5a94 100644 --- a/src/providers/sources/warezcdn/types.ts +++ b/src/providers/sources/warezcdn/types.ts @@ -1,16 +1,22 @@ -interface Data { +interface Episode { id: string; - audio: string; - mixdropStatus: string; - fembedStatus: string; - streamtapeStatus: string; - warezcdnStatus: string; + name: string; + editedName: string | null; + released: string; + titlePt: string; + rating: string; + runtime: string; + airdate: string; } -type List = { - [key: string]: Data; -}; - -export interface SerieAjaxResponse { - list: List; +interface Season { + id: string; + name: string; + episodesCount: number; + episodes: Record; +} + +export interface cachedSeasonsRes { + seasonCount: number; + seasons: Record; }