BoxSetXmlSaver.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Entities.Movies;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Model.Entities;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Text;
  8. using System.Threading;
  9. namespace MediaBrowser.Providers.Savers
  10. {
  11. public class BoxSetXmlSaver : IMetadataFileSaver
  12. {
  13. public string Name
  14. {
  15. get
  16. {
  17. return "Media Browser Xml";
  18. }
  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(IHasMetadata item, ItemUpdateType updateType)
  27. {
  28. if (!item.SupportsLocalMetadata)
  29. {
  30. return false;
  31. }
  32. var wasMetadataEdited = (updateType & ItemUpdateType.MetadataEdit) == ItemUpdateType.MetadataEdit;
  33. var wasMetadataDownloaded = (updateType & ItemUpdateType.MetadataDownload) == ItemUpdateType.MetadataDownload;
  34. // If new metadata has been downloaded and save local is on
  35. if (wasMetadataEdited || wasMetadataDownloaded)
  36. {
  37. return item is BoxSet;
  38. }
  39. return false;
  40. }
  41. /// <summary>
  42. /// Saves the specified item.
  43. /// </summary>
  44. /// <param name="item">The item.</param>
  45. /// <param name="cancellationToken">The cancellation token.</param>
  46. /// <returns>Task.</returns>
  47. public void Save(IHasMetadata item, CancellationToken cancellationToken)
  48. {
  49. var builder = new StringBuilder();
  50. builder.Append("<Item>");
  51. XmlSaverHelpers.AddCommonNodes((BoxSet)item, builder);
  52. builder.Append("</Item>");
  53. var xmlFilePath = GetSavePath(item);
  54. XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { });
  55. }
  56. /// <summary>
  57. /// Gets the save path.
  58. /// </summary>
  59. /// <param name="item">The item.</param>
  60. /// <returns>System.String.</returns>
  61. public string GetSavePath(IHasMetadata item)
  62. {
  63. return Path.Combine(item.Path, "collection.xml");
  64. }
  65. }
  66. }