| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Globalization; |
| | 3 | | using System.IO; |
| | 4 | | using System.Xml; |
| | 5 | | using MediaBrowser.Controller.Configuration; |
| | 6 | | using MediaBrowser.Controller.Entities; |
| | 7 | | using MediaBrowser.Controller.Entities.TV; |
| | 8 | | using MediaBrowser.Controller.Library; |
| | 9 | | using MediaBrowser.Model.IO; |
| | 10 | | using MediaBrowser.XbmcMetadata.Configuration; |
| | 11 | | using Microsoft.Extensions.Logging; |
| | 12 | |
|
| | 13 | | namespace MediaBrowser.XbmcMetadata.Savers |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Nfo saver for episodes. |
| | 17 | | /// </summary> |
| | 18 | | public class EpisodeNfoSaver : BaseNfoSaver |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// Initializes a new instance of the <see cref="EpisodeNfoSaver"/> class. |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="fileSystem">The file system.</param> |
| | 24 | | /// <param name="configurationManager">the server configuration manager.</param> |
| | 25 | | /// <param name="libraryManager">The library manager.</param> |
| | 26 | | /// <param name="userManager">The user manager.</param> |
| | 27 | | /// <param name="userDataManager">The user data manager.</param> |
| | 28 | | /// <param name="logger">The logger.</param> |
| | 29 | | public EpisodeNfoSaver( |
| | 30 | | IFileSystem fileSystem, |
| | 31 | | IServerConfigurationManager configurationManager, |
| | 32 | | ILibraryManager libraryManager, |
| | 33 | | IUserManager userManager, |
| | 34 | | IUserDataManager userDataManager, |
| | 35 | | ILogger<EpisodeNfoSaver> logger) |
| 21 | 36 | | : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger) |
| | 37 | | { |
| 21 | 38 | | } |
| | 39 | |
|
| | 40 | | /// <inheritdoc /> |
| | 41 | | protected override string GetLocalSavePath(BaseItem item) |
| 0 | 42 | | => Path.ChangeExtension(item.Path, ".nfo"); |
| | 43 | |
|
| | 44 | | /// <inheritdoc /> |
| | 45 | | protected override string GetRootElementName(BaseItem item) |
| 0 | 46 | | => "episodedetails"; |
| | 47 | |
|
| | 48 | | /// <inheritdoc /> |
| | 49 | | public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType) |
| 131 | 50 | | => item.SupportsLocalMetadata && item is Episode && updateType >= MinimumUpdateType; |
| | 51 | |
|
| | 52 | | /// <inheritdoc /> |
| | 53 | | protected override void WriteCustomElements(BaseItem item, XmlWriter writer) |
| | 54 | | { |
| 0 | 55 | | var episode = (Episode)item; |
| | 56 | |
|
| 0 | 57 | | writer.WriteElementString("showtitle", episode.SeriesName); |
| | 58 | |
|
| 0 | 59 | | if (episode.IndexNumber.HasValue) |
| | 60 | | { |
| 0 | 61 | | writer.WriteElementString("episode", episode.IndexNumber.Value.ToString(CultureInfo.InvariantCulture)); |
| | 62 | | } |
| | 63 | |
|
| 0 | 64 | | if (episode.IndexNumberEnd.HasValue) |
| | 65 | | { |
| 0 | 66 | | writer.WriteElementString("episodenumberend", episode.IndexNumberEnd.Value.ToString(CultureInfo.Invarian |
| | 67 | | } |
| | 68 | |
|
| 0 | 69 | | if (episode.ParentIndexNumber.HasValue) |
| | 70 | | { |
| 0 | 71 | | writer.WriteElementString("season", episode.ParentIndexNumber.Value.ToString(CultureInfo.InvariantCultur |
| | 72 | | } |
| | 73 | |
|
| 0 | 74 | | if (episode.PremiereDate.HasValue) |
| | 75 | | { |
| 0 | 76 | | var formatString = ConfigurationManager.GetNfoConfiguration().ReleaseDateFormat; |
| | 77 | |
|
| 0 | 78 | | writer.WriteElementString("aired", episode.PremiereDate.Value.ToString(formatString, CultureInfo.Invaria |
| | 79 | | } |
| | 80 | |
|
| 0 | 81 | | if (!episode.ParentIndexNumber.HasValue || episode.ParentIndexNumber.Value == 0) |
| | 82 | | { |
| 0 | 83 | | if (episode.AirsAfterSeasonNumber.HasValue && episode.AirsAfterSeasonNumber.Value != -1) |
| | 84 | | { |
| 0 | 85 | | writer.WriteElementString("airsafter_season", episode.AirsAfterSeasonNumber.Value.ToString(CultureIn |
| | 86 | | } |
| | 87 | |
|
| 0 | 88 | | if (episode.AirsBeforeEpisodeNumber.HasValue && episode.AirsBeforeEpisodeNumber.Value != -1) |
| | 89 | | { |
| 0 | 90 | | writer.WriteElementString("airsbefore_episode", episode.AirsBeforeEpisodeNumber.Value.ToString(Cultu |
| | 91 | | } |
| | 92 | |
|
| 0 | 93 | | if (episode.AirsBeforeSeasonNumber.HasValue && episode.AirsBeforeSeasonNumber.Value != -1) |
| | 94 | | { |
| 0 | 95 | | writer.WriteElementString("airsbefore_season", episode.AirsBeforeSeasonNumber.Value.ToString(Culture |
| | 96 | | } |
| | 97 | |
|
| 0 | 98 | | if (episode.AirsBeforeEpisodeNumber.HasValue && episode.AirsBeforeEpisodeNumber.Value != -1) |
| | 99 | | { |
| 0 | 100 | | writer.WriteElementString("displayepisode", episode.AirsBeforeEpisodeNumber.Value.ToString(CultureIn |
| | 101 | | } |
| | 102 | |
|
| 0 | 103 | | var specialSeason = episode.AiredSeasonNumber; |
| 0 | 104 | | if (specialSeason.HasValue && specialSeason.Value != -1) |
| | 105 | | { |
| 0 | 106 | | writer.WriteElementString("displayseason", specialSeason.Value.ToString(CultureInfo.InvariantCulture |
| | 107 | | } |
| | 108 | | } |
| 0 | 109 | | } |
| | 110 | |
|
| | 111 | | /// <inheritdoc /> |
| | 112 | | protected override IEnumerable<string> GetTagsUsed(BaseItem item) |
| | 113 | | { |
| | 114 | | foreach (var tag in base.GetTagsUsed(item)) |
| | 115 | | { |
| | 116 | | yield return tag; |
| | 117 | | } |
| | 118 | |
|
| | 119 | | yield return "aired"; |
| | 120 | | yield return "season"; |
| | 121 | | yield return "episode"; |
| | 122 | | yield return "episodenumberend"; |
| | 123 | | yield return "airsafter_season"; |
| | 124 | | yield return "airsbefore_episode"; |
| | 125 | | yield return "airsbefore_season"; |
| | 126 | | yield return "displayseason"; |
| | 127 | | yield return "displayepisode"; |
| | 128 | | yield return "showtitle"; |
| | 129 | | } |
| | 130 | | } |
| | 131 | | } |