diff --git a/src/providers/all.ts b/src/providers/all.ts index 63be995..e32790e 100644 --- a/src/providers/all.ts +++ b/src/providers/all.ts @@ -31,6 +31,8 @@ import { streamvidScraper } from './embeds/streamvid'; import { vidCloudScraper } from './embeds/vidcloud'; import { vidplayScraper } from './embeds/vidplay'; import { voeScraper } from './embeds/voe'; +import { warezcdnembedHlsScraper } from './embeds/warezcdn/hls'; +import { warezcdnembedMp4Scraper } from './embeds/warezcdn/mp4'; import { wootlyScraper } from './embeds/wootly'; import { goojaraScraper } from './sources/goojara'; import { hdRezkaScraper } from './sources/hdrezka'; @@ -39,6 +41,7 @@ import { primewireScraper } from './sources/primewire'; import { ridooMoviesScraper } from './sources/ridomovies'; import { smashyStreamScraper } from './sources/smashystream'; import { vidSrcToScraper } from './sources/vidsrcto'; +import { warezcdnScraper } from './sources/warezcdn'; export function gatherAllSources(): Array { // all sources are gathered here @@ -58,6 +61,7 @@ export function gatherAllSources(): Array { goojaraScraper, hdRezkaScraper, primewireScraper, + warezcdnScraper, ]; } @@ -88,5 +92,7 @@ export function gatherAllEmbeds(): Array { droploadScraper, filelionsScraper, vTubeScraper, + warezcdnembedHlsScraper, + warezcdnembedMp4Scraper, ]; } diff --git a/src/providers/embeds/warezcdn/common.ts b/src/providers/embeds/warezcdn/common.ts new file mode 100644 index 0000000..5c944d7 --- /dev/null +++ b/src/providers/embeds/warezcdn/common.ts @@ -0,0 +1,57 @@ +import { warezcdnPlayerBase } from '@/providers/sources/warezcdn/common'; +import { EmbedScrapeContext } from '@/utils/context'; +import { NotFoundError } from '@/utils/errors'; + +function decrypt(input: string) { + let output = atob(input); + + // Remove leading and trailing whitespaces + output = output.trim(); + + // Reverse the string + output = output.split('').reverse().join(''); + + // Get the last 5 characters and reverse them + let last = output.slice(-5); + last = last.split('').reverse().join(''); + + // Remove the last 5 characters from the original string + output = output.slice(0, -5); + + // Return the original string concatenated with the reversed last 5 characters + return `${output}${last}`; +} + +export async function getDecryptedId(ctx: EmbedScrapeContext) { + const page = await ctx.proxiedFetcher(`/player.php?${new URLSearchParams({ id: ctx.url })}`, { + baseUrl: warezcdnPlayerBase, + headers: { + Referer: `${warezcdnPlayerBase}/getEmbed.php?${new URLSearchParams({ + id: ctx.url, + sv: 'warezcdn', + })}`, + }, + }); + const allowanceKey = page.match(/let allowanceKey = "(.*?)";/)?.[1]; + if (!allowanceKey) throw new NotFoundError('Failed to get allowanceKey'); + + const streamData = await ctx.proxiedFetcher('/functions.php', { + baseUrl: warezcdnPlayerBase, + method: 'POST', + body: new URLSearchParams({ + getVideo: ctx.url, + key: allowanceKey, + }), + }); + const stream = JSON.parse(streamData); + + if (!stream.id) throw new NotFoundError("can't get stream id"); + + const decryptedId = decrypt(stream.id); + + if (!decryptedId) throw new NotFoundError("can't get file id"); + + return decryptedId; +} + +export const warezcdnWorkerProxy = 'https://workerproxy.warezcdn.workers.dev'; diff --git a/src/providers/embeds/warezcdn/hls.ts b/src/providers/embeds/warezcdn/hls.ts new file mode 100644 index 0000000..1fbbef3 --- /dev/null +++ b/src/providers/embeds/warezcdn/hls.ts @@ -0,0 +1,44 @@ +import { flags } from '@/entrypoint/utils/targets'; +import { makeEmbed } from '@/providers/base'; +import { EmbedScrapeContext } from '@/utils/context'; +import { NotFoundError } from '@/utils/errors'; + +import { getDecryptedId } from './common'; + +// Method found by atpn +async function getVideowlUrlStream(ctx: EmbedScrapeContext, decryptedId: string) { + const sharePage = await ctx.proxiedFetcher('https://cloud.mail.ru/public/uaRH/2PYWcJRpH'); + const regex = /"videowl_view":\{"count":"(\d+)","url":"([^"]+)"\}/g; + const videowlUrl = regex.exec(sharePage)?.[2]; + + if (!videowlUrl) throw new NotFoundError('Failed to get videoOwlUrl'); + + return `${videowlUrl}/0p/${btoa(decryptedId)}.m3u8?${new URLSearchParams({ + double_encode: '1', + })}`; +} + +export const warezcdnembedHlsScraper = makeEmbed({ + id: 'warezcdnembedhls', // WarezCDN is both a source and an embed host + name: 'WarezCDN HLS', + rank: 82, + async scrape(ctx) { + const decryptedId = await getDecryptedId(ctx); + + if (!decryptedId) throw new NotFoundError("can't get file id"); + + const streamUrl = await getVideowlUrlStream(ctx, decryptedId); + + return { + stream: [ + { + id: 'primary', + type: 'hls', + flags: [flags.IP_LOCKED], + captions: [], + playlist: streamUrl, + }, + ], + }; + }, +}); diff --git a/src/providers/embeds/warezcdn/mp4.ts b/src/providers/embeds/warezcdn/mp4.ts new file mode 100644 index 0000000..d4a5cff --- /dev/null +++ b/src/providers/embeds/warezcdn/mp4.ts @@ -0,0 +1,56 @@ +import { makeEmbed } from '@/providers/base'; +import { EmbedScrapeContext } from '@/utils/context'; +import { NotFoundError } from '@/utils/errors'; + +import { getDecryptedId, warezcdnWorkerProxy } from './common'; + +const cdnListing = [50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64]; + +async function checkUrls(ctx: EmbedScrapeContext, fileId: string) { + for (const id of cdnListing) { + const url = `https://cloclo${id}.cloud.mail.ru/weblink/view/${fileId}`; + const response = await ctx.proxiedFetcher.full(url, { + method: 'GET', + headers: { + Range: 'bytes=0-1', + }, + }); + if (response.statusCode === 206) return url; + } + return null; +} + +export const warezcdnembedMp4Scraper = makeEmbed({ + id: 'warezcdnembedmp4', // WarezCDN is both a source and an embed host + name: 'WarezCDN MP4', + rank: 83, + disabled: false, + async scrape(ctx) { + const decryptedId = await getDecryptedId(ctx); + + if (!decryptedId) throw new NotFoundError("can't get file id"); + + const streamUrl = await checkUrls(ctx, decryptedId); + + if (!streamUrl) throw new NotFoundError("can't get stream id"); + + return { + stream: [ + { + id: 'primary', + captions: [], + qualities: { + unknown: { + type: 'mp4', + url: `${warezcdnWorkerProxy}/?${new URLSearchParams({ + url: streamUrl, + })}`, + }, + }, + type: 'file', + flags: [], + }, + ], + }; + }, +}); diff --git a/src/providers/sources/warezcdn/common.ts b/src/providers/sources/warezcdn/common.ts new file mode 100644 index 0000000..5fcde55 --- /dev/null +++ b/src/providers/sources/warezcdn/common.ts @@ -0,0 +1,3 @@ +export const warezcdnBase = 'https://embed.warezcdn.com'; +export const warezcdnApiBase = 'https://warezcdn.com/embed'; +export const warezcdnPlayerBase = 'https://warezcdn.com/player'; diff --git a/src/providers/sources/warezcdn/index.ts b/src/providers/sources/warezcdn/index.ts new file mode 100644 index 0000000..e504e41 --- /dev/null +++ b/src/providers/sources/warezcdn/index.ts @@ -0,0 +1,76 @@ +import { load } from 'cheerio'; + +import { SourcererEmbed, SourcererOutput, 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 { MovieScrapeContext, ShowScrapeContext } from '@/utils/context'; +import { NotFoundError } from '@/utils/errors'; + +import { warezcdnApiBase, warezcdnBase } from './common'; + +const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => { + if (!ctx.media.imdbId) throw new NotFoundError('This source requires IMDB id.'); + + let id = `filme/${ctx.media.imdbId}`; + if (ctx.media.type === 'show') + id = `serie/${ctx.media.imdbId}/${ctx.media.season.number}/${ctx.media.episode.number}`; + + const serversPage = await ctx.proxiedFetcher(`/${id}`, { + baseUrl: warezcdnBase, + }); + const $ = load(serversPage); + + const embedsHost = $('.hostList.active [data-load-embed]').get(); + + 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 params = new URLSearchParams({ + id: embedUrl, + sv: 'mixdrop', + }); + const realUrl = await ctx.proxiedFetcher(`/getPlay.php?${params}`, { + baseUrl: warezcdnApiBase, + headers: { + Referer: `${warezcdnApiBase}/getEmbed.php?${params}`, + }, + }); + + const realEmbedUrl = realUrl.match(/window\.location\.href="([^"]*)";/); + if (!realEmbedUrl) throw new Error('Could not find embed url'); + embeds.push({ + embedId: mixdropScraper.id, + url: realEmbedUrl[1], + }); + } else if (embedHost === 'warezcdn') { + embeds.push( + { + embedId: warezcdnembedHlsScraper.id, + url: embedUrl, + }, + { + embedId: warezcdnembedMp4Scraper.id, + url: embedUrl, + }, + ); + } + }); + + return { + embeds, + } as SourcererOutput; +}; + +export const warezcdnScraper = makeSourcerer({ + id: 'warezcdn', + name: 'WarezCDN', + rank: 81, + flags: [], + scrapeMovie: universalScraper, + scrapeShow: universalScraper, +});