EpisodeMetadataService.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Entities.TV;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Controller.Providers;
  6. using MediaBrowser.Model.Entities;
  7. using MediaBrowser.Model.Logging;
  8. using MediaBrowser.Providers.Manager;
  9. using System.Collections.Generic;
  10. using System.Threading.Tasks;
  11. using CommonIO;
  12. namespace MediaBrowser.Providers.TV
  13. {
  14. public class EpisodeMetadataService : MetadataService<Episode, EpisodeInfo>
  15. {
  16. protected override async Task<ItemUpdateType> BeforeSave(Episode item, bool isFullRefresh, ItemUpdateType currentUpdateType)
  17. {
  18. var updateType = await base.BeforeSave(item, isFullRefresh, currentUpdateType).ConfigureAwait(false);
  19. if (updateType <= ItemUpdateType.None)
  20. {
  21. if (!string.Equals(item.SeriesName, item.FindSeriesName(), StringComparison.Ordinal))
  22. {
  23. updateType |= ItemUpdateType.MetadataImport;
  24. }
  25. }
  26. if (updateType <= ItemUpdateType.None)
  27. {
  28. if (!string.Equals(item.SeriesSortName, item.FindSeriesSortName(), StringComparison.Ordinal))
  29. {
  30. updateType |= ItemUpdateType.MetadataImport;
  31. }
  32. }
  33. if (updateType <= ItemUpdateType.None)
  34. {
  35. if (!string.Equals(item.SeasonName, item.FindSeasonName(), StringComparison.Ordinal))
  36. {
  37. updateType |= ItemUpdateType.MetadataImport;
  38. }
  39. }
  40. if (updateType <= ItemUpdateType.None)
  41. {
  42. if (item.SeriesId != item.FindSeriesId())
  43. {
  44. updateType |= ItemUpdateType.MetadataImport;
  45. }
  46. }
  47. if (updateType <= ItemUpdateType.None)
  48. {
  49. if (item.SeasonId != item.FindSeasonId())
  50. {
  51. updateType |= ItemUpdateType.MetadataImport;
  52. }
  53. }
  54. return updateType;
  55. }
  56. protected override void MergeData(MetadataResult<Episode> source, MetadataResult<Episode> target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings)
  57. {
  58. ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
  59. var sourceItem = source.Item;
  60. var targetItem = target.Item;
  61. if (replaceData || !targetItem.AirsBeforeSeasonNumber.HasValue)
  62. {
  63. targetItem.AirsBeforeSeasonNumber = sourceItem.AirsBeforeSeasonNumber;
  64. }
  65. if (replaceData || !targetItem.AirsAfterSeasonNumber.HasValue)
  66. {
  67. targetItem.AirsAfterSeasonNumber = sourceItem.AirsAfterSeasonNumber;
  68. }
  69. if (replaceData || !targetItem.AirsBeforeEpisodeNumber.HasValue)
  70. {
  71. targetItem.AirsBeforeEpisodeNumber = sourceItem.AirsBeforeEpisodeNumber;
  72. }
  73. if (replaceData || !targetItem.DvdSeasonNumber.HasValue)
  74. {
  75. targetItem.DvdSeasonNumber = sourceItem.DvdSeasonNumber;
  76. }
  77. if (replaceData || !targetItem.DvdEpisodeNumber.HasValue)
  78. {
  79. targetItem.DvdEpisodeNumber = sourceItem.DvdEpisodeNumber;
  80. }
  81. if (replaceData || !targetItem.AbsoluteEpisodeNumber.HasValue)
  82. {
  83. targetItem.AbsoluteEpisodeNumber = sourceItem.AbsoluteEpisodeNumber;
  84. }
  85. if (replaceData || !targetItem.IndexNumberEnd.HasValue)
  86. {
  87. targetItem.IndexNumberEnd = sourceItem.IndexNumberEnd;
  88. }
  89. }
  90. public EpisodeMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
  91. {
  92. }
  93. }
  94. }