BoxSetXmlSaver.cs 2.3 KB

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