| | 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.Entities; |
| | 10 | | using MediaBrowser.Model.IO; |
| | 11 | | using Microsoft.Extensions.Logging; |
| | 12 | |
|
| | 13 | | namespace MediaBrowser.XbmcMetadata.Savers |
| | 14 | | { |
| | 15 | | /// <summary> |
| | 16 | | /// Nfo saver for series. |
| | 17 | | /// </summary> |
| | 18 | | public class SeriesNfoSaver : BaseNfoSaver |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// Initializes a new instance of the <see cref="SeriesNfoSaver"/> 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 SeriesNfoSaver( |
| | 30 | | IFileSystem fileSystem, |
| | 31 | | IServerConfigurationManager configurationManager, |
| | 32 | | ILibraryManager libraryManager, |
| | 33 | | IUserManager userManager, |
| | 34 | | IUserDataManager userDataManager, |
| | 35 | | ILogger<SeriesNfoSaver> 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.Combine(item.Path, "tvshow.nfo"); |
| | 43 | |
|
| | 44 | | /// <inheritdoc /> |
| | 45 | | protected override string GetRootElementName(BaseItem item) |
| 0 | 46 | | => "tvshow"; |
| | 47 | |
|
| | 48 | | /// <inheritdoc /> |
| | 49 | | public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType) |
| 131 | 50 | | => item.SupportsLocalMetadata && item is Series && updateType >= MinimumUpdateType; |
| | 51 | |
|
| | 52 | | /// <inheritdoc /> |
| | 53 | | protected override void WriteCustomElements(BaseItem item, XmlWriter writer) |
| | 54 | | { |
| 0 | 55 | | var series = (Series)item; |
| | 56 | |
|
| 0 | 57 | | if (item.TryGetProviderId(MetadataProvider.Tvdb, out var tvdb)) |
| | 58 | | { |
| 0 | 59 | | writer.WriteElementString("id", tvdb); |
| | 60 | |
|
| 0 | 61 | | writer.WriteStartElement("episodeguide"); |
| | 62 | |
|
| 0 | 63 | | var language = item.GetPreferredMetadataLanguage(); |
| 0 | 64 | | language = string.IsNullOrEmpty(language) |
| 0 | 65 | | ? "en" |
| 0 | 66 | | : language; |
| | 67 | |
|
| 0 | 68 | | writer.WriteStartElement("url"); |
| 0 | 69 | | writer.WriteAttributeString("cache", tvdb + ".xml"); |
| 0 | 70 | | writer.WriteString( |
| 0 | 71 | | string.Format( |
| 0 | 72 | | CultureInfo.InvariantCulture, |
| 0 | 73 | | "http://www.thetvdb.com/api/1D62F2F90030C444/series/{0}/all/{1}.zip", |
| 0 | 74 | | tvdb, |
| 0 | 75 | | language)); |
| 0 | 76 | | writer.WriteEndElement(); |
| | 77 | |
|
| 0 | 78 | | writer.WriteEndElement(); |
| | 79 | | } |
| | 80 | |
|
| 0 | 81 | | writer.WriteElementString("season", "-1"); |
| 0 | 82 | | writer.WriteElementString("episode", "-1"); |
| | 83 | |
|
| 0 | 84 | | if (series.Status.HasValue) |
| | 85 | | { |
| 0 | 86 | | writer.WriteElementString("status", series.Status.Value.ToString()); |
| | 87 | | } |
| 0 | 88 | | } |
| | 89 | |
|
| | 90 | | /// <inheritdoc /> |
| | 91 | | protected override IEnumerable<string> GetTagsUsed(BaseItem item) |
| | 92 | | { |
| | 93 | | foreach (var tag in base.GetTagsUsed(item)) |
| | 94 | | { |
| | 95 | | yield return tag; |
| | 96 | | } |
| | 97 | |
|
| | 98 | | yield return "id"; |
| | 99 | | yield return "episodeguide"; |
| | 100 | | yield return "season"; |
| | 101 | | yield return "episode"; |
| | 102 | | yield return "status"; |
| | 103 | | yield return "displayorder"; |
| | 104 | | } |
| | 105 | | } |
| | 106 | | } |