fix: pass user provided TMDB access token to TMDBMetadata

This commit is contained in:
Viren070
2025-06-13 13:42:31 +01:00
parent 915187a612
commit d2f4dc1b8d
2 changed files with 8 additions and 4 deletions
+3 -1
View File
@@ -1136,7 +1136,9 @@ ${errorStreams.length > 0 ? ` ❌ Errors : ${errorStreams.map((s) => `
let titles: string[] = [];
if (this.userData.titleMatching && TYPES.includes(type as any)) {
try {
titles = await new TMDBMetadata().getTitles(id, type as any);
titles = await new TMDBMetadata(
this.userData.tmdbAccessToken
).getTitles(id, type as any);
logger.info(`Found ${titles.length} titles for ${id}`, { titles });
} catch (error) {
logger.error(`Error fetching titles for ${id}: ${error}`);
+5 -3
View File
@@ -25,18 +25,20 @@ export class TMDBMetadata {
private readonly IMDB_ID_REGEX = /^(?:tt)(\d+)(?::\d+:\d+)?$/;
private readonly idCache: Cache<string, string>;
private readonly titleCache: Cache<string, string[]>;
private readonly accessToken: string;
public constructor() {
if (!Env.TMDB_ACCESS_TOKEN) {
public constructor(accessToken?: string) {
if (!accessToken && !Env.TMDB_ACCESS_TOKEN) {
throw new Error('TMDB Access Token is not set');
}
this.accessToken = (accessToken || Env.TMDB_ACCESS_TOKEN)!;
this.idCache = Cache.getInstance<string, string>('tmdb_id_conversion');
this.titleCache = Cache.getInstance<string, string[]>('alternative_titles');
}
private getHeaders(): Record<string, string> {
return {
Authorization: `Bearer ${Env.TMDB_ACCESS_TOKEN}`,
Authorization: `Bearer ${this.accessToken}`,
};
}