mirror of
https://github.com/sussy-code/providers.git
synced 2026-04-14 05:30:19 +00:00
add searchResult filtering
This commit is contained in:
parent
c423a51b4c
commit
43faeec1e7
2 changed files with 11 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ export type SearchResults = {
|
|||
data: {
|
||||
id: number;
|
||||
name: string;
|
||||
second_name: string;
|
||||
url: string;
|
||||
type: 'Movie' | 'Serie';
|
||||
}[];
|
||||
|
|
|
|||
Loading…
Reference in a new issue