jellyfin/MediaBrowser.XbmcMetadata/Savers/EpisodeNfoSaver.cs

134 lines
5.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2014-07-08 17:46:11 -07:00
using System.Globalization;
using System.IO;
using System.Xml;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
2016-10-25 12:02:04 -07:00
using MediaBrowser.Model.IO;
using MediaBrowser.XbmcMetadata.Configuration;
using Microsoft.Extensions.Logging;
2014-07-08 17:46:11 -07:00
namespace MediaBrowser.XbmcMetadata.Savers
{
/// <summary>
/// Nfo saver for episodes.
/// </summary>
2014-07-08 17:46:11 -07:00
public class EpisodeNfoSaver : BaseNfoSaver
{
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
/// <summary>
/// Initializes a new instance of the <see cref="EpisodeNfoSaver"/> class.
/// </summary>
/// <param name="fileSystem">The file system.</param>
/// <param name="configurationManager">the server configuration manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="userManager">The user manager.</param>
/// <param name="userDataManager">The user data manager.</param>
/// <param name="logger">The logger.</param>
public EpisodeNfoSaver(
IFileSystem fileSystem,
IServerConfigurationManager configurationManager,
ILibraryManager libraryManager,
IUserManager userManager,
IUserDataManager userDataManager,
ILogger<EpisodeNfoSaver> logger)
: base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
2014-07-08 17:46:11 -07:00
{
}
/// <inheritdoc />
protected override string GetLocalSavePath(BaseItem item)
=> Path.ChangeExtension(item.Path, ".nfo");
/// <inheritdoc />
2018-09-12 10:26:21 -07:00
protected override string GetRootElementName(BaseItem item)
=> "episodedetails";
2014-07-08 17:46:11 -07:00
/// <inheritdoc />
2018-09-12 10:26:21 -07:00
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
2019-09-20 03:42:08 -07:00
=> item.SupportsLocalMetadata && item is Episode && updateType >= MinimumUpdateType;
2014-07-08 17:46:11 -07:00
/// <inheritdoc />
2018-09-12 10:26:21 -07:00
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
2014-07-08 17:46:11 -07:00
{
var episode = (Episode)item;
2021-01-20 11:47:31 -07:00
writer.WriteElementString("showtitle", episode.SeriesName);
2014-07-08 17:46:11 -07:00
if (episode.IndexNumber.HasValue)
{
writer.WriteElementString("episode", episode.IndexNumber.Value.ToString(_usCulture));
2014-07-08 17:46:11 -07:00
}
if (episode.IndexNumberEnd.HasValue)
{
writer.WriteElementString("episodenumberend", episode.IndexNumberEnd.Value.ToString(_usCulture));
2014-07-08 17:46:11 -07:00
}
if (episode.ParentIndexNumber.HasValue)
{
writer.WriteElementString("season", episode.ParentIndexNumber.Value.ToString(_usCulture));
2014-07-08 17:46:11 -07:00
}
if (episode.PremiereDate.HasValue)
{
var formatString = ConfigurationManager.GetNfoConfiguration().ReleaseDateFormat;
writer.WriteElementString("aired", episode.PremiereDate.Value.ToLocalTime().ToString(formatString, CultureInfo.InvariantCulture));
2014-07-08 17:46:11 -07:00
}
2016-09-30 20:34:43 -07:00
if (!episode.ParentIndexNumber.HasValue || episode.ParentIndexNumber.Value == 0)
2014-07-08 17:46:11 -07:00
{
2016-09-30 20:34:43 -07:00
if (episode.AirsAfterSeasonNumber.HasValue && episode.AirsAfterSeasonNumber.Value != -1)
{
writer.WriteElementString("airsafter_season", episode.AirsAfterSeasonNumber.Value.ToString(_usCulture));
2016-09-30 20:34:43 -07:00
}
2016-09-30 20:34:43 -07:00
if (episode.AirsBeforeEpisodeNumber.HasValue && episode.AirsBeforeEpisodeNumber.Value != -1)
{
writer.WriteElementString("airsbefore_episode", episode.AirsBeforeEpisodeNumber.Value.ToString(_usCulture));
2016-09-30 20:34:43 -07:00
}
2016-09-30 20:34:43 -07:00
if (episode.AirsBeforeSeasonNumber.HasValue && episode.AirsBeforeSeasonNumber.Value != -1)
{
writer.WriteElementString("airsbefore_season", episode.AirsBeforeSeasonNumber.Value.ToString(_usCulture));
2016-09-30 20:34:43 -07:00
}
2014-07-08 17:46:11 -07:00
2016-08-28 09:46:28 -07:00
if (episode.AirsBeforeEpisodeNumber.HasValue && episode.AirsBeforeEpisodeNumber.Value != -1)
{
writer.WriteElementString("displayepisode", episode.AirsBeforeEpisodeNumber.Value.ToString(_usCulture));
2016-08-28 09:46:28 -07:00
}
var specialSeason = episode.AiredSeasonNumber;
if (specialSeason.HasValue && specialSeason.Value != -1)
{
writer.WriteElementString("displayseason", specialSeason.Value.ToString(_usCulture));
2016-08-28 09:46:28 -07:00
}
2016-06-24 13:07:35 -07:00
}
2014-07-08 17:46:11 -07:00
}
/// <inheritdoc />
2021-03-08 19:04:47 -07:00
protected override IEnumerable<string> GetTagsUsed(BaseItem item)
2014-07-08 17:46:11 -07:00
{
2021-03-08 19:04:47 -07:00
foreach (var tag in base.GetTagsUsed(item))
2014-07-08 17:46:11 -07:00
{
2021-03-08 19:04:47 -07:00
yield return tag;
}
yield return "aired";
yield return "season";
yield return "episode";
yield return "episodenumberend";
yield return "airsafter_season";
yield return "airsbefore_episode";
yield return "airsbefore_season";
yield return "displayseason";
yield return "displayepisode";
yield return "showtitle";
2016-10-25 19:53:47 -07:00
}
2014-07-08 17:46:11 -07:00
}
}