mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
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
This commit is contained in:
parent
1ebb71db59
commit
82eadcffaa
@ -10,11 +10,13 @@
|
||||
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 @@ public class XbmcMetadata : MetadataBase<XbmcMetadataSettings>
|
||||
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 @@ public XbmcMetadata(IDetectXbmcNfo detectNfo,
|
||||
_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 @@ public override MetadataFileResult MovieMetadata(Movie movie, MovieFile movieFil
|
||||
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 @@ public override MetadataFileResult MovieMetadata(Movie movie, MovieFile movieFil
|
||||
|
||||
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 @@ public XbmcMetadataSettings()
|
||||
{
|
||||
MovieMetadata = true;
|
||||
MovieMetadataURL = false;
|
||||
MovieMetadataLanguage = (int)Language.English;
|
||||
MovieImages = true;
|
||||
UseMovieNfo = false;
|
||||
}
|
||||
@ -30,10 +32,13 @@ public XbmcMetadataSettings()
|
||||
[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;
|
||||
|
17
src/NzbDrone.Core/Languages/RealLanguageFieldConverter.cs
Normal file
17
src/NzbDrone.Core/Languages/RealLanguageFieldConverter.cs
Normal file
@ -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…
Reference in New Issue
Block a user