mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 13:33:25 +00:00
cleanup
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
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, ScrapeContext, 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 { VideoLinks } from './types';
|
||||||
@@ -12,30 +13,20 @@ const baseHeaders = {
|
|||||||
'X-Hdrezka-Android-App-Version': '2.2.0',
|
'X-Hdrezka-Android-App-Version': '2.2.0',
|
||||||
};
|
};
|
||||||
|
|
||||||
async function searchAndFindMediaId({
|
async function searchAndFindMediaId(ctx: ShowScrapeContext | MovieScrapeContext): Promise<string | null> {
|
||||||
type,
|
|
||||||
title,
|
|
||||||
releaseYear,
|
|
||||||
ctx,
|
|
||||||
}: {
|
|
||||||
type: 'show' | 'movie';
|
|
||||||
title: string;
|
|
||||||
releaseYear: number;
|
|
||||||
ctx: ScrapeContext;
|
|
||||||
}): Promise<string | 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$/;
|
||||||
|
|
||||||
const searchData = await ctx.proxiedFetcher<string>(`/engine/ajax/search.php`, {
|
const searchData = await ctx.proxiedFetcher<string>(`/engine/ajax/search.php`, {
|
||||||
baseUrl: rezkaBase,
|
baseUrl: rezkaBase,
|
||||||
headers: baseHeaders,
|
headers: baseHeaders,
|
||||||
query: { q: title },
|
query: { q: ctx.media.title },
|
||||||
});
|
});
|
||||||
|
|
||||||
const movieData: {
|
const movieData: {
|
||||||
id: string | null;
|
id: string | null;
|
||||||
year: number | null;
|
year: number | null;
|
||||||
type: 'show' | 'movie';
|
type: ScrapeMedia['type'];
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
for (const match of searchData.matchAll(itemRegexPattern)) {
|
for (const match of searchData.matchAll(itemRegexPattern)) {
|
||||||
@@ -46,11 +37,11 @@ async function searchAndFindMediaId({
|
|||||||
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 });
|
movieData.push({ id, year: result.year, type: ctx.media.type });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredItems = movieData.filter((item) => item.type === type && item.year === releaseYear);
|
const filteredItems = movieData.filter((item) => item.type === ctx.media.type && item.year === ctx.media.releaseYear);
|
||||||
|
|
||||||
return filteredItems[0]?.id || null;
|
return filteredItems[0]?.id || null;
|
||||||
}
|
}
|
||||||
@@ -84,12 +75,7 @@ async function getStream(id: string, ctx: ShowScrapeContext | MovieScrapeContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
const universalScraper = async (ctx: ShowScrapeContext | MovieScrapeContext): Promise<SourcererOutput> => {
|
const universalScraper = async (ctx: ShowScrapeContext | MovieScrapeContext): Promise<SourcererOutput> => {
|
||||||
const id = await searchAndFindMediaId({
|
const id = await searchAndFindMediaId(ctx);
|
||||||
type: ctx.media.type === 'show' ? 'show' : 'movie',
|
|
||||||
title: ctx.media.title,
|
|
||||||
releaseYear: ctx.media.releaseYear,
|
|
||||||
ctx,
|
|
||||||
});
|
|
||||||
if (!id) throw new NotFoundError('No result found');
|
if (!id) throw new NotFoundError('No result found');
|
||||||
|
|
||||||
const { url: streamUrl, subtitle: streamSubtitle } = await getStream(id, ctx);
|
const { url: streamUrl, subtitle: streamSubtitle } = await getStream(id, ctx);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Qualities } from '../../lib';
|
import { Qualities } from '@/providers/streams';
|
||||||
|
|
||||||
export function getValidQualityFromString(quality: string): Qualities {
|
export function getValidQualityFromString(quality: string): Qualities {
|
||||||
switch (quality.toLowerCase().replace('p', '')) {
|
switch (quality.toLowerCase().replace('p', '')) {
|
||||||
|
Reference in New Issue
Block a user