AlbumXmlSaver.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using MediaBrowser.Controller.Configuration;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Entities.Audio;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Providers.Music;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Text;
  10. using System.Threading;
  11. namespace MediaBrowser.Providers.Savers
  12. {
  13. class AlbumXmlSaver : IMetadataSaver
  14. {
  15. private readonly IServerConfigurationManager _config;
  16. public AlbumXmlSaver(IServerConfigurationManager config)
  17. {
  18. _config = config;
  19. }
  20. /// <summary>
  21. /// Determines whether [is enabled for] [the specified item].
  22. /// </summary>
  23. /// <param name="item">The item.</param>
  24. /// <param name="updateType">Type of the update.</param>
  25. /// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
  26. public bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
  27. {
  28. var wasMetadataEdited = (updateType & ItemUpdateType.MetadataEdit) == ItemUpdateType.MetadataEdit;
  29. var wasMetadataDownloaded = (updateType & ItemUpdateType.MetadataDownload) == ItemUpdateType.MetadataDownload;
  30. // If new metadata has been downloaded and save local is on
  31. if (_config.Configuration.SaveLocalMeta && (wasMetadataEdited || wasMetadataDownloaded))
  32. {
  33. return item is MusicAlbum;
  34. }
  35. return false;
  36. }
  37. /// <summary>
  38. /// Saves the specified item.
  39. /// </summary>
  40. /// <param name="item">The item.</param>
  41. /// <param name="cancellationToken">The cancellation token.</param>
  42. /// <returns>Task.</returns>
  43. public void Save(BaseItem item, CancellationToken cancellationToken)
  44. {
  45. var builder = new StringBuilder();
  46. builder.Append("<Item>");
  47. XmlSaverHelpers.AddCommonNodes(item, builder);
  48. builder.Append("</Item>");
  49. var xmlFilePath = GetSavePath(item);
  50. XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { });
  51. }
  52. /// <summary>
  53. /// Gets the save path.
  54. /// </summary>
  55. /// <param name="item">The item.</param>
  56. /// <returns>System.String.</returns>
  57. public string GetSavePath(BaseItem item)
  58. {
  59. return Path.Combine(item.Path, "album.xml");
  60. }
  61. }
  62. }