From a91a9f7fd9c7ab270b7992ed7e46fd8fb6fcae3b Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 11 Feb 2024 18:36:13 +0200 Subject: [PATCH] Fixed: Movie titles using default language after using movie editor --- .../Movies/MovieEditorController.cs | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Radarr.Api.V3/Movies/MovieEditorController.cs b/src/Radarr.Api.V3/Movies/MovieEditorController.cs index 0d9266b55..623f8aa61 100644 --- a/src/Radarr.Api.V3/Movies/MovieEditorController.cs +++ b/src/Radarr.Api.V3/Movies/MovieEditorController.cs @@ -2,10 +2,13 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; using NzbDrone.Common.Extensions; +using NzbDrone.Core.Configuration; using NzbDrone.Core.DecisionEngine.Specifications; +using NzbDrone.Core.Languages; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Movies; using NzbDrone.Core.Movies.Commands; +using NzbDrone.Core.Movies.Translations; using Radarr.Http; namespace Radarr.Api.V3.Movies @@ -14,12 +17,20 @@ namespace Radarr.Api.V3.Movies public class MovieEditorController : Controller { private readonly IMovieService _movieService; + private readonly IMovieTranslationService _movieTranslationService; + private readonly IConfigService _configService; private readonly IManageCommandQueue _commandQueueManager; private readonly IUpgradableSpecification _upgradableSpecification; - public MovieEditorController(IMovieService movieService, IManageCommandQueue commandQueueManager, IUpgradableSpecification upgradableSpecification) + public MovieEditorController(IMovieService movieService, + IMovieTranslationService movieTranslationService, + IConfigService configService, + IManageCommandQueue commandQueueManager, + IUpgradableSpecification upgradableSpecification) { _movieService = movieService; + _movieTranslationService = movieTranslationService; + _configService = configService; _commandQueueManager = commandQueueManager; _upgradableSpecification = upgradableSpecification; } @@ -86,7 +97,23 @@ namespace Radarr.Api.V3.Movies }); } - return Accepted(_movieService.UpdateMovie(moviesToUpdate, !resource.MoveFiles).ToResource(0, _upgradableSpecification)); + var configLanguage = (Language)_configService.MovieInfoLanguage; + var availabilityDelay = _configService.AvailabilityDelay; + + var translations = _movieTranslationService.GetAllTranslationsForLanguage(configLanguage); + var tdict = translations.ToDictionary(x => x.MovieMetadataId); + + var updatedMovies = _movieService.UpdateMovie(moviesToUpdate, !resource.MoveFiles); + + var moviesResources = new List(updatedMovies.Count); + + foreach (var movie in updatedMovies) + { + var translation = GetTranslationFromDict(tdict, movie.MovieMetadata, configLanguage); + moviesResources.Add(movie.ToResource(availabilityDelay, translation, _upgradableSpecification)); + } + + return Accepted(moviesResources); } [HttpDelete] @@ -96,5 +123,28 @@ namespace Radarr.Api.V3.Movies return new { }; } + + private MovieTranslation GetTranslationFromDict(Dictionary translations, MovieMetadata movie, Language configLanguage) + { + if (configLanguage == Language.Original) + { + return new MovieTranslation + { + Title = movie.OriginalTitle, + Overview = movie.Overview + }; + } + + if (!translations.TryGetValue(movie.Id, out var translation)) + { + translation = new MovieTranslation + { + Title = movie.Title, + Language = Language.English + }; + } + + return translation; + } } }