| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Globalization; |
| | 3 | | using System.IO; |
| | 4 | | using System.Linq; |
| | 5 | | using System.Xml; |
| | 6 | | using MediaBrowser.Controller.Configuration; |
| | 7 | | using MediaBrowser.Controller.Entities; |
| | 8 | | using MediaBrowser.Controller.Entities.Audio; |
| | 9 | | using MediaBrowser.Controller.Library; |
| | 10 | | using MediaBrowser.Model.IO; |
| | 11 | | using MediaBrowser.XbmcMetadata.Configuration; |
| | 12 | | using Microsoft.Extensions.Logging; |
| | 13 | |
|
| | 14 | | namespace MediaBrowser.XbmcMetadata.Savers |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Nfo saver for artist. |
| | 18 | | /// </summary> |
| | 19 | | public class ArtistNfoSaver : BaseNfoSaver |
| | 20 | | { |
| | 21 | | /// <summary> |
| | 22 | | /// Initializes a new instance of the <see cref="ArtistNfoSaver"/> class. |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="fileSystem">The file system.</param> |
| | 25 | | /// <param name="configurationManager">the server configuration manager.</param> |
| | 26 | | /// <param name="libraryManager">The library manager.</param> |
| | 27 | | /// <param name="userManager">The user manager.</param> |
| | 28 | | /// <param name="userDataManager">The user data manager.</param> |
| | 29 | | /// <param name="logger">The logger.</param> |
| | 30 | | public ArtistNfoSaver( |
| | 31 | | IFileSystem fileSystem, |
| | 32 | | IServerConfigurationManager configurationManager, |
| | 33 | | ILibraryManager libraryManager, |
| | 34 | | IUserManager userManager, |
| | 35 | | IUserDataManager userDataManager, |
| | 36 | | ILogger<ArtistNfoSaver> logger) |
| 21 | 37 | | : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger) |
| | 38 | | { |
| 21 | 39 | | } |
| | 40 | |
|
| | 41 | | /// <inheritdoc /> |
| | 42 | | protected override string GetLocalSavePath(BaseItem item) |
| 0 | 43 | | => Path.Combine(item.Path, "artist.nfo"); |
| | 44 | |
|
| | 45 | | /// <inheritdoc /> |
| | 46 | | protected override string GetRootElementName(BaseItem item) |
| 0 | 47 | | => "artist"; |
| | 48 | |
|
| | 49 | | /// <inheritdoc /> |
| | 50 | | public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType) |
| 131 | 51 | | => item.SupportsLocalMetadata && item is MusicArtist && updateType >= MinimumUpdateType; |
| | 52 | |
|
| | 53 | | /// <inheritdoc /> |
| | 54 | | protected override void WriteCustomElements(BaseItem item, XmlWriter writer) |
| | 55 | | { |
| 0 | 56 | | var artist = (MusicArtist)item; |
| | 57 | |
|
| 0 | 58 | | if (artist.EndDate.HasValue) |
| | 59 | | { |
| 0 | 60 | | var formatString = ConfigurationManager.GetNfoConfiguration().ReleaseDateFormat; |
| | 61 | |
|
| 0 | 62 | | writer.WriteElementString("disbanded", artist.EndDate.Value.ToString(formatString, CultureInfo.Invariant |
| | 63 | | } |
| | 64 | |
|
| 0 | 65 | | var albums = artist |
| 0 | 66 | | .GetRecursiveChildren(i => i is MusicAlbum); |
| | 67 | |
|
| 0 | 68 | | AddAlbums(albums, writer); |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | private void AddAlbums(IReadOnlyList<BaseItem> albums, XmlWriter writer) |
| | 72 | | { |
| 0 | 73 | | foreach (var album in albums |
| 0 | 74 | | .OrderBy(album => album.ProductionYear ?? 0) |
| 0 | 75 | | .ThenBy(album => SortNameOrName(album)) |
| 0 | 76 | | .ThenBy(album => album.Name?.Trim())) |
| | 77 | | { |
| 0 | 78 | | writer.WriteStartElement("album"); |
| | 79 | |
|
| 0 | 80 | | if (!string.IsNullOrEmpty(album.Name)) |
| | 81 | | { |
| 0 | 82 | | writer.WriteElementString("title", album.Name); |
| | 83 | | } |
| | 84 | |
|
| 0 | 85 | | if (album.ProductionYear.HasValue) |
| | 86 | | { |
| 0 | 87 | | writer.WriteElementString("year", album.ProductionYear.Value.ToString(CultureInfo.InvariantCulture)) |
| | 88 | | } |
| | 89 | |
|
| 0 | 90 | | writer.WriteEndElement(); |
| | 91 | | } |
| 0 | 92 | | } |
| | 93 | |
|
| | 94 | | /// <inheritdoc /> |
| | 95 | | protected override IEnumerable<string> GetTagsUsed(BaseItem item) |
| | 96 | | { |
| | 97 | | foreach (var tag in base.GetTagsUsed(item)) |
| | 98 | | { |
| | 99 | | yield return tag; |
| | 100 | | } |
| | 101 | |
|
| | 102 | | yield return "album"; |
| | 103 | | yield return "disbanded"; |
| | 104 | | } |
| | 105 | | } |
| | 106 | | } |