You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs

137 lines
4.5 KiB

using System.Collections.Generic;
using System.IO;
using System.Xml;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Savers
{
10 years ago
public class MovieNfoSaver : BaseNfoSaver
{
protected override string GetLocalSavePath(BaseItem item)
{
var paths = GetMovieSavePaths(new ItemInfo(item), FileSystem);
return paths.Count == 0 ? null : paths[0];
}
public static List<string> GetMovieSavePaths(ItemInfo item, IFileSystem fileSystem)
{
var list = new List<string>();
if (item.VideoType == VideoType.Dvd && !item.IsPlaceHolder)
{
var path = item.ContainingFolderPath;
10 years ago
list.Add(Path.Combine(path, "VIDEO_TS", "VIDEO_TS.nfo"));
}
if (!item.IsPlaceHolder && (item.VideoType == VideoType.Dvd || item.VideoType == VideoType.BluRay))
{
var path = item.ContainingFolderPath;
list.Add(Path.Combine(path, Path.GetFileName(path) + ".nfo"));
}
else
{
// 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))
//{
// list.Add(Path.Combine(item.ContainingFolderPath, "movie.nfo"));
//}
list.Add(Path.ChangeExtension(item.Path, ".nfo"));
if (!item.IsInMixedFolder)
{
list.Add(Path.Combine(item.ContainingFolderPath, "movie.nfo"));
}
}
return list;
}
protected override string GetRootElementName(BaseItem item)
{
10 years ago
return item is MusicVideo ? "musicvideo" : "movie";
}
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
10 years ago
{
if (!item.SupportsLocalMetadata)
{
return false;
}
10 years ago
var video = item as Video;
10 years ago
// Check parent for null to avoid running this against things like video backdrops
if (video != null && !(item is Episode) && !video.ExtraType.HasValue)
10 years ago
{
return updateType >= MinimumUpdateType;
10 years ago
}
10 years ago
return false;
}
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
10 years ago
{
var imdb = item.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrEmpty(imdb))
{
10 years ago
writer.WriteElementString("id", imdb);
}
var musicVideo = item as MusicVideo;
if (musicVideo != null)
{
10 years ago
foreach (var artist in musicVideo.Artists)
{
10 years ago
writer.WriteElementString("artist", artist);
}
if (!string.IsNullOrEmpty(musicVideo.Album))
{
10 years ago
writer.WriteElementString("album", musicVideo.Album);
}
}
var movie = item as Movie;
if (movie != null)
{
if (!string.IsNullOrEmpty(movie.CollectionName))
{
writer.WriteElementString("set", movie.CollectionName);
}
}
10 years ago
}
protected override List<string> GetTagsUsed(BaseItem item)
10 years ago
{
var list = base.GetTagsUsed(item);
list.AddRange(new string[]
10 years ago
{
"album",
"artist",
"set",
"id"
});
10 years ago
return list;
}
public MovieNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
}
}