jellyfin/MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs

139 lines
4.6 KiB
C#
Raw Normal View History

2016-03-27 23:11:27 +02:00
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
2015-05-15 17:46:20 +02:00
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.IO;
2014-07-09 02:46:11 +02:00
using System.Xml;
2017-05-26 08:48:54 +02:00
2016-10-25 21:02:04 +02:00
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
2016-10-26 04:53:47 +02:00
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
2014-07-09 02:46:11 +02:00
public class MovieNfoSaver : BaseNfoSaver
{
2018-09-12 19:26:21 +02:00
protected override string GetLocalSavePath(BaseItem item)
{
2017-08-24 21:52:19 +02:00
var paths = GetMovieSavePaths(new ItemInfo(item), FileSystem);
return paths.Count == 0 ? null : paths[0];
}
2015-05-15 17:46:20 +02:00
public static List<string> GetMovieSavePaths(ItemInfo item, IFileSystem fileSystem)
{
2015-05-15 17:46:20 +02:00
var list = new List<string>();
2015-10-08 18:22:14 +02:00
if (item.VideoType == VideoType.Dvd && !item.IsPlaceHolder)
{
var path = item.ContainingFolderPath;
2015-05-21 22:53:14 +02:00
list.Add(Path.Combine(path, "VIDEO_TS", "VIDEO_TS.nfo"));
}
2017-08-07 22:36:41 +02:00
if (!item.IsPlaceHolder && (item.VideoType == VideoType.Dvd || item.VideoType == VideoType.BluRay))
2015-05-15 17:46:20 +02:00
{
var path = item.ContainingFolderPath;
list.Add(Path.Combine(path, Path.GetFileName(path) + ".nfo"));
}
else
{
2016-06-16 04:37:06 +02:00
// http://kodi.wiki/view/NFO_files/Movies
// movie.nfo will override all and any .nfo files in the same folder as the media files if you use the "Use foldernames for lookups" setting. If you don't, then moviename.nfo is used
//if (!item.IsInMixedFolder && item.ItemType == typeof(Movie))
2016-06-15 22:14:04 +02:00
//{
// list.Add(Path.Combine(item.ContainingFolderPath, "movie.nfo"));
//}
2015-05-15 17:46:20 +02:00
list.Add(Path.ChangeExtension(item.Path, ".nfo"));
2017-07-21 21:05:52 +02:00
if (!item.IsInMixedFolder)
{
list.Add(Path.Combine(item.ContainingFolderPath, "movie.nfo"));
}
2015-05-15 17:46:20 +02:00
}
return list;
}
2018-09-12 19:26:21 +02:00
protected override string GetRootElementName(BaseItem item)
{
2014-07-09 02:46:11 +02:00
return item is MusicVideo ? "musicvideo" : "movie";
}
2018-09-12 19:26:21 +02:00
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
2014-07-09 02:46:11 +02:00
{
if (!item.SupportsLocalMetadata)
{
return false;
}
2014-07-09 02:46:11 +02:00
var video = item as Video;
2014-07-09 02:46:11 +02:00
// Check parent for null to avoid running this against things like video backdrops
2018-09-12 19:26:21 +02:00
if (video != null && !(item is Episode) && !video.ExtraType.HasValue)
2014-07-09 02:46:11 +02:00
{
return updateType >= MinimumUpdateType;
2014-07-09 02:46:11 +02:00
}
2014-07-09 02:46:11 +02:00
return false;
}
2018-09-12 19:26:21 +02:00
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
2014-07-09 02:46:11 +02:00
{
var imdb = item.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrEmpty(imdb))
{
2014-07-09 02:46:11 +02:00
writer.WriteElementString("id", imdb);
}
var musicVideo = item as MusicVideo;
if (musicVideo != null)
{
2014-10-20 22:23:40 +02:00
foreach (var artist in musicVideo.Artists)
{
2014-10-20 22:23:40 +02:00
writer.WriteElementString("artist", artist);
}
if (!string.IsNullOrEmpty(musicVideo.Album))
{
2014-07-09 02:46:11 +02:00
writer.WriteElementString("album", musicVideo.Album);
}
}
var movie = item as Movie;
if (movie != null)
{
2016-03-14 02:34:24 +01:00
if (!string.IsNullOrEmpty(movie.CollectionName))
{
2016-03-14 02:34:24 +01:00
writer.WriteElementString("set", movie.CollectionName);
}
}
2014-07-09 02:46:11 +02:00
}
2018-09-12 19:26:21 +02:00
protected override List<string> GetTagsUsed(BaseItem item)
2014-07-09 02:46:11 +02:00
{
var list = base.GetTagsUsed(item);
list.AddRange(new string[]
2014-07-09 02:46:11 +02:00
{
"album",
"artist",
"set",
"id"
});
2014-07-09 02:46:11 +02:00
return list;
}
2016-10-26 04:53:47 +02:00
public MovieNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
}
}