fix(scanner): add tvdb indexer for scanner

This commit is contained in:
TOomaAh
2025-01-08 18:47:15 +01:00
parent 5f49a978a9
commit 4dcb308955
6 changed files with 36 additions and 9 deletions

View File

@@ -20,4 +20,11 @@ export interface TvShowIndexer {
seasonNumber: number;
language?: string;
}): Promise<TmdbSeasonWithEpisodes>;
getShowByTvdbId({
tvdbId,
language,
}: {
tvdbId: number;
language?: string;
}): Promise<TmdbTvDetails>;
}

View File

@@ -66,6 +66,19 @@ class Tvdb extends ExternalAPI implements TvShowIndexer {
}
}
public async getShowByTvdbId({
tvdbId,
}: {
tvdbId: number;
language?: string;
}): Promise<TmdbTvDetails> {
return await this.get<TmdbTvDetails>(
`/en/${tvdbId}`,
{},
Tvdb.DEFAULT_CACHE_TTL
);
}
public async getTvShow({
tvId,
language = Tvdb.DEFAULT_LANGUAGE,

View File

@@ -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<T> {
protected sessionId: string;
protected running = false;
readonly asyncLock = new AsyncLock();
readonly tvShowIndexer = getIndexer();
readonly tmdb = new TheMovieDb();
protected constructor(

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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;