Skip to content

Commit

Permalink
fix: fall back to English genre names (#1352)
Browse files Browse the repository at this point in the history
* fix: fall back to English genre names

* fix: use startsWith() instead of equality check
  • Loading branch information
TheCatLady committed Apr 6, 2021
1 parent b4450a3 commit e43106a
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions server/api/themoviedb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,34 @@ class TheMovieDb extends ExternalAPI {
86400 // 24 hours
);

const movieGenres = sortBy(data.genres, 'name');
if (
!language.startsWith('en') &&
data.genres.some((genre) => !genre.name)
) {
const englishData = await this.get<TmdbGenresResult>(
'/genre/movie/list',
{
params: {
language: 'en',
},
},
86400 // 24 hours
);

data.genres
.filter((genre) => !genre.name)
.forEach((genre) => {
genre.name =
englishData.genres.find(
(englishGenre) => englishGenre.id === genre.id
)?.name ?? '';
});
}

const movieGenres = sortBy(
data.genres.filter((genre) => genre.name),
'name'
);

return movieGenres;
} catch (e) {
Expand All @@ -739,7 +766,34 @@ class TheMovieDb extends ExternalAPI {
86400 // 24 hours
);

const tvGenres = sortBy(data.genres, 'name');
if (
!language.startsWith('en') &&
data.genres.some((genre) => !genre.name)
) {
const englishData = await this.get<TmdbGenresResult>(
'/genre/tv/list',
{
params: {
language: 'en',
},
},
86400 // 24 hours
);

data.genres
.filter((genre) => !genre.name)
.forEach((genre) => {
genre.name =
englishData.genres.find(
(englishGenre) => englishGenre.id === genre.id
)?.name ?? '';
});
}

const tvGenres = sortBy(
data.genres.filter((genre) => genre.name),
'name'
);

return tvGenres;
} catch (e) {
Expand Down

0 comments on commit e43106a

Please sign in to comment.