mirror of
https://github.com/Radarr/Radarr
synced 2025-02-22 14:21:14 +00:00
Fixed: Movie titles using default language after using movie editor
This commit is contained in:
parent
4c8e9f204e
commit
a91a9f7fd9
1 changed files with 52 additions and 2 deletions
|
@ -2,10 +2,13 @@
|
|||
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 @@ public IActionResult SaveAll([FromBody] MovieEditorResource resource)
|
|||
});
|
||||
}
|
||||
|
||||
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<MovieResource>(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 @@ public object DeleteMovies([FromBody] MovieEditorResource resource)
|
|||
|
||||
return new { };
|
||||
}
|
||||
|
||||
private MovieTranslation GetTranslationFromDict(Dictionary<int, MovieTranslation> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue