BoxSetXmlSaver.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. return item is BoxSet && updateType >= ItemUpdateType.MetadataDownload;
  33. }
  34. /// <summary>
  35. /// Saves the specified item.
  36. /// </summary>
  37. /// <param name="item">The item.</param>
  38. /// <param name="cancellationToken">The cancellation token.</param>
  39. /// <returns>Task.</returns>
  40. public void Save(IHasMetadata item, CancellationToken cancellationToken)
  41. {
  42. var builder = new StringBuilder();
  43. builder.Append("<Item>");
  44. XmlSaverHelpers.AddCommonNodes((BoxSet)item, builder);
  45. builder.Append("</Item>");
  46. var xmlFilePath = GetSavePath(item);
  47. XmlSaverHelpers.Save(builder, xmlFilePath, new List<string> { });
  48. }
  49. /// <summary>
  50. /// Gets the save path.
  51. /// </summary>
  52. /// <param name="item">The item.</param>
  53. /// <returns>System.String.</returns>
  54. public string GetSavePath(IHasMetadata item)
  55. {
  56. return Path.Combine(item.Path, "collection.xml");
  57. }
  58. }
  59. }