mirror of
https://github.com/Radarr/Radarr.git
synced 2024-10-05 15:47:20 +02:00
Fixed: Movie titles using default language after using movie editor
This commit is contained in:
parent
4c8e9f204e
commit
a91a9f7fd9
@ -2,10 +2,13 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||||
|
using NzbDrone.Core.Languages;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
using NzbDrone.Core.Movies;
|
using NzbDrone.Core.Movies;
|
||||||
using NzbDrone.Core.Movies.Commands;
|
using NzbDrone.Core.Movies.Commands;
|
||||||
|
using NzbDrone.Core.Movies.Translations;
|
||||||
using Radarr.Http;
|
using Radarr.Http;
|
||||||
|
|
||||||
namespace Radarr.Api.V3.Movies
|
namespace Radarr.Api.V3.Movies
|
||||||
@ -14,12 +17,20 @@ namespace Radarr.Api.V3.Movies
|
|||||||
public class MovieEditorController : Controller
|
public class MovieEditorController : Controller
|
||||||
{
|
{
|
||||||
private readonly IMovieService _movieService;
|
private readonly IMovieService _movieService;
|
||||||
|
private readonly IMovieTranslationService _movieTranslationService;
|
||||||
|
private readonly IConfigService _configService;
|
||||||
private readonly IManageCommandQueue _commandQueueManager;
|
private readonly IManageCommandQueue _commandQueueManager;
|
||||||
private readonly IUpgradableSpecification _upgradableSpecification;
|
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;
|
_movieService = movieService;
|
||||||
|
_movieTranslationService = movieTranslationService;
|
||||||
|
_configService = configService;
|
||||||
_commandQueueManager = commandQueueManager;
|
_commandQueueManager = commandQueueManager;
|
||||||
_upgradableSpecification = upgradableSpecification;
|
_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]
|
[HttpDelete]
|
||||||
@ -96,5 +123,28 @@ public object DeleteMovies([FromBody] MovieEditorResource resource)
|
|||||||
|
|
||||||
return new { };
|
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 New Issue
Block a user