fixed feedback, added external_ids

This commit is contained in:
Jorrin
2023-12-28 18:39:49 +01:00
parent a208aef364
commit 9b338b6f3b
3 changed files with 25 additions and 12 deletions

View File

@@ -2,7 +2,7 @@ import { getConfig } from '@/dev-cli/config';
import { MovieMedia, ShowMedia } from '..';
export async function makeTMDBRequest(url: string): Promise<Response> {
export async function makeTMDBRequest(url: string, appendToResponse?: string): Promise<Response> {
const headers: {
accept: 'application/json';
authorization?: string;
@@ -10,7 +10,7 @@ export async function makeTMDBRequest(url: string): Promise<Response> {
accept: 'application/json',
};
let requestURL = url;
const requestURL = new URL(url);
const key = getConfig().tmdbApiKey;
// * JWT keys always start with ey and are ONLY valid as a header.
@@ -19,7 +19,11 @@ export async function makeTMDBRequest(url: string): Promise<Response> {
if (key.startsWith('ey')) {
headers.authorization = `Bearer ${key}`;
} else {
requestURL += `?api_key=${key}`;
requestURL.searchParams.append('api_key', key);
}
if (appendToResponse) {
requestURL.searchParams.append('append_to_response', appendToResponse);
}
return fetch(requestURL, {
@@ -29,7 +33,7 @@ export async function makeTMDBRequest(url: string): Promise<Response> {
}
export async function getMovieMediaDetails(id: string): Promise<MovieMedia> {
const response = await makeTMDBRequest(`https://api.themoviedb.org/3/movie/${id}`);
const response = await makeTMDBRequest(`https://api.themoviedb.org/3/movie/${id}`, 'external_ids');
const movie = await response.json();
if (movie.success === false) {
@@ -52,7 +56,7 @@ export async function getMovieMediaDetails(id: string): Promise<MovieMedia> {
export async function getShowMediaDetails(id: string, seasonNumber: string, episodeNumber: string): Promise<ShowMedia> {
// * TV shows require the TMDB ID for the series, season, and episode
// * and the name of the series. Needs multiple requests
let response = await makeTMDBRequest(`https://api.themoviedb.org/3/tv/${id}`);
let response = await makeTMDBRequest(`https://api.themoviedb.org/3/tv/${id}`, 'external_ids');
const series = await response.json();
if (series.success === false) {
@@ -92,6 +96,6 @@ export async function getShowMediaDetails(id: string, seasonNumber: string, epis
number: season.season_number,
tmdbId: season.id,
},
imdbId: series.imdb_id,
imdbId: series.external_ids.imdb_id,
};
}