Skip to content

Commit 8c2b82c

Browse files
committed
fix(scanner): add tvdb indexer for scanner
1 parent 1cfb768 commit 8c2b82c

6 files changed

Lines changed: 36 additions & 9 deletions

File tree

server/api/indexer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ export interface TvShowIndexer {
2020
seasonNumber: number;
2121
language?: string;
2222
}): Promise<TmdbSeasonWithEpisodes>;
23+
getShowByTvdbId({
24+
tvdbId,
25+
language,
26+
}: {
27+
tvdbId: number;
28+
language?: string;
29+
}): Promise<TmdbTvDetails>;
2330
}

server/api/tvdb/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ class Tvdb extends ExternalAPI implements TvShowIndexer {
6666
}
6767
}
6868

69+
public async getShowByTvdbId({
70+
tvdbId,
71+
}: {
72+
tvdbId: number;
73+
language?: string;
74+
}): Promise<TmdbTvDetails> {
75+
return await this.get<TmdbTvDetails>(
76+
`/en/${tvdbId}`,
77+
{},
78+
Tvdb.DEFAULT_CACHE_TTL
79+
);
80+
}
81+
6982
public async getTvShow({
7083
tvId,
7184
language = Tvdb.DEFAULT_LANGUAGE,

server/lib/scanners/baseScanner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MediaStatus, MediaType } from '@server/constants/media';
33
import { getRepository } from '@server/datasource';
44
import Media from '@server/entity/Media';
55
import Season from '@server/entity/Season';
6-
import { getSettings } from '@server/lib/settings';
6+
import { getIndexer, getSettings } from '@server/lib/settings';
77
import logger from '@server/logger';
88
import AsyncLock from '@server/utils/asyncLock';
99
import { randomUUID } from 'crypto';
@@ -62,6 +62,7 @@ class BaseScanner<T> {
6262
protected sessionId: string;
6363
protected running = false;
6464
readonly asyncLock = new AsyncLock();
65+
readonly tvShowIndexer = getIndexer();
6566
readonly tmdb = new TheMovieDb();
6667

6768
protected constructor(

server/lib/scanners/jellyfin/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { TvShowIndexer } from '@server/api/indexer';
12
import type { JellyfinLibraryItem } from '@server/api/jellyfin';
23
import JellyfinAPI from '@server/api/jellyfin';
34
import TheMovieDb from '@server/api/themoviedb';
@@ -9,7 +10,7 @@ import Media from '@server/entity/Media';
910
import Season from '@server/entity/Season';
1011
import { User } from '@server/entity/User';
1112
import type { Library } from '@server/lib/settings';
12-
import { getSettings } from '@server/lib/settings';
13+
import { getIndexer, getSettings } from '@server/lib/settings';
1314
import logger from '@server/logger';
1415
import AsyncLock from '@server/utils/asyncLock';
1516
import { getHostname } from '@server/utils/getHostname';
@@ -30,6 +31,7 @@ interface SyncStatus {
3031
class JellyfinScanner {
3132
private sessionId: string;
3233
private tmdb: TheMovieDb;
34+
private tvShowIndexer: TvShowIndexer;
3335
private jfClient: JellyfinAPI;
3436
private items: JellyfinLibraryItem[] = [];
3537
private progress = 0;
@@ -43,6 +45,8 @@ class JellyfinScanner {
4345

4446
constructor({ isRecentOnly }: { isRecentOnly?: boolean } = {}) {
4547
this.tmdb = new TheMovieDb();
48+
this.tvShowIndexer = getIndexer();
49+
4650
this.isRecentOnly = isRecentOnly ?? false;
4751
}
4852

@@ -212,7 +216,7 @@ class JellyfinScanner {
212216

213217
if (metadata.ProviderIds.Tmdb) {
214218
try {
215-
tvShow = await this.tmdb.getTvShow({
219+
tvShow = await this.tvShowIndexer.getTvShow({
216220
tvId: Number(metadata.ProviderIds.Tmdb),
217221
});
218222
} catch {
@@ -223,7 +227,7 @@ class JellyfinScanner {
223227
}
224228
if (!tvShow && metadata.ProviderIds.Tvdb) {
225229
try {
226-
tvShow = await this.tmdb.getShowByTvdbId({
230+
tvShow = await this.tvShowIndexer.getShowByTvdbId({
227231
tvdbId: Number(metadata.ProviderIds.Tvdb),
228232
});
229233
} catch {

server/lib/scanners/plex/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ class PlexScanner
273273
await this.processHamaSpecials(metadata, mediaIds.tvdbId);
274274
}
275275

276-
const tvShow = await this.tmdb.getTvShow({ tvId: mediaIds.tmdbId });
276+
const tvShow = await this.tvShowIndexer.getTvShow({
277+
tvId: mediaIds.tmdbId,
278+
});
277279

278280
const seasons = tvShow.seasons;
279281
const processableSeasons: ProcessableSeason[] = [];
@@ -429,7 +431,7 @@ class PlexScanner
429431
const matchedtvdb = plexitem.guid.match(hamaTvdbRegex);
430432

431433
if (matchedtvdb) {
432-
const show = await this.tmdb.getShowByTvdbId({
434+
const show = await this.tvShowIndexer.getShowByTvdbId({
433435
tvdbId: Number(matchedtvdb[1]),
434436
});
435437

@@ -463,7 +465,7 @@ class PlexScanner
463465
type: 'tvdb',
464466
});
465467
if (extResponse.tv_results[0]) {
466-
tvShow = await this.tmdb.getTvShow({
468+
tvShow = await this.tvShowIndexer.getTvShow({
467469
tvId: extResponse.tv_results[0].id,
468470
});
469471
mediaIds.tvdbId = result.tvdbId;

server/lib/scanners/sonarr/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ class SonarrScanner
9494
});
9595

9696
if (!media || !media.tmdbId) {
97-
tvShow = await this.tmdb.getShowByTvdbId({
97+
tvShow = await this.tvShowIndexer.getShowByTvdbId({
9898
tvdbId: sonarrSeries.tvdbId,
9999
});
100100
} else {
101-
tvShow = await this.tmdb.getTvShow({ tvId: media.tmdbId });
101+
tvShow = await this.tvShowIndexer.getTvShow({ tvId: media.tmdbId });
102102
}
103103

104104
const tmdbId = tvShow.id;

0 commit comments

Comments
 (0)