add nepu provider

This commit is contained in:
lonelil 2024-01-29 20:36:36 +08:00
parent ff29bc3299
commit c423a51b4c
No known key found for this signature in database
3 changed files with 89 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import { ridooScraper } from './embeds/ridoo';
import { smashyStreamDScraper } from './embeds/smashystream/dued';
import { smashyStreamFScraper } from './embeds/smashystream/video1';
import { vidplayScraper } from './embeds/vidplay';
import { nepuScraper } from './sources/nepu';
import { ridooMoviesScraper } from './sources/ridomovies';
import { smashyStreamScraper } from './sources/smashystream';
import { vidSrcToScraper } from './sources/vidsrcto';
@ -41,6 +42,7 @@ export function gatherAllSources(): Array<Sourcerer> {
smashyStreamScraper,
ridooMoviesScraper,
vidSrcToScraper,
nepuScraper,
];
}

View File

@ -0,0 +1,78 @@
import { load } from 'cheerio';
import { flags } from '@/entrypoint/utils/targets';
import { SourcererOutput, makeSourcerer } from '@/providers/base';
import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
import { NotFoundError } from '@/utils/errors';
import { SearchResults } from './types';
const nepuBase = 'https://nepu.to';
const nepuReferer = `${nepuBase}/`;
const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => {
const searchResultRequest = await ctx.proxiedFetcher('/ajax/posts', {
baseUrl: nepuBase,
query: {
q: ctx.media.title,
},
});
// json isn't parsed by searchResultRequest for some reason.
const searchResult = JSON.parse(searchResultRequest) as SearchResults;
const show = searchResult.data[0];
if (!show) throw new NotFoundError('No watchable item found');
let videoUrl = show.url;
if (ctx.media.type === 'show') {
videoUrl = `${show.url}/season/${ctx.media.season.number}/episode/${ctx.media.episode.number}`;
}
const videoPage = await ctx.proxiedFetcher(videoUrl, {
baseUrl: nepuBase,
});
const videoPage$ = load(videoPage);
const embedId = videoPage$('a.btn-service').attr('data-embed');
if (!embedId) throw new NotFoundError('No embed found.');
const playerPage = await ctx.proxiedFetcher('/ajax/embed', {
method: 'POST',
baseUrl: nepuBase,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `id=${embedId}`,
});
const streamUrl = playerPage.match(/"file":"(http[^"]+)"/);
if (!streamUrl) throw new NotFoundError('No stream found.');
return {
embeds: [],
stream: [
{
id: 'primary',
captions: [],
playlist: streamUrl[1],
type: 'hls',
flags: [flags.CORS_ALLOWED],
preferredHeaders: {
Origin: nepuBase,
Referer: nepuReferer,
},
},
],
} as SourcererOutput;
};
export const nepuScraper = makeSourcerer({
id: 'nepu',
name: 'Nepu',
rank: 111,
flags: [flags.CORS_ALLOWED],
scrapeMovie: universalScraper,
scrapeShow: universalScraper,
});

View File

@ -0,0 +1,9 @@
export type SearchResults = {
data: {
id: number;
name: string;
second_name: string;
url: string;
type: 'Movie' | 'Serie';
}[];
};