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

New: LanguageId filter added to all movie endpoint #9948

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/Radarr.Api.V3/Movies/MovieController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,34 @@ public class MovieController : RestControllerWithSignalR<MovieResource, Movie>,
}

[HttpGet]
public List<MovieResource> AllMovie(int? tmdbId, bool excludeLocalCovers = false)
public List<MovieResource> AllMovie(int? tmdbId, bool excludeLocalCovers = false, int? languageId = null)
{
var moviesResources = new List<MovieResource>();

Dictionary<string, FileInfo> coverFileInfos = null;

var translationLanguage = languageId is > 0
? Language.All.Single(l => l.Id == languageId.Value)
: (Language)_configService.MovieInfoLanguage;

if (tmdbId.HasValue)
{
var movie = _moviesService.FindByTmdbId(tmdbId.Value);

if (movie != null)
{
moviesResources.AddIfNotNull(MapToResource(movie));
moviesResources.AddIfNotNull(MapToResource(movie, translationLanguage));
}
}
else
{
var movieStats = _movieStatisticsService.MovieStatistics();
var configLanguage = (Language)_configService.MovieInfoLanguage;
var availDelay = _configService.AvailabilityDelay;

var movieTask = Task.Run(() => _moviesService.GetAllMovies());

var translations = _movieTranslationService
.GetAllTranslationsForLanguage(configLanguage);
.GetAllTranslationsForLanguage(translationLanguage);

var tdict = translations.ToDictionary(x => x.MovieMetadataId);
var sdict = movieStats.ToDictionary(x => x.MovieId);
Expand All @@ -152,7 +155,7 @@ public List<MovieResource> AllMovie(int? tmdbId, bool excludeLocalCovers = false

foreach (var movie in movies)
{
var translation = GetTranslationFromDict(tdict, movie.MovieMetadata, configLanguage);
var translation = GetTranslationFromDict(tdict, movie.MovieMetadata, translationLanguage);
moviesResources.Add(movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
}

Expand All @@ -178,17 +181,18 @@ protected override MovieResource GetResourceById(int id)
return MapToResource(movie);
}

protected MovieResource MapToResource(Movie movie)
protected MovieResource MapToResource(Movie movie, Language translationLanguage = null)
{
if (movie == null)
{
return null;
}

translationLanguage ??= (Language)_configService.MovieInfoLanguage;
var availDelay = _configService.AvailabilityDelay;

var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
var translation = GetMovieTranslation(translations, movie.MovieMetadata, translationLanguage);

var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification);
MapCoversToLocal(resource);
Expand Down