From c423a51b4cb489b1408a2344a85d298c862e84eb Mon Sep 17 00:00:00 2001 From: lonelil <51315646+lonelil@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:36:36 +0800 Subject: [PATCH 1/7] add nepu provider --- src/providers/all.ts | 2 + src/providers/sources/nepu/index.ts | 78 +++++++++++++++++++++++++++++ src/providers/sources/nepu/types.ts | 9 ++++ 3 files changed, 89 insertions(+) create mode 100644 src/providers/sources/nepu/index.ts create mode 100644 src/providers/sources/nepu/types.ts diff --git a/src/providers/all.ts b/src/providers/all.ts index 13e9039..edbe50b 100644 --- a/src/providers/all.ts +++ b/src/providers/all.ts @@ -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 { smashyStreamScraper, ridooMoviesScraper, vidSrcToScraper, + nepuScraper, ]; } diff --git a/src/providers/sources/nepu/index.ts b/src/providers/sources/nepu/index.ts new file mode 100644 index 0000000..d6e1505 --- /dev/null +++ b/src/providers/sources/nepu/index.ts @@ -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, +}); diff --git a/src/providers/sources/nepu/types.ts b/src/providers/sources/nepu/types.ts new file mode 100644 index 0000000..7c8275b --- /dev/null +++ b/src/providers/sources/nepu/types.ts @@ -0,0 +1,9 @@ +export type SearchResults = { + data: { + id: number; + name: string; + second_name: string; + url: string; + type: 'Movie' | 'Serie'; + }[]; +}; From 43faeec1e7e7bee10391a589043e60a09e0eed18 Mon Sep 17 00:00:00 2001 From: lonelil <51315646+lonelil@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:58:46 +0800 Subject: [PATCH 2/7] add searchResult filtering --- src/providers/sources/nepu/index.ts | 13 +++++++++++-- src/providers/sources/nepu/types.ts | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/providers/sources/nepu/index.ts b/src/providers/sources/nepu/index.ts index d6e1505..f5fcd83 100644 --- a/src/providers/sources/nepu/index.ts +++ b/src/providers/sources/nepu/index.ts @@ -6,6 +6,7 @@ import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; import { SearchResults } from './types'; +import { compareTitle } from '@/utils/compare'; const nepuBase = 'https://nepu.to'; const nepuReferer = `${nepuBase}/`; @@ -17,10 +18,18 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => q: ctx.media.title, }, }); - // json isn't parsed by searchResultRequest for some reason. + + // json isn't parsed by proxiedFetcher due to content-type being text/html. const searchResult = JSON.parse(searchResultRequest) as SearchResults; - const show = searchResult.data[0]; + const show = searchResult.data.find((item) => { + if (!item) return false; + if (ctx.media.type === 'movie' && item.type !== "Movie") return false; + if (ctx.media.type === "show" && item.type !== "Serie") return false + + return compareTitle(ctx.media.title, item.name); + }); + if (!show) throw new NotFoundError('No watchable item found'); let videoUrl = show.url; diff --git a/src/providers/sources/nepu/types.ts b/src/providers/sources/nepu/types.ts index 7c8275b..200995a 100644 --- a/src/providers/sources/nepu/types.ts +++ b/src/providers/sources/nepu/types.ts @@ -2,7 +2,6 @@ export type SearchResults = { data: { id: number; name: string; - second_name: string; url: string; type: 'Movie' | 'Serie'; }[]; From bd1e3234d1a5bc322c6bb3bc50ccaf255ad450da Mon Sep 17 00:00:00 2001 From: lonelil <51315646+lonelil@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:54:47 +0800 Subject: [PATCH 3/7] fix linting issues --- src/providers/sources/nepu/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/providers/sources/nepu/index.ts b/src/providers/sources/nepu/index.ts index f5fcd83..5a69615 100644 --- a/src/providers/sources/nepu/index.ts +++ b/src/providers/sources/nepu/index.ts @@ -2,11 +2,11 @@ import { load } from 'cheerio'; import { flags } from '@/entrypoint/utils/targets'; import { SourcererOutput, makeSourcerer } from '@/providers/base'; +import { compareTitle } from '@/utils/compare'; import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context'; import { NotFoundError } from '@/utils/errors'; import { SearchResults } from './types'; -import { compareTitle } from '@/utils/compare'; const nepuBase = 'https://nepu.to'; const nepuReferer = `${nepuBase}/`; @@ -24,8 +24,8 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => const show = searchResult.data.find((item) => { if (!item) return false; - if (ctx.media.type === 'movie' && item.type !== "Movie") return false; - if (ctx.media.type === "show" && item.type !== "Serie") return false + if (ctx.media.type === 'movie' && item.type !== 'Movie') return false; + if (ctx.media.type === 'show' && item.type !== 'Serie') return false; return compareTitle(ctx.media.title, item.name); }); From a30881cf5d2ecd03109b6711bd3af2a1814da987 Mon Sep 17 00:00:00 2001 From: lonelil <51315646+lonelil@users.noreply.github.com> Date: Tue, 30 Jan 2024 07:31:43 +0800 Subject: [PATCH 4/7] Add requested changes --- src/providers/sources/nepu/index.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/providers/sources/nepu/index.ts b/src/providers/sources/nepu/index.ts index 5a69615..38128d9 100644 --- a/src/providers/sources/nepu/index.ts +++ b/src/providers/sources/nepu/index.ts @@ -9,10 +9,9 @@ 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', { + const searchResultRequest = await ctx.proxiedFetcher('/ajax/posts', { baseUrl: nepuBase, query: { q: ctx.media.title, @@ -38,7 +37,7 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => videoUrl = `${show.url}/season/${ctx.media.season.number}/episode/${ctx.media.episode.number}`; } - const videoPage = await ctx.proxiedFetcher(videoUrl, { + const videoPage = await ctx.proxiedFetcher(videoUrl, { baseUrl: nepuBase, }); const videoPage$ = load(videoPage); @@ -46,13 +45,10 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => if (!embedId) throw new NotFoundError('No embed found.'); - const playerPage = await ctx.proxiedFetcher('/ajax/embed', { + const playerPage = await ctx.proxiedFetcher('/ajax/embed', { method: 'POST', baseUrl: nepuBase, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - body: `id=${embedId}`, + body: new URLSearchParams({ id: embedId }), }); const streamUrl = playerPage.match(/"file":"(http[^"]+)"/); @@ -68,10 +64,6 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => playlist: streamUrl[1], type: 'hls', flags: [flags.CORS_ALLOWED], - preferredHeaders: { - Origin: nepuBase, - Referer: nepuReferer, - }, }, ], } as SourcererOutput; From fc052a9f08ec4eddc3ad487c9fc6920d3c9a4c6b Mon Sep 17 00:00:00 2001 From: lonelil <51315646+lonelil@users.noreply.github.com> Date: Wed, 31 Jan 2024 03:38:30 +0800 Subject: [PATCH 5/7] re-add headers --- src/providers/sources/nepu/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/providers/sources/nepu/index.ts b/src/providers/sources/nepu/index.ts index 38128d9..1b31429 100644 --- a/src/providers/sources/nepu/index.ts +++ b/src/providers/sources/nepu/index.ts @@ -1,6 +1,5 @@ import { load } from 'cheerio'; -import { flags } from '@/entrypoint/utils/targets'; import { SourcererOutput, makeSourcerer } from '@/providers/base'; import { compareTitle } from '@/utils/compare'; import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context'; @@ -9,6 +8,7 @@ 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', { @@ -63,7 +63,11 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => captions: [], playlist: streamUrl[1], type: 'hls', - flags: [flags.CORS_ALLOWED], + flags: [], + headers: { + Origin: nepuBase, + Referer: nepuReferer, + }, }, ], } as SourcererOutput; @@ -73,7 +77,7 @@ export const nepuScraper = makeSourcerer({ id: 'nepu', name: 'Nepu', rank: 111, - flags: [flags.CORS_ALLOWED], + flags: [], scrapeMovie: universalScraper, scrapeShow: universalScraper, }); From cb44f663cad8188d235cddb89af07df4458f48de Mon Sep 17 00:00:00 2001 From: lonelil <51315646+lonelil@users.noreply.github.com> Date: Wed, 31 Jan 2024 23:39:44 +0800 Subject: [PATCH 6/7] Change embed selector --- src/providers/sources/nepu/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/sources/nepu/index.ts b/src/providers/sources/nepu/index.ts index 1b31429..576c789 100644 --- a/src/providers/sources/nepu/index.ts +++ b/src/providers/sources/nepu/index.ts @@ -41,7 +41,7 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) => baseUrl: nepuBase, }); const videoPage$ = load(videoPage); - const embedId = videoPage$('a.btn-service').attr('data-embed'); + const embedId = videoPage$('a[data-embed]').attr('data-embed'); if (!embedId) throw new NotFoundError('No embed found.'); From 96a455c4c260da33b97d03e866c077d693ab2cae Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 31 Jan 2024 16:50:49 +0100 Subject: [PATCH 7/7] fix linting --- src/providers/all.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/all.ts b/src/providers/all.ts index 4f3defd..9a17e46 100644 --- a/src/providers/all.ts +++ b/src/providers/all.ts @@ -24,9 +24,9 @@ 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 { wootlyScraper } from './embeds/wootly'; import { goojaraScraper } from './sources/goojara'; +import { nepuScraper } from './sources/nepu'; import { ridooMoviesScraper } from './sources/ridomovies'; import { smashyStreamScraper } from './sources/smashystream'; import { vidSrcToScraper } from './sources/vidsrcto';