SeasonXmlSaver.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using MediaBrowser.Controller.Configuration;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Entities.TV;
  4. using MediaBrowser.Controller.Library;
  5. using System.IO;
  6. using System.Text;
  7. using System.Threading;
  8. namespace MediaBrowser.Providers.Savers
  9. {
  10. public class SeasonXmlSaver : IMetadataSaver
  11. {
  12. private readonly IServerConfigurationManager _config;
  13. public SeasonXmlSaver(IServerConfigurationManager config)
  14. {
  15. _config = config;
  16. }
  17. /// <summary>
  18. /// Determines whether [is enabled for] [the specified item].
  19. /// </summary>
  20. /// <param name="item">The item.</param>
  21. /// <param name="updateType">Type of the update.</param>
  22. /// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
  23. public bool IsEnabledFor(BaseItem item, ItemUpdateType updateType)
  24. {
  25. var wasMetadataEdited = (updateType & ItemUpdateType.MetadataEdit) == ItemUpdateType.MetadataEdit;
  26. var wasMetadataDownloaded = (updateType & ItemUpdateType.MetadataDownload) == ItemUpdateType.MetadataDownload;
  27. // If new metadata has been downloaded and save local is on, OR metadata was manually edited, proceed
  28. if ((_config.Configuration.SaveLocalMeta && (wasMetadataEdited || wasMetadataDownloaded)) || wasMetadataEdited)
  29. {
  30. return item is Season;
  31. }
  32. return false;
  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(BaseItem item, CancellationToken cancellationToken)
  41. {
  42. var builder = new StringBuilder();
  43. builder.Append("<Item>");
  44. XmlSaverHelpers.AddCommonNodes(item, builder);
  45. builder.Append("</Item>");
  46. var xmlFilePath = GetSavePath(item);
  47. XmlSaverHelpers.Save(builder, xmlFilePath, new 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(BaseItem item)
  55. {
  56. return Path.Combine(item.Path, "season.xml");
  57. }
  58. }
  59. }