Add catflix source

This commit is contained in:
TPN 2024-06-16 14:01:05 +05:30
parent 6054a2d187
commit 26d32b5531
No known key found for this signature in database
GPG Key ID: 40AE091637892B91
2 changed files with 68 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import { upstreamScraper } from '@/providers/embeds/upstream';
import { vidsrcembedScraper } from '@/providers/embeds/vidsrc'; import { vidsrcembedScraper } from '@/providers/embeds/vidsrc';
import { vTubeScraper } from '@/providers/embeds/vtube'; import { vTubeScraper } from '@/providers/embeds/vtube';
import { autoembedScraper } from '@/providers/sources/autoembed'; import { autoembedScraper } from '@/providers/sources/autoembed';
import { catflixScraper } from '@/providers/sources/catflix';
import { flixhqScraper } from '@/providers/sources/flixhq/index'; import { flixhqScraper } from '@/providers/sources/flixhq/index';
import { goMoviesScraper } from '@/providers/sources/gomovies/index'; import { goMoviesScraper } from '@/providers/sources/gomovies/index';
import { insertunitScraper } from '@/providers/sources/insertunit'; import { insertunitScraper } from '@/providers/sources/insertunit';
@ -65,6 +66,7 @@ import { warezcdnScraper } from './sources/warezcdn';
export function gatherAllSources(): Array<Sourcerer> { export function gatherAllSources(): Array<Sourcerer> {
// all sources are gathered here // all sources are gathered here
return [ return [
catflixScraper,
flixhqScraper, flixhqScraper,
remotestreamScraper, remotestreamScraper,
kissAsianScraper, kissAsianScraper,

View File

@ -0,0 +1,66 @@
import { load } from 'cheerio';
import { SourcererOutput, makeSourcerer } from '@/providers/base';
import { compareMedia } from '@/utils/compare';
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
import { NotFoundError } from '@/utils/errors';
const baseUrl = 'https://catflix.su';
async function comboScraper(ctx: ShowScrapeContext | MovieScrapeContext): Promise<SourcererOutput> {
const searchPage = await ctx.proxiedFetcher('/', {
baseUrl,
query: {
s: ctx.media.title,
},
});
const $search = load(searchPage);
const searchResults: { title: string; year?: number | undefined; url: string }[] = [];
$search('li').each((_, element) => {
const title = $search(element).find('h2').first().text().trim();
// the year is always present, but I sitll decided to make it nullable since the impl isn't as future-proof
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');
if (ctx.media.type === 'show') {
const match = watchPageUrl.match(/\/series\/([^/]+)\/?/);
if (!match) throw new Error('Failed to parse watch page url');
watchPageUrl = watchPageUrl.replace(
`/series/${match[1]}`,
`/episode/${match[1]}-${ctx.media.season.number}x${ctx.media.episode.number}`,
);
}
const watchPage = load(await ctx.proxiedFetcher(watchPageUrl));
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');
return {
embeds: [
{
embedId: 'turbovid',
url,
},
],
};
}
export const catflixScraper = makeSourcerer({
id: 'catflix',
name: 'Catflix',
rank: 122,
flags: [],
scrapeMovie: comboScraper,
scrapeShow: comboScraper,
});