mirror of
https://github.com/p-stream/providers.git
synced 2026-01-11 20:10:33 +00:00
update hianime to always search english title
This commit is contained in:
parent
e1ea6a4e99
commit
5827b35272
1 changed files with 19 additions and 5 deletions
|
|
@ -4,6 +4,9 @@ import { SourcererOutput, makeSourcerer } from '@/providers/base';
|
|||
import { ShowScrapeContext } from '@/utils/context';
|
||||
import { NotFoundError } from '@/utils/errors';
|
||||
|
||||
const apiKey = '5b9790d9305dca8713b9a0afad42ea8d'; // plz dont abuse
|
||||
const baseUrl = 'https://hianime.pstream.org/';
|
||||
|
||||
interface HianimeSearchResult {
|
||||
success: boolean;
|
||||
data: {
|
||||
|
|
@ -26,7 +29,7 @@ interface HianimeEpisodeResult {
|
|||
}
|
||||
|
||||
async function searchAnime(title: string): Promise<string> {
|
||||
const response = await fetch(`https://hianime.pstream.org/api/v2/hianime/search?q=${encodeURIComponent(title)}`);
|
||||
const response = await fetch(`${baseUrl}api/v2/hianime/search?q=${encodeURIComponent(title)}`);
|
||||
if (!response.ok) throw new Error('Failed to search anime');
|
||||
const data: HianimeSearchResult = await response.json();
|
||||
|
||||
|
|
@ -41,8 +44,16 @@ async function searchAnime(title: string): Promise<string> {
|
|||
return match?.id ?? data.data.animes[0].id;
|
||||
}
|
||||
|
||||
async function fetchTmdbShowDetails(tmdbShowId: string): Promise<string> {
|
||||
const response = await fetch(`https://api.themoviedb.org/3/tv/${tmdbShowId}?api_key=${apiKey}`);
|
||||
if (!response.ok) throw new NotFoundError('Failed to fetch show data from TMDB');
|
||||
const data = await response.json();
|
||||
|
||||
// Return the English title, falling back to the original title if not available
|
||||
return data.name || data.original_name;
|
||||
}
|
||||
|
||||
async function fetchTmdbSeasonEpisodes(tmdbShowId: string, seasonNumber: number): Promise<any[]> {
|
||||
const apiKey = '5b9790d9305dca8713b9a0afad42ea8d'; // plz dont abuse
|
||||
const response = await fetch(
|
||||
`https://api.themoviedb.org/3/tv/${tmdbShowId}/season/${seasonNumber}?api_key=${apiKey}`,
|
||||
);
|
||||
|
|
@ -66,14 +77,17 @@ async function calculateAbsoluteEpisodeNumber(
|
|||
}
|
||||
|
||||
async function fetchEpisodeData(animeId: string): Promise<HianimeEpisodeResult> {
|
||||
const response = await fetch(`https://hianime.pstream.org/api/v2/hianime/anime/${animeId}/episodes`);
|
||||
const response = await fetch(`${baseUrl}api/v2/hianime/anime/${animeId}/episodes`);
|
||||
if (!response.ok) throw new NotFoundError('Failed to fetch episode data');
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async function comboScraper(ctx: ShowScrapeContext): Promise<SourcererOutput> {
|
||||
const animeId = await searchAnime(ctx.media.title);
|
||||
// console.log(animeId);
|
||||
// Get the English title from TMDB first
|
||||
const englishTitle = await fetchTmdbShowDetails(ctx.media.tmdbId);
|
||||
|
||||
// Use the English title to search for the anime
|
||||
const animeId = await searchAnime(englishTitle);
|
||||
|
||||
const absoluteEp = await calculateAbsoluteEpisodeNumber(
|
||||
ctx.media.tmdbId,
|
||||
|
|
|
|||
Loading…
Reference in a new issue