Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): set tmdb query's default language based on locale setting #667

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions server/api/themoviedb/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ExternalAPI from '@server/api/externalapi';
import cacheManager from '@server/lib/cache';
import { getSettings } from '@server/lib/settings';
import { sortBy } from 'lodash';
import type {
TmdbCollection,
Expand Down Expand Up @@ -98,6 +99,7 @@ interface DiscoverTvOptions {
}

class TheMovieDb extends ExternalAPI {
private locale: string;
private region?: string;
private originalLanguage?: string;
constructor({
Expand All @@ -117,6 +119,7 @@ class TheMovieDb extends ExternalAPI {
},
}
);
this.locale = getSettings().main?.locale || 'en';
this.region = region;
this.originalLanguage = originalLanguage;
}
Expand All @@ -125,7 +128,7 @@ class TheMovieDb extends ExternalAPI {
query,
page = 1,
includeAdult = false,
language = 'en',
language = this.locale,
}: SearchOptions): Promise<TmdbSearchMultiResponse> => {
try {
const data = await this.get<TmdbSearchMultiResponse>('/search/multi', {
Expand All @@ -147,7 +150,7 @@ class TheMovieDb extends ExternalAPI {
query,
page = 1,
includeAdult = false,
language = 'en',
language = this.locale,
year,
}: SingleSearchOptions): Promise<TmdbSearchMovieResponse> => {
try {
Expand Down Expand Up @@ -176,7 +179,7 @@ class TheMovieDb extends ExternalAPI {
query,
page = 1,
includeAdult = false,
language = 'en',
language = this.locale,
year,
}: SingleSearchOptions): Promise<TmdbSearchTvResponse> => {
try {
Expand All @@ -203,7 +206,7 @@ class TheMovieDb extends ExternalAPI {

public getPerson = async ({
personId,
language = 'en',
language = this.locale,
}: {
personId: number;
language?: string;
Expand All @@ -221,7 +224,7 @@ class TheMovieDb extends ExternalAPI {

public getPersonCombinedCredits = async ({
personId,
language = 'en',
language = this.locale,
}: {
personId: number;
language?: string;
Expand All @@ -244,7 +247,7 @@ class TheMovieDb extends ExternalAPI {

public getMovie = async ({
movieId,
language = 'en',
language = this.locale,
}: {
movieId: number;
language?: string;
Expand All @@ -270,7 +273,7 @@ class TheMovieDb extends ExternalAPI {

public getTvShow = async ({
tvId,
language = 'en',
language = this.locale,
}: {
tvId: number;
language?: string;
Expand Down Expand Up @@ -323,7 +326,7 @@ class TheMovieDb extends ExternalAPI {
public async getMovieRecommendations({
movieId,
page = 1,
language = 'en',
language = this.locale,
}: {
movieId: number;
page?: number;
Expand All @@ -349,7 +352,7 @@ class TheMovieDb extends ExternalAPI {
public async getMovieSimilar({
movieId,
page = 1,
language = 'en',
language = this.locale,
}: {
movieId: number;
page?: number;
Expand All @@ -375,7 +378,7 @@ class TheMovieDb extends ExternalAPI {
public async getMoviesByKeyword({
keywordId,
page = 1,
language = 'en',
language = this.locale,
}: {
keywordId: number;
page?: number;
Expand All @@ -401,7 +404,7 @@ class TheMovieDb extends ExternalAPI {
public async getTvRecommendations({
tvId,
page = 1,
language = 'en',
language = this.locale,
}: {
tvId: number;
page?: number;
Expand Down Expand Up @@ -429,7 +432,7 @@ class TheMovieDb extends ExternalAPI {
public async getTvSimilar({
tvId,
page = 1,
language = 'en',
language = this.locale,
}: {
tvId: number;
page?: number;
Expand All @@ -453,7 +456,7 @@ class TheMovieDb extends ExternalAPI {
sortBy = 'popularity.desc',
page = 1,
includeAdult = false,
language = 'en',
language = this.locale,
primaryReleaseDateGte,
primaryReleaseDateLte,
originalLanguage,
Expand Down Expand Up @@ -526,7 +529,7 @@ class TheMovieDb extends ExternalAPI {
public getDiscoverTv = async ({
sortBy = 'popularity.desc',
page = 1,
language = 'en',
language = this.locale,
firstAirDateGte,
firstAirDateLte,
includeEmptyReleaseDate = false,
Expand Down Expand Up @@ -599,7 +602,7 @@ class TheMovieDb extends ExternalAPI {

public getUpcomingMovies = async ({
page = 1,
language = 'en',
language = this.locale,
}: {
page: number;
language: string;
Expand All @@ -626,7 +629,7 @@ class TheMovieDb extends ExternalAPI {
public getAllTrending = async ({
page = 1,
timeWindow = 'day',
language = 'en',
language = this.locale,
}: {
page?: number;
timeWindow?: 'day' | 'week';
Expand Down Expand Up @@ -699,7 +702,7 @@ class TheMovieDb extends ExternalAPI {
public async getByExternalId({
externalId,
type,
language = 'en',
language = this.locale,
}:
| {
externalId: string;
Expand Down Expand Up @@ -730,7 +733,7 @@ class TheMovieDb extends ExternalAPI {

public async getMediaByImdbId({
imdbId,
language = 'en',
language = this.locale,
}: {
imdbId: string;
language?: string;
Expand Down Expand Up @@ -769,7 +772,7 @@ class TheMovieDb extends ExternalAPI {

public async getShowByTvdbId({
tvdbId,
language = 'en',
language = this.locale,
}: {
tvdbId: number;
language?: string;
Expand Down Expand Up @@ -799,7 +802,7 @@ class TheMovieDb extends ExternalAPI {

public async getCollection({
collectionId,
language = 'en',
language = this.locale,
}: {
collectionId: number;
language?: string;
Expand Down Expand Up @@ -875,7 +878,7 @@ class TheMovieDb extends ExternalAPI {
}

public async getMovieGenres({
language = 'en',
language = this.locale,
}: {
language?: string;
} = {}): Promise<TmdbGenre[]> {
Expand Down Expand Up @@ -926,7 +929,7 @@ class TheMovieDb extends ExternalAPI {
}

public async getTvGenres({
language = 'en',
language = this.locale,
}: {
language?: string;
} = {}): Promise<TmdbGenre[]> {
Expand Down
Loading