Skip to content

Commit

Permalink
New: LanguageId filter added to all movie endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
isc30 authored and mynameisbogdan committed May 10, 2024
1 parent 5185e03 commit 886711b
Showing 1 changed file with 11 additions and 7 deletions.
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 @@ -110,31 +110,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 @@ -150,7 +153,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 @@ -176,17 +179,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

0 comments on commit 886711b

Please sign in to comment.