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

114 lines
3.5 KiB

using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System.Collections.Generic;
11 years ago
using System.Globalization;
using System.IO;
11 years ago
using System.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
11 years ago
public class MovieNfoSaver : BaseNfoSaver
{
public MovieNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
11 years ago
public override string GetSavePath(IHasMetadata item)
{
return GetMovieSavePath(item, FileSystem);
}
public static string GetMovieSavePath(IHasMetadata item, IFileSystem fileSystem)
{
var video = (Video)item;
if (video.VideoType == VideoType.Dvd || video.VideoType == VideoType.BluRay || video.VideoType == VideoType.HdDvd)
{
var path = item.ContainingFolderPath;
return Path.Combine(path, fileSystem.GetFileNameWithoutExtension(path) + ".nfo");
}
return Path.ChangeExtension(item.Path, ".nfo");
}
11 years ago
protected override string GetRootElementName(IHasMetadata item)
{
11 years ago
return item is MusicVideo ? "musicvideo" : "movie";
}
11 years ago
public override bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
{
if (!item.SupportsLocalMetadata)
{
return false;
}
11 years ago
var video = item as Video;
11 years ago
// Check parent for null to avoid running this against things like video backdrops
if (video != null && !(item is Episode) && !video.IsOwnedItem)
{
return updateType >= ItemUpdateType.ImageUpdate;
11 years ago
}
11 years ago
return false;
}
11 years ago
protected override void WriteCustomElements(IHasMetadata item, XmlWriter writer)
{
var imdb = item.GetProviderId(MetadataProviders.Imdb);
if (!string.IsNullOrEmpty(imdb))
{
11 years ago
writer.WriteElementString("id", imdb);
}
var musicVideo = item as MusicVideo;
if (musicVideo != null)
{
if (!string.IsNullOrEmpty(musicVideo.Artist))
{
11 years ago
writer.WriteElementString("artist", musicVideo.Artist);
}
if (!string.IsNullOrEmpty(musicVideo.Album))
{
11 years ago
writer.WriteElementString("album", musicVideo.Album);
}
}
var movie = item as Movie;
if (movie != null)
{
if (!string.IsNullOrEmpty(movie.TmdbCollectionName))
{
11 years ago
writer.WriteElementString("set", movie.TmdbCollectionName);
}
}
11 years ago
}
11 years ago
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
11 years ago
protected override List<string> GetTagsUsed()
{
var list = new List<string>
{
"album",
"artist",
"set",
"id"
11 years ago
};
11 years ago
return list;
}
}
}