mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 13:33:25 +00:00
@@ -1,10 +1,9 @@
|
|||||||
import { flags } from '@/entrypoint/utils/targets';
|
import { flags } from '@/entrypoint/utils/targets';
|
||||||
import { ScrapeMedia } from '@/index';
|
|
||||||
import { SourcererOutput, makeSourcerer } from '@/providers/base';
|
import { SourcererOutput, makeSourcerer } from '@/providers/base';
|
||||||
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
|
|
||||||
import { VideoLinks } from './types';
|
import { MovieData, VideoLinks } from './types';
|
||||||
import { extractTitleAndYear, generateRandomFavs, parseSubtitleLinks, parseVideoLinks } from './utils';
|
import { extractTitleAndYear, generateRandomFavs, parseSubtitleLinks, parseVideoLinks } from './utils';
|
||||||
|
|
||||||
const rezkaBase = 'https://hdrzk.org';
|
const rezkaBase = 'https://hdrzk.org';
|
||||||
@@ -13,7 +12,7 @@ const baseHeaders = {
|
|||||||
'X-Hdrezka-Android-App-Version': '2.2.0',
|
'X-Hdrezka-Android-App-Version': '2.2.0',
|
||||||
};
|
};
|
||||||
|
|
||||||
async function searchAndFindMediaId(ctx: ShowScrapeContext | MovieScrapeContext): Promise<string | null> {
|
async function searchAndFindMediaId(ctx: ShowScrapeContext | MovieScrapeContext): Promise<MovieData | null> {
|
||||||
const itemRegexPattern = /<a href="([^"]+)"><span class="enty">([^<]+)<\/span> \(([^)]+)\)/g;
|
const itemRegexPattern = /<a href="([^"]+)"><span class="enty">([^<]+)<\/span> \(([^)]+)\)/g;
|
||||||
const idRegexPattern = /\/(\d+)-[^/]+\.html$/;
|
const idRegexPattern = /\/(\d+)-[^/]+\.html$/;
|
||||||
|
|
||||||
@@ -23,11 +22,7 @@ async function searchAndFindMediaId(ctx: ShowScrapeContext | MovieScrapeContext)
|
|||||||
query: { q: ctx.media.title },
|
query: { q: ctx.media.title },
|
||||||
});
|
});
|
||||||
|
|
||||||
const movieData: {
|
const movieData: MovieData[] = [];
|
||||||
id: string | null;
|
|
||||||
year: number | null;
|
|
||||||
type: ScrapeMedia['type'];
|
|
||||||
}[] = [];
|
|
||||||
|
|
||||||
for (const match of searchData.matchAll(itemRegexPattern)) {
|
for (const match of searchData.matchAll(itemRegexPattern)) {
|
||||||
const url = match[1];
|
const url = match[1];
|
||||||
@@ -37,20 +32,23 @@ async function searchAndFindMediaId(ctx: ShowScrapeContext | MovieScrapeContext)
|
|||||||
if (result !== null) {
|
if (result !== null) {
|
||||||
const id = url.match(idRegexPattern)?.[1] || null;
|
const id = url.match(idRegexPattern)?.[1] || null;
|
||||||
|
|
||||||
movieData.push({ id, year: result.year, type: ctx.media.type });
|
movieData.push({ id: id ?? '', year: result.year ?? 0, type: ctx.media.type, url });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredItems = movieData.filter((item) => item.type === ctx.media.type && item.year === ctx.media.releaseYear);
|
const filteredItems = movieData.filter((item) => item.type === ctx.media.type && item.year === ctx.media.releaseYear);
|
||||||
|
|
||||||
return filteredItems[0]?.id || null;
|
return filteredItems[0] || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getStream(id: string, ctx: ShowScrapeContext | MovieScrapeContext): Promise<VideoLinks> {
|
async function getStream(
|
||||||
|
id: string,
|
||||||
|
translatorId: string,
|
||||||
|
ctx: ShowScrapeContext | MovieScrapeContext,
|
||||||
|
): Promise<VideoLinks> {
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
searchParams.append('id', id);
|
searchParams.append('id', id);
|
||||||
// Translator ID 238 represents the Original + subtitles player.
|
searchParams.append('translator_id', translatorId);
|
||||||
searchParams.append('translator_id', '238');
|
|
||||||
if (ctx.media.type === 'show') {
|
if (ctx.media.type === 'show') {
|
||||||
searchParams.append('season', ctx.media.season.number.toString());
|
searchParams.append('season', ctx.media.season.number.toString());
|
||||||
searchParams.append('episode', ctx.media.episode.number.toString());
|
searchParams.append('episode', ctx.media.episode.number.toString());
|
||||||
@@ -74,11 +72,34 @@ async function getStream(id: string, ctx: ShowScrapeContext | MovieScrapeContext
|
|||||||
return JSON.parse(response);
|
return JSON.parse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
const universalScraper = async (ctx: ShowScrapeContext | MovieScrapeContext): Promise<SourcererOutput> => {
|
async function getTranslatorId(
|
||||||
const id = await searchAndFindMediaId(ctx);
|
url: string,
|
||||||
if (!id) throw new NotFoundError('No result found');
|
id: string,
|
||||||
|
ctx: ShowScrapeContext | MovieScrapeContext,
|
||||||
|
): Promise<string | null> {
|
||||||
|
const response = await ctx.proxiedFetcher<string>(url, {
|
||||||
|
headers: baseHeaders,
|
||||||
|
});
|
||||||
|
|
||||||
const { url: streamUrl, subtitle: streamSubtitle } = await getStream(id, ctx);
|
// Translator ID 238 represents the Original + subtitles player.
|
||||||
|
if (response.includes(`data-translator_id="238"`)) return '238';
|
||||||
|
|
||||||
|
const functionName = ctx.media.type === 'movie' ? 'initCDNMoviesEvents' : 'initCDNSeriesEvents';
|
||||||
|
const regexPattern = new RegExp(`sof\\.tv\\.${functionName}\\(${id}, ([^,]+)`, 'i');
|
||||||
|
const match = response.match(regexPattern);
|
||||||
|
const translatorId = match ? match[1] : null;
|
||||||
|
|
||||||
|
return translatorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const universalScraper = async (ctx: ShowScrapeContext | MovieScrapeContext): Promise<SourcererOutput> => {
|
||||||
|
const result = await searchAndFindMediaId(ctx);
|
||||||
|
if (!result || !result.id) throw new NotFoundError('No result found');
|
||||||
|
|
||||||
|
const translatorId = await getTranslatorId(result.url, result.id, ctx);
|
||||||
|
if (!translatorId) throw new NotFoundError('No translator id found');
|
||||||
|
|
||||||
|
const { url: streamUrl, subtitle: streamSubtitle } = await getStream(result.id, translatorId, ctx);
|
||||||
const parsedVideos = parseVideoLinks(streamUrl);
|
const parsedVideos = parseVideoLinks(streamUrl);
|
||||||
const parsedSubtitles = parseSubtitleLinks(streamSubtitle);
|
const parsedSubtitles = parseSubtitleLinks(streamSubtitle);
|
||||||
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import { ScrapeMedia } from '@/index';
|
||||||
|
|
||||||
export type VideoLinks = {
|
export type VideoLinks = {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
@@ -9,3 +11,10 @@ export type VideoLinks = {
|
|||||||
subtitle_def: boolean;
|
subtitle_def: boolean;
|
||||||
thumbnails: string;
|
thumbnails: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface MovieData {
|
||||||
|
id: string | null;
|
||||||
|
year: number;
|
||||||
|
type: ScrapeMedia['type'];
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user