Skip to content

Commit

Permalink
fix(scanner): add tvdb indexer for scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
TOomaAh committed Jan 8, 2025
1 parent 1cfb768 commit 8c2b82c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
7 changes: 7 additions & 0 deletions server/api/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ export interface TvShowIndexer {
seasonNumber: number;
language?: string;
}): Promise<TmdbSeasonWithEpisodes>;
getShowByTvdbId({
tvdbId,
language,
}: {
tvdbId: number;
language?: string;
}): Promise<TmdbTvDetails>;
}
13 changes: 13 additions & 0 deletions server/api/tvdb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion server/lib/scanners/baseScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 7 additions & 3 deletions server/lib/scanners/jellyfin/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -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;
Expand All @@ -43,6 +45,8 @@ class JellyfinScanner {

constructor({ isRecentOnly }: { isRecentOnly?: boolean } = {}) {
this.tmdb = new TheMovieDb();
this.tvShowIndexer = getIndexer();

this.isRecentOnly = isRecentOnly ?? false;
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions server/lib/scanners/plex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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]),
});

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions server/lib/scanners/sonarr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8c2b82c

Please sign in to comment.