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/EpisodeNfoSaver.cs

119 lines
4.5 KiB

using MediaBrowser.Controller.Configuration;
11 years ago
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using Microsoft.Extensions.Logging;
11 years ago
using MediaBrowser.XbmcMetadata.Configuration;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Xml;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
11 years ago
namespace MediaBrowser.XbmcMetadata.Savers
{
public class EpisodeNfoSaver : BaseNfoSaver
{
protected override string GetLocalSavePath(BaseItem item)
11 years ago
{
return Path.ChangeExtension(item.Path, ".nfo");
}
protected override string GetRootElementName(BaseItem item)
11 years ago
{
return "episodedetails";
}
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
11 years ago
{
if (!item.SupportsLocalMetadata)
{
return false;
}
return item is Episode && updateType >= MinimumUpdateType;
11 years ago
}
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
11 years ago
{
var episode = (Episode)item;
if (episode.IndexNumber.HasValue)
{
writer.WriteElementString("episode", episode.IndexNumber.Value.ToString(UsCulture));
}
if (episode.IndexNumberEnd.HasValue)
{
writer.WriteElementString("episodenumberend", episode.IndexNumberEnd.Value.ToString(UsCulture));
}
if (episode.ParentIndexNumber.HasValue)
{
writer.WriteElementString("season", episode.ParentIndexNumber.Value.ToString(UsCulture));
}
if (episode.PremiereDate.HasValue)
{
var formatString = ConfigurationManager.GetNfoConfiguration().ReleaseDateFormat;
writer.WriteElementString("aired", episode.PremiereDate.Value.ToLocalTime().ToString(formatString));
11 years ago
}
if (!episode.ParentIndexNumber.HasValue || episode.ParentIndexNumber.Value == 0)
11 years ago
{
if (episode.AirsAfterSeasonNumber.HasValue && episode.AirsAfterSeasonNumber.Value != -1)
{
writer.WriteElementString("airsafter_season", episode.AirsAfterSeasonNumber.Value.ToString(UsCulture));
}
if (episode.AirsBeforeEpisodeNumber.HasValue && episode.AirsBeforeEpisodeNumber.Value != -1)
{
writer.WriteElementString("airsbefore_episode", episode.AirsBeforeEpisodeNumber.Value.ToString(UsCulture));
}
if (episode.AirsBeforeSeasonNumber.HasValue && episode.AirsBeforeSeasonNumber.Value != -1)
{
writer.WriteElementString("airsbefore_season", episode.AirsBeforeSeasonNumber.Value.ToString(UsCulture));
}
11 years ago
if (episode.AirsBeforeEpisodeNumber.HasValue && episode.AirsBeforeEpisodeNumber.Value != -1)
{
writer.WriteElementString("displayepisode", episode.AirsBeforeEpisodeNumber.Value.ToString(UsCulture));
}
var specialSeason = episode.AiredSeasonNumber;
if (specialSeason.HasValue && specialSeason.Value != -1)
{
writer.WriteElementString("displayseason", specialSeason.Value.ToString(UsCulture));
}
}
11 years ago
}
private readonly CultureInfo UsCulture = new CultureInfo("en-US");
11 years ago
protected override List<string> GetTagsUsed(BaseItem item)
11 years ago
{
var list = base.GetTagsUsed(item);
list.AddRange(new string[]
11 years ago
{
"aired",
"season",
"episode",
"episodenumberend",
"airsafter_season",
"airsbefore_episode",
"airsbefore_season",
"displayseason",
"displayepisode"
});
11 years ago
return list;
}
public EpisodeNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
11 years ago
}
}