mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 13:03:25 +00:00
add searchResult filtering
This commit is contained in:
@@ -6,6 +6,7 @@ import { MovieScrapeContext, ShowScrapeContext } from '@/utils/context';
|
|||||||
import { NotFoundError } from '@/utils/errors';
|
import { NotFoundError } from '@/utils/errors';
|
||||||
|
|
||||||
import { SearchResults } from './types';
|
import { SearchResults } from './types';
|
||||||
|
import { compareTitle } from '@/utils/compare';
|
||||||
|
|
||||||
const nepuBase = 'https://nepu.to';
|
const nepuBase = 'https://nepu.to';
|
||||||
const nepuReferer = `${nepuBase}/`;
|
const nepuReferer = `${nepuBase}/`;
|
||||||
@@ -17,10 +18,18 @@ const universalScraper = async (ctx: MovieScrapeContext | ShowScrapeContext) =>
|
|||||||
q: ctx.media.title,
|
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 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');
|
if (!show) throw new NotFoundError('No watchable item found');
|
||||||
|
|
||||||
let videoUrl = show.url;
|
let videoUrl = show.url;
|
||||||
|
@@ -2,7 +2,6 @@ export type SearchResults = {
|
|||||||
data: {
|
data: {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
second_name: string;
|
|
||||||
url: string;
|
url: string;
|
||||||
type: 'Movie' | 'Serie';
|
type: 'Movie' | 'Serie';
|
||||||
}[];
|
}[];
|
||||||
|
Reference in New Issue
Block a user