1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-17 15:02:34 +02:00

New: Add TMDB/IMDB url in Kodi metadata

This commit is contained in:
FuNK3Y 2019-11-17 17:14:31 +01:00 committed by Devin Buhl
parent e8b658646a
commit fedf2326f0
2 changed files with 134 additions and 125 deletions

View File

@ -102,158 +102,156 @@ public override MetadataFile FindMetadataFile(Movie movie, string path)
public override MetadataFileResult MovieMetadata(Movie movie, MovieFile movieFile) public override MetadataFileResult MovieMetadata(Movie movie, MovieFile movieFile)
{ {
if (!Settings.MovieMetadata)
{
return null;
}
_logger.Debug("Generating Movie Metadata for: {0}", Path.Combine(movie.Path, movieFile.RelativePath));
var watched = GetExistingWatchedStatus(movie, movieFile.RelativePath);
var xmlResult = string.Empty; var xmlResult = string.Empty;
if (Settings.MovieMetadata)
var sb = new StringBuilder();
var xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = false;
using (var xw = XmlWriter.Create(sb, xws))
{ {
var doc = new XDocument(); _logger.Debug("Generating Movie Metadata for: {0}", Path.Combine(movie.Path, movieFile.RelativePath));
var thumbnail = movie.Images.SingleOrDefault(i => i.CoverType == MediaCoverTypes.Screenshot); var watched = GetExistingWatchedStatus(movie, movieFile.RelativePath);
var posters = movie.Images.Where(i => i.CoverType == MediaCoverTypes.Poster);
var fanarts = movie.Images.Where(i => i.CoverType == MediaCoverTypes.Fanart);
var details = new XElement("movie"); var sb = new StringBuilder();
var xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = false;
details.Add(new XElement("title", movie.Title)); using (var xw = XmlWriter.Create(sb, xws))
if (movie.Ratings != null && movie.Ratings.Votes > 0)
{ {
details.Add(new XElement("rating", movie.Ratings.Value)); var doc = new XDocument();
} var thumbnail = movie.Images.SingleOrDefault(i => i.CoverType == MediaCoverTypes.Screenshot);
var posters = movie.Images.Where(i => i.CoverType == MediaCoverTypes.Poster);
var fanarts = movie.Images.Where(i => i.CoverType == MediaCoverTypes.Fanart);
details.Add(new XElement("plot", movie.Overview)); var details = new XElement("movie");
details.Add(new XElement("id", movie.ImdbId));
if (movie.ImdbId.IsNotNullOrWhiteSpace()) details.Add(new XElement("title", movie.Title));
{
var imdbId = new XElement("uniqueid", movie.ImdbId);
imdbId.SetAttributeValue("type", "imdb");
imdbId.SetAttributeValue("default", true);
details.Add(imdbId);
}
var uniqueId = new XElement("uniqueid", movie.TmdbId); if (movie.Ratings != null && movie.Ratings.Votes > 0)
uniqueId.SetAttributeValue("type", "tmdb");
details.Add(uniqueId);
details.Add(new XElement("year", movie.Year));
if (movie.InCinemas.HasValue)
{
details.Add(new XElement("premiered", movie.InCinemas.Value.ToString("yyyy-MM-dd")));
}
foreach (var genre in movie.Genres)
{
details.Add(new XElement("genre", genre));
}
details.Add(new XElement("studio", movie.Studio));
if (thumbnail == null)
{
details.Add(new XElement("thumb"));
}
else
{
details.Add(new XElement("thumb", thumbnail.Url));
}
foreach (var poster in posters)
{
if (poster != null && poster.Url != null)
{ {
details.Add(new XElement("thumb", new XAttribute("aspect", "poster"), poster.Url)); details.Add(new XElement("rating", movie.Ratings.Value));
} }
}
if (fanarts.Count() > 0) details.Add(new XElement("plot", movie.Overview));
{ details.Add(new XElement("id", movie.ImdbId));
var fanartElement = new XElement("fanart");
foreach (var fanart in fanarts) if (movie.ImdbId.IsNotNullOrWhiteSpace())
{ {
if (fanart != null && fanart.Url != null) var imdbId = new XElement("uniqueid", movie.ImdbId);
imdbId.SetAttributeValue("type", "imdb");
imdbId.SetAttributeValue("default", true);
details.Add(imdbId);
}
var uniqueId = new XElement("uniqueid", movie.TmdbId);
uniqueId.SetAttributeValue("type", "tmdb");
details.Add(uniqueId);
details.Add(new XElement("year", movie.Year));
if (movie.InCinemas.HasValue)
{
details.Add(new XElement("premiered", movie.InCinemas.Value.ToString("yyyy-MM-dd")));
}
foreach (var genre in movie.Genres)
{
details.Add(new XElement("genre", genre));
}
details.Add(new XElement("studio", movie.Studio));
if (thumbnail == null)
{
details.Add(new XElement("thumb"));
}
else
{
details.Add(new XElement("thumb", thumbnail.Url));
}
foreach (var poster in posters)
{
if (poster != null && poster.Url != null)
{ {
fanartElement.Add(new XElement("thumb", fanart.Url)); details.Add(new XElement("thumb", new XAttribute("aspect", "poster"), poster.Url));
} }
} }
details.Add(fanartElement);
}
details.Add(new XElement("watched", watched)); if (fanarts.Count() > 0)
if (movieFile.MediaInfo != null)
{
var sceneName = movieFile.GetSceneOrFileName();
var fileInfo = new XElement("fileinfo");
var streamDetails = new XElement("streamdetails");
var video = new XElement("video");
video.Add(new XElement("aspect", (float)movieFile.MediaInfo.Width / (float)movieFile.MediaInfo.Height));
video.Add(new XElement("bitrate", movieFile.MediaInfo.VideoBitrate));
video.Add(new XElement("codec", MediaInfoFormatter.FormatVideoCodec(movieFile.MediaInfo, sceneName)));
video.Add(new XElement("framerate", movieFile.MediaInfo.VideoFps));
video.Add(new XElement("height", movieFile.MediaInfo.Height));
video.Add(new XElement("scantype", movieFile.MediaInfo.ScanType));
video.Add(new XElement("width", movieFile.MediaInfo.Width));
if (movieFile.MediaInfo.RunTime != null)
{ {
video.Add(new XElement("duration", movieFile.MediaInfo.RunTime.TotalMinutes)); var fanartElement = new XElement("fanart");
video.Add(new XElement("durationinseconds", movieFile.MediaInfo.RunTime.TotalSeconds)); foreach (var fanart in fanarts)
{
if (fanart != null && fanart.Url != null)
{
fanartElement.Add(new XElement("thumb", fanart.Url));
}
}
details.Add(fanartElement);
} }
streamDetails.Add(video); details.Add(new XElement("watched", watched));
var audio = new XElement("audio"); if (movieFile.MediaInfo != null)
audio.Add(new XElement("bitrate", movieFile.MediaInfo.AudioBitrate));
audio.Add(new XElement("channels", movieFile.MediaInfo.AudioChannels));
audio.Add(new XElement("codec", MediaInfoFormatter.FormatAudioCodec(movieFile.MediaInfo, sceneName)));
audio.Add(new XElement("language", movieFile.MediaInfo.AudioLanguages));
streamDetails.Add(audio);
if (movieFile.MediaInfo.Subtitles != null && movieFile.MediaInfo.Subtitles.Length > 0)
{ {
var subtitle = new XElement("subtitle"); var sceneName = movieFile.GetSceneOrFileName();
subtitle.Add(new XElement("language", movieFile.MediaInfo.Subtitles));
streamDetails.Add(subtitle); var fileInfo = new XElement("fileinfo");
var streamDetails = new XElement("streamdetails");
var video = new XElement("video");
video.Add(new XElement("aspect", (float)movieFile.MediaInfo.Width / (float)movieFile.MediaInfo.Height));
video.Add(new XElement("bitrate", movieFile.MediaInfo.VideoBitrate));
video.Add(new XElement("codec", MediaInfoFormatter.FormatVideoCodec(movieFile.MediaInfo, sceneName)));
video.Add(new XElement("framerate", movieFile.MediaInfo.VideoFps));
video.Add(new XElement("height", movieFile.MediaInfo.Height));
video.Add(new XElement("scantype", movieFile.MediaInfo.ScanType));
video.Add(new XElement("width", movieFile.MediaInfo.Width));
if (movieFile.MediaInfo.RunTime != null)
{
video.Add(new XElement("duration", movieFile.MediaInfo.RunTime.TotalMinutes));
video.Add(new XElement("durationinseconds", movieFile.MediaInfo.RunTime.TotalSeconds));
}
streamDetails.Add(video);
var audio = new XElement("audio");
audio.Add(new XElement("bitrate", movieFile.MediaInfo.AudioBitrate));
audio.Add(new XElement("channels", movieFile.MediaInfo.AudioChannels));
audio.Add(new XElement("codec", MediaInfoFormatter.FormatAudioCodec(movieFile.MediaInfo, sceneName)));
audio.Add(new XElement("language", movieFile.MediaInfo.AudioLanguages));
streamDetails.Add(audio);
if (movieFile.MediaInfo.Subtitles != null && movieFile.MediaInfo.Subtitles.Length > 0)
{
var subtitle = new XElement("subtitle");
subtitle.Add(new XElement("language", movieFile.MediaInfo.Subtitles));
streamDetails.Add(subtitle);
}
fileInfo.Add(streamDetails);
details.Add(fileInfo);
} }
fileInfo.Add(streamDetails); doc.Add(details);
details.Add(fileInfo); doc.Save(xw);
xmlResult += doc.ToString();
xmlResult += Environment.NewLine;
} }
}
doc.Add(details); if (Settings.MovieMetadataURL)
doc.Save(xw); {
xmlResult += "https://www.themoviedb.org/movie/" + movie.TmdbId;
xmlResult += doc.ToString();
xmlResult += Environment.NewLine; xmlResult += Environment.NewLine;
xmlResult += "https://www.imdb.com/title/" + movie.ImdbId;
xmlResult += Environment.NewLine;
} }
var metadataFileName = GetMovieMetadataFilename(movieFile.RelativePath); var metadataFileName = GetMovieMetadataFilename(movieFile.RelativePath);
if (Settings.UseMovieNfo) return xmlResult == string.Empty ? null : new MetadataFileResult(metadataFileName, xmlResult.Trim(Environment.NewLine.ToCharArray()));
{
metadataFileName = "movie.nfo";
}
return new MetadataFileResult(metadataFileName, xmlResult.Trim(Environment.NewLine.ToCharArray()));
} }
public override List<ImageFileResult> MovieImages(Movie movie) public override List<ImageFileResult> MovieImages(Movie movie)
@ -279,7 +277,14 @@ private IEnumerable<ImageFileResult> ProcessMovieImages(Movie movie)
private string GetMovieMetadataFilename(string movieFilePath) private string GetMovieMetadataFilename(string movieFilePath)
{ {
return Path.ChangeExtension(movieFilePath, "nfo"); if (Settings.UseMovieNfo)
{
return Path.Combine(Path.GetDirectoryName(movieFilePath), "movie.nfo");
}
else
{
return Path.ChangeExtension(movieFilePath, "nfo");
}
} }
private bool GetExistingWatchedStatus(Movie movie, string movieFilePath) private bool GetExistingWatchedStatus(Movie movie, string movieFilePath)

View File

@ -19,6 +19,7 @@ public class XbmcMetadataSettings : IProviderConfig
public XbmcMetadataSettings() public XbmcMetadataSettings()
{ {
MovieMetadata = true; MovieMetadata = true;
MovieMetadataURL = true;
MovieImages = true; MovieImages = true;
UseMovieNfo = false; UseMovieNfo = false;
} }
@ -26,10 +27,13 @@ public XbmcMetadataSettings()
[FieldDefinition(0, Label = "Movie Metadata", Type = FieldType.Checkbox)] [FieldDefinition(0, Label = "Movie Metadata", Type = FieldType.Checkbox)]
public bool MovieMetadata { get; set; } public bool MovieMetadata { get; set; }
[FieldDefinition(1, Label = "Movie Images", Type = FieldType.Checkbox)] [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)]
public bool MovieImages { get; set; } public bool MovieImages { get; set; }
[FieldDefinition(2, Label = "Use Movie.nfo", Type = FieldType.Checkbox, HelpText = "Radarr will write metadata to movie.nfo instead of the default <movie-filename>.nfo")] [FieldDefinition(3, 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 UseMovieNfo { get; set; }
public bool IsValid => true; public bool IsValid => true;