mirror of
https://github.com/sussy-code/providers.git
synced 2026-04-21 00:22:07 +00:00
revert Catflix changes (keep rank)
This commit is contained in:
parent
546cef05d1
commit
3c3edbbace
1 changed files with 36 additions and 40 deletions
|
|
@ -1,59 +1,56 @@
|
||||||
import { load } from 'cheerio';
|
import { load } from 'cheerio';
|
||||||
|
|
||||||
import { SourcererOutput, makeSourcerer } from '@/providers/base';
|
import { SourcererOutput, makeSourcerer } from '@/providers/base';
|
||||||
|
import { compareMedia } from '@/utils/compare';
|
||||||
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
||||||
|
import { NotFoundError } from '@/utils/errors';
|
||||||
|
|
||||||
const baseUrl = 'https://catflix.su';
|
const baseUrl = 'https://catflix.su';
|
||||||
|
|
||||||
async function comboScraper(ctx: ShowScrapeContext | MovieScrapeContext): Promise<SourcererOutput> {
|
async function comboScraper(ctx: ShowScrapeContext | MovieScrapeContext): Promise<SourcererOutput> {
|
||||||
const movieId = ctx.media.tmdbId;
|
const searchPage = await ctx.proxiedFetcher('/', {
|
||||||
const mediaTitle = ctx.media.title.replace(/ /g, '-').replace(/[():]/g, '').toLowerCase();
|
baseUrl,
|
||||||
let watchPageUrl: string | undefined;
|
query: {
|
||||||
|
s: ctx.media.title,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (ctx.media.type === 'movie') {
|
ctx.progress(40);
|
||||||
watchPageUrl = `${baseUrl}/movie/${mediaTitle}-${movieId}`;
|
|
||||||
} else if (ctx.media.type === 'show') {
|
|
||||||
const seasonNumber = ctx.media.season.number;
|
|
||||||
const episodeNumber = ctx.media.episode.number;
|
|
||||||
const episodeId = ctx.media.episode.tmdbId;
|
|
||||||
|
|
||||||
if (!episodeId) {
|
const $search = load(searchPage);
|
||||||
throw new Error('Missing episode ID for show');
|
const searchResults: { title: string; year?: number | undefined; url: string }[] = [];
|
||||||
}
|
|
||||||
|
|
||||||
watchPageUrl = `${baseUrl}/episode/${mediaTitle}-season-${seasonNumber}-episode-${episodeNumber}/eid-${episodeId}`;
|
$search('li').each((_, element) => {
|
||||||
}
|
const title = $search(element).find('h2').first().text().trim();
|
||||||
if (!watchPageUrl) {
|
// the year is always present, but I sitll decided to make it nullable since the impl isn't as future-proof
|
||||||
throw new Error('Failed to generate watch page URL');
|
const year = Number($search(element).find('.text-xs > span').eq(1).text().trim()) || undefined;
|
||||||
}
|
const url = $search(element).find('a').attr('href');
|
||||||
|
|
||||||
|
if (!title || !url) return;
|
||||||
|
|
||||||
|
searchResults.push({ title, year, url });
|
||||||
|
});
|
||||||
|
|
||||||
|
let watchPageUrl = searchResults.find((x) => x && compareMedia(ctx.media, x.title, x.year))?.url;
|
||||||
|
if (!watchPageUrl) throw new NotFoundError('No watchable item found');
|
||||||
|
|
||||||
ctx.progress(60);
|
ctx.progress(60);
|
||||||
|
|
||||||
const WatchPage = await ctx.proxiedFetcher(watchPageUrl);
|
if (ctx.media.type === 'show') {
|
||||||
const $WatchPage = load(WatchPage);
|
const match = watchPageUrl.match(/\/series\/([^/]+)\/?/);
|
||||||
|
if (!match) throw new Error('Failed to parse watch page url');
|
||||||
const scriptContent = $WatchPage('script')
|
watchPageUrl = watchPageUrl.replace(
|
||||||
.toArray()
|
`/series/${match[1]}`,
|
||||||
.find((script) => {
|
`/episode/${match[1]}-${ctx.media.season.number}x${ctx.media.episode.number}`,
|
||||||
return (
|
);
|
||||||
script.children[0] && script.children[0].type === 'text' && script.children[0].data.includes('main_origin =')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!scriptContent) {
|
|
||||||
throw new Error('Script containing main_origin not found');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mainOriginScript = scriptContent.children[0].type === 'text' ? scriptContent.children[0].data : '';
|
const watchPage = load(await ctx.proxiedFetcher(watchPageUrl));
|
||||||
const mainOriginMatch = mainOriginScript.match(/main_origin = "(.*?)";/);
|
|
||||||
|
|
||||||
if (!mainOriginMatch) {
|
ctx.progress(80);
|
||||||
throw new Error('Unable to extract main_origin value');
|
|
||||||
}
|
|
||||||
|
|
||||||
const Catflix1 = mainOriginMatch[1];
|
const url = watchPage('iframe').first().attr('src'); // I couldn't think of a better way
|
||||||
|
if (!url) throw new Error('Failed to find embed url');
|
||||||
const decodedUrl = atob(Catflix1);
|
|
||||||
|
|
||||||
ctx.progress(90);
|
ctx.progress(90);
|
||||||
|
|
||||||
|
|
@ -61,7 +58,7 @@ async function comboScraper(ctx: ShowScrapeContext | MovieScrapeContext): Promis
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
embedId: 'turbovid',
|
embedId: 'turbovid',
|
||||||
url: decodedUrl,
|
url,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
@ -72,7 +69,6 @@ export const catflixScraper = makeSourcerer({
|
||||||
name: 'Catflix',
|
name: 'Catflix',
|
||||||
rank: 170,
|
rank: 170,
|
||||||
flags: [],
|
flags: [],
|
||||||
disabled: false,
|
|
||||||
scrapeMovie: comboScraper,
|
scrapeMovie: comboScraper,
|
||||||
scrapeShow: comboScraper,
|
scrapeShow: comboScraper,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue