New: Add Option to localize metadata written in .nfo if available (#5060)

* Add Option to localize metadata written in .nfo if available

* Fix Pull Request comments
pull/2/head
Daniel Martin Gonzalez 4 years ago committed by GitHub
parent 1ebb71db59
commit 82eadcffaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,11 +10,13 @@ using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Extras.Metadata.Files;
using NzbDrone.Core.Languages;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Movies.Credits;
using NzbDrone.Core.Movies.Translations;
namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
{
@ -25,11 +27,13 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
private readonly IDetectXbmcNfo _detectNfo;
private readonly IDiskProvider _diskProvider;
private readonly ICreditService _creditService;
private readonly IMovieTranslationService _movieTranslationsService;
public XbmcMetadata(IDetectXbmcNfo detectNfo,
IDiskProvider diskProvider,
IMapCoversToLocal mediaCoverService,
ICreditService creditService,
IMovieTranslationService movieTranslationsService,
Logger logger)
{
_logger = logger;
@ -37,6 +41,7 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
_diskProvider = diskProvider;
_detectNfo = detectNfo;
_creditService = creditService;
_movieTranslationsService = movieTranslationsService;
}
private static readonly Regex MovieImagesRegex = new Regex(@"^(?<type>poster|banner|fanart|clearart|discart|keyart|landscape|logo|backdrop|clearlogo)\.(?:png|jpe?g)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
@ -112,6 +117,15 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
if (Settings.MovieMetadata)
{
_logger.Debug("Generating Movie Metadata for: {0}", Path.Combine(movie.Path, movieFile.RelativePath));
var movieMetadataLanguage = (Settings.MovieMetadataLanguage == (int)Language.Original) ?
(int)movie.OriginalLanguage :
Settings.MovieMetadataLanguage;
var movieTranslations = _movieTranslationsService.GetAllTranslationsForMovie(movie.Id);
var selectedSettingsLanguage = Language.FindById(movieMetadataLanguage);
var movieTranslation = movieTranslations.FirstOrDefault(mt => mt.Language == selectedSettingsLanguage);
var watched = GetExistingWatchedStatus(movie, movieFile.RelativePath);
var sb = new StringBuilder();
@ -128,14 +142,14 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
var details = new XElement("movie");
details.Add(new XElement("title", movie.Title));
details.Add(new XElement("title", movieTranslation?.Title ?? movie.Title));
if (movie.Ratings != null && movie.Ratings.Votes > 0)
{
details.Add(new XElement("rating", movie.Ratings.Value));
}
details.Add(new XElement("plot", movie.Overview));
details.Add(new XElement("plot", movieTranslation?.Overview ?? movie.Overview));
details.Add(new XElement("id", movie.ImdbId));
details.Add(new XElement("tmdbid", movie.TmdbId));

@ -1,5 +1,6 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Languages;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
@ -20,6 +21,7 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
{
MovieMetadata = true;
MovieMetadataURL = false;
MovieMetadataLanguage = (int)Language.English;
MovieImages = true;
UseMovieNfo = false;
}
@ -30,10 +32,13 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
[FieldDefinition(1, Label = "Movie Metadata URL", Type = FieldType.Checkbox, HelpText = "Radarr will write the tmdb/imdb url in the .nfo file", Advanced = true)]
public bool MovieMetadataURL { get; set; }
[FieldDefinition(2, Label = "Movie Images", Type = FieldType.Checkbox)]
[FieldDefinition(2, Label = "Metadata Language", Type = FieldType.Select, SelectOptions = typeof(RealLanguageFieldConverter), HelpText = "Radarr will write metadata in the selected language if available")]
public int MovieMetadataLanguage { get; set; }
[FieldDefinition(3, Label = "Movie Images", Type = FieldType.Checkbox)]
public bool MovieImages { get; set; }
[FieldDefinition(3, Label = "Use Movie.nfo", Type = FieldType.Checkbox, HelpText = "Radarr will write metadata to movie.nfo instead of the default <movie-filename>.nfo")]
[FieldDefinition(4, Label = "Use Movie.nfo", Type = FieldType.Checkbox, HelpText = "Radarr will write metadata to movie.nfo instead of the default <movie-filename>.nfo")]
public bool UseMovieNfo { get; set; }
public bool IsValid => true;

@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Annotations;
namespace NzbDrone.Core.Languages
{
public class RealLanguageFieldConverter : ISelectOptionsConverter
{
public List<SelectOption> GetSelectOptions()
{
return Language.All
.Where(l => l != Language.Unknown && l != Language.Any)
.ToList()
.ConvertAll(v => new SelectOption { Value = v.Id, Name = v.Name });
}
}
}
Loading…
Cancel
Save