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] 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'; }[];