Fix warezcdn

This commit is contained in:
TPN 2024-12-08 12:01:29 +00:00
parent 1010fc5882
commit a2c8784369
No known key found for this signature in database
GPG key ID: 40AE091637892B91
3 changed files with 83 additions and 87 deletions

View file

@ -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) {

View file

@ -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<SourcererEmbed[]> {
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<string>(`/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<string>(`/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<string>(`/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<string>(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<string>(`/serieAjax.php`, {
method: 'POST',
const streamsData = await ctx.proxiedFetcher<cachedSeasonsRes>(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<string>('/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,

View file

@ -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<string, Episode>;
}
export interface cachedSeasonsRes {
seasonCount: number;
seasons: Record<string, Season>;
}