diff --git a/server/api/indexer.ts b/server/api/indexer.ts index fa944b62..d741e719 100644 --- a/server/api/indexer.ts +++ b/server/api/indexer.ts @@ -20,4 +20,11 @@ export interface TvShowIndexer { seasonNumber: number; language?: string; }): Promise; + getShowByTvdbId({ + tvdbId, + language, + }: { + tvdbId: number; + language?: string; + }): Promise; } diff --git a/server/api/tvdb/index.ts b/server/api/tvdb/index.ts index 8ec39063..aabf945c 100644 --- a/server/api/tvdb/index.ts +++ b/server/api/tvdb/index.ts @@ -66,6 +66,19 @@ class Tvdb extends ExternalAPI implements TvShowIndexer { } } + public async getShowByTvdbId({ + tvdbId, + }: { + tvdbId: number; + language?: string; + }): Promise { + return await this.get( + `/en/${tvdbId}`, + {}, + Tvdb.DEFAULT_CACHE_TTL + ); + } + public async getTvShow({ tvId, language = Tvdb.DEFAULT_LANGUAGE, diff --git a/server/lib/scanners/baseScanner.ts b/server/lib/scanners/baseScanner.ts index b78ea811..5a06c330 100644 --- a/server/lib/scanners/baseScanner.ts +++ b/server/lib/scanners/baseScanner.ts @@ -3,7 +3,7 @@ import { MediaStatus, MediaType } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import Media from '@server/entity/Media'; import Season from '@server/entity/Season'; -import { getSettings } from '@server/lib/settings'; +import { getIndexer, getSettings } from '@server/lib/settings'; import logger from '@server/logger'; import AsyncLock from '@server/utils/asyncLock'; import { randomUUID } from 'crypto'; @@ -62,6 +62,7 @@ class BaseScanner { protected sessionId: string; protected running = false; readonly asyncLock = new AsyncLock(); + readonly tvShowIndexer = getIndexer(); readonly tmdb = new TheMovieDb(); protected constructor( diff --git a/server/lib/scanners/jellyfin/index.ts b/server/lib/scanners/jellyfin/index.ts index bfef4f7e..d535d632 100644 --- a/server/lib/scanners/jellyfin/index.ts +++ b/server/lib/scanners/jellyfin/index.ts @@ -1,3 +1,4 @@ +import type { TvShowIndexer } from '@server/api/indexer'; import type { JellyfinLibraryItem } from '@server/api/jellyfin'; import JellyfinAPI from '@server/api/jellyfin'; import TheMovieDb from '@server/api/themoviedb'; @@ -9,7 +10,7 @@ import Media from '@server/entity/Media'; import Season from '@server/entity/Season'; import { User } from '@server/entity/User'; import type { Library } from '@server/lib/settings'; -import { getSettings } from '@server/lib/settings'; +import { getIndexer, getSettings } from '@server/lib/settings'; import logger from '@server/logger'; import AsyncLock from '@server/utils/asyncLock'; import { getHostname } from '@server/utils/getHostname'; @@ -30,6 +31,7 @@ interface SyncStatus { class JellyfinScanner { private sessionId: string; private tmdb: TheMovieDb; + private tvShowIndexer: TvShowIndexer; private jfClient: JellyfinAPI; private items: JellyfinLibraryItem[] = []; private progress = 0; @@ -43,6 +45,8 @@ class JellyfinScanner { constructor({ isRecentOnly }: { isRecentOnly?: boolean } = {}) { this.tmdb = new TheMovieDb(); + this.tvShowIndexer = getIndexer(); + this.isRecentOnly = isRecentOnly ?? false; } @@ -212,7 +216,7 @@ class JellyfinScanner { if (metadata.ProviderIds.Tmdb) { try { - tvShow = await this.tmdb.getTvShow({ + tvShow = await this.tvShowIndexer.getTvShow({ tvId: Number(metadata.ProviderIds.Tmdb), }); } catch { @@ -223,7 +227,7 @@ class JellyfinScanner { } if (!tvShow && metadata.ProviderIds.Tvdb) { try { - tvShow = await this.tmdb.getShowByTvdbId({ + tvShow = await this.tvShowIndexer.getShowByTvdbId({ tvdbId: Number(metadata.ProviderIds.Tvdb), }); } catch { diff --git a/server/lib/scanners/plex/index.ts b/server/lib/scanners/plex/index.ts index 9dee904a..16cd9522 100644 --- a/server/lib/scanners/plex/index.ts +++ b/server/lib/scanners/plex/index.ts @@ -273,7 +273,9 @@ class PlexScanner await this.processHamaSpecials(metadata, mediaIds.tvdbId); } - const tvShow = await this.tmdb.getTvShow({ tvId: mediaIds.tmdbId }); + const tvShow = await this.tvShowIndexer.getTvShow({ + tvId: mediaIds.tmdbId, + }); const seasons = tvShow.seasons; const processableSeasons: ProcessableSeason[] = []; @@ -429,7 +431,7 @@ class PlexScanner const matchedtvdb = plexitem.guid.match(hamaTvdbRegex); if (matchedtvdb) { - const show = await this.tmdb.getShowByTvdbId({ + const show = await this.tvShowIndexer.getShowByTvdbId({ tvdbId: Number(matchedtvdb[1]), }); @@ -463,7 +465,7 @@ class PlexScanner type: 'tvdb', }); if (extResponse.tv_results[0]) { - tvShow = await this.tmdb.getTvShow({ + tvShow = await this.tvShowIndexer.getTvShow({ tvId: extResponse.tv_results[0].id, }); mediaIds.tvdbId = result.tvdbId; diff --git a/server/lib/scanners/sonarr/index.ts b/server/lib/scanners/sonarr/index.ts index 7a6e95c0..99982dc2 100644 --- a/server/lib/scanners/sonarr/index.ts +++ b/server/lib/scanners/sonarr/index.ts @@ -94,11 +94,11 @@ class SonarrScanner }); if (!media || !media.tmdbId) { - tvShow = await this.tmdb.getShowByTvdbId({ + tvShow = await this.tvShowIndexer.getShowByTvdbId({ tvdbId: sonarrSeries.tvdbId, }); } else { - tvShow = await this.tmdb.getTvShow({ tvId: media.tmdbId }); + tvShow = await this.tvShowIndexer.getTvShow({ tvId: media.tmdbId }); } const tmdbId = tvShow.id;