2019-01-13 20:03:10 +00:00
|
|
|
using System.Collections.Generic;
|
2014-07-09 00:46:11 +00:00
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.Xml;
|
2019-01-13 19:26:56 +00:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2016-10-25 19:02:04 +00:00
|
|
|
using MediaBrowser.Model.IO;
|
2019-01-13 19:26:56 +00:00
|
|
|
using MediaBrowser.XbmcMetadata.Configuration;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2014-07-09 00:46:11 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.XbmcMetadata.Savers
|
|
|
|
{
|
2020-02-23 11:11:43 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Nfo saver for episodes.
|
|
|
|
/// </summary>
|
2014-07-09 00:46:11 +00:00
|
|
|
public class EpisodeNfoSaver : BaseNfoSaver
|
|
|
|
{
|
2020-02-23 11:11:43 +00:00
|
|
|
/// <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)
|
2019-08-18 17:54:07 +00:00
|
|
|
: base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
|
2014-07-09 00:46:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-18 17:54:07 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
protected override string GetLocalSavePath(BaseItem item)
|
|
|
|
=> Path.ChangeExtension(item.Path, ".nfo");
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
protected override string GetRootElementName(BaseItem item)
|
2019-08-18 17:54:07 +00:00
|
|
|
=> "episodedetails";
|
2014-07-09 00:46:11 +00:00
|
|
|
|
2019-08-18 17:54:07 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
|
2019-09-20 10:42:08 +00:00
|
|
|
=> item.SupportsLocalMetadata && item is Episode && updateType >= MinimumUpdateType;
|
2014-07-09 00:46:11 +00:00
|
|
|
|
2019-08-18 17:54:07 +00:00
|
|
|
/// <inheritdoc />
|
2018-09-12 17:26:21 +00:00
|
|
|
protected override void WriteCustomElements(BaseItem item, XmlWriter writer)
|
2014-07-09 00:46:11 +00:00
|
|
|
{
|
|
|
|
var episode = (Episode)item;
|
|
|
|
|
2021-01-20 18:47:31 +00:00
|
|
|
writer.WriteElementString("showtitle", episode.SeriesName);
|
|
|
|
|
2014-07-09 00:46:11 +00:00
|
|
|
if (episode.IndexNumber.HasValue)
|
|
|
|
{
|
2021-09-26 14:14:36 +00:00
|
|
|
writer.WriteElementString("episode", episode.IndexNumber.Value.ToString(CultureInfo.InvariantCulture));
|
2014-07-09 00:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (episode.IndexNumberEnd.HasValue)
|
|
|
|
{
|
2021-09-26 14:14:36 +00:00
|
|
|
writer.WriteElementString("episodenumberend", episode.IndexNumberEnd.Value.ToString(CultureInfo.InvariantCulture));
|
2014-07-09 00:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (episode.ParentIndexNumber.HasValue)
|
|
|
|
{
|
2021-09-26 14:14:36 +00:00
|
|
|
writer.WriteElementString("season", episode.ParentIndexNumber.Value.ToString(CultureInfo.InvariantCulture));
|
2014-07-09 00:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (episode.PremiereDate.HasValue)
|
|
|
|
{
|
|
|
|
var formatString = ConfigurationManager.GetNfoConfiguration().ReleaseDateFormat;
|
|
|
|
|
2022-04-17 12:40:28 +00:00
|
|
|
writer.WriteElementString("aired", episode.PremiereDate.Value.ToString(formatString, CultureInfo.InvariantCulture));
|
2014-07-09 00:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-10-01 03:34:43 +00:00
|
|
|
if (!episode.ParentIndexNumber.HasValue || episode.ParentIndexNumber.Value == 0)
|
2014-07-09 00:46:11 +00:00
|
|
|
{
|
2016-10-01 03:34:43 +00:00
|
|
|
if (episode.AirsAfterSeasonNumber.HasValue && episode.AirsAfterSeasonNumber.Value != -1)
|
|
|
|
{
|
2021-09-26 14:14:36 +00:00
|
|
|
writer.WriteElementString("airsafter_season", episode.AirsAfterSeasonNumber.Value.ToString(CultureInfo.InvariantCulture));
|
2016-10-01 03:34:43 +00:00
|
|
|
}
|
2019-08-18 17:54:07 +00:00
|
|
|
|
2016-10-01 03:34:43 +00:00
|
|
|
if (episode.AirsBeforeEpisodeNumber.HasValue && episode.AirsBeforeEpisodeNumber.Value != -1)
|
|
|
|
{
|
2021-09-26 14:14:36 +00:00
|
|
|
writer.WriteElementString("airsbefore_episode", episode.AirsBeforeEpisodeNumber.Value.ToString(CultureInfo.InvariantCulture));
|
2016-10-01 03:34:43 +00:00
|
|
|
}
|
2019-08-18 17:54:07 +00:00
|
|
|
|
2016-10-01 03:34:43 +00:00
|
|
|
if (episode.AirsBeforeSeasonNumber.HasValue && episode.AirsBeforeSeasonNumber.Value != -1)
|
|
|
|
{
|
2021-09-26 14:14:36 +00:00
|
|
|
writer.WriteElementString("airsbefore_season", episode.AirsBeforeSeasonNumber.Value.ToString(CultureInfo.InvariantCulture));
|
2016-10-01 03:34:43 +00:00
|
|
|
}
|
2014-07-09 00:46:11 +00:00
|
|
|
|
2016-08-28 16:46:28 +00:00
|
|
|
if (episode.AirsBeforeEpisodeNumber.HasValue && episode.AirsBeforeEpisodeNumber.Value != -1)
|
|
|
|
{
|
2021-09-26 14:14:36 +00:00
|
|
|
writer.WriteElementString("displayepisode", episode.AirsBeforeEpisodeNumber.Value.ToString(CultureInfo.InvariantCulture));
|
2016-08-28 16:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var specialSeason = episode.AiredSeasonNumber;
|
|
|
|
if (specialSeason.HasValue && specialSeason.Value != -1)
|
|
|
|
{
|
2021-09-26 14:14:36 +00:00
|
|
|
writer.WriteElementString("displayseason", specialSeason.Value.ToString(CultureInfo.InvariantCulture));
|
2016-08-28 16:46:28 +00:00
|
|
|
}
|
2016-06-24 20:07:35 +00:00
|
|
|
}
|
2014-07-09 00:46:11 +00:00
|
|
|
}
|
|
|
|
|
2019-08-18 17:54:07 +00:00
|
|
|
/// <inheritdoc />
|
2021-03-09 02:04:47 +00:00
|
|
|
protected override IEnumerable<string> GetTagsUsed(BaseItem item)
|
2014-07-09 00:46:11 +00:00
|
|
|
{
|
2021-03-09 02:04:47 +00:00
|
|
|
foreach (var tag in base.GetTagsUsed(item))
|
2014-07-09 00:46:11 +00:00
|
|
|
{
|
2021-03-09 02:04:47 +00: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-26 02:53:47 +00:00
|
|
|
}
|
2014-07-09 00:46:11 +00:00
|
|
|
}
|
2018-12-13 13:18:25 +00:00
|
|
|
}
|