| | 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.IO; |
| | 8 | | using MediaBrowser.Providers.Manager; |
| | 9 | | using Microsoft.Extensions.Logging; |
| | 10 | |
|
| | 11 | | namespace MediaBrowser.Providers.TV |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Service to manage episode metadata. |
| | 15 | | /// </summary> |
| | 16 | | public class EpisodeMetadataService : MetadataService<Episode, EpisodeInfo> |
| | 17 | | { |
| | 18 | | /// <summary> |
| | 19 | | /// Initializes a new instance of the <see cref="EpisodeMetadataService"/> class. |
| | 20 | | /// </summary> |
| | 21 | | /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface |
| | 22 | | /// <param name="logger">Instance of the <see cref="ILogger{SeasonMetadataService}"/> interface.</param> |
| | 23 | | /// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param> |
| | 24 | | /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param> |
| | 25 | | /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> |
| | 26 | | public EpisodeMetadataService( |
| | 27 | | IServerConfigurationManager serverConfigurationManager, |
| | 28 | | ILogger<EpisodeMetadataService> logger, |
| | 29 | | IProviderManager providerManager, |
| | 30 | | IFileSystem fileSystem, |
| | 31 | | ILibraryManager libraryManager) |
| 21 | 32 | | : base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager) |
| | 33 | | { |
| 21 | 34 | | } |
| | 35 | |
|
| | 36 | | /// <inheritdoc /> |
| | 37 | | protected override ItemUpdateType BeforeSaveInternal(Episode item, bool isFullRefresh, ItemUpdateType updateType |
| | 38 | | { |
| 0 | 39 | | var updatedType = base.BeforeSaveInternal(item, isFullRefresh, updateType); |
| | 40 | |
|
| 0 | 41 | | var seriesName = item.FindSeriesName(); |
| 0 | 42 | | if (!string.Equals(item.SeriesName, seriesName, StringComparison.Ordinal)) |
| | 43 | | { |
| 0 | 44 | | item.SeriesName = seriesName; |
| 0 | 45 | | updatedType |= ItemUpdateType.MetadataImport; |
| | 46 | | } |
| | 47 | |
|
| 0 | 48 | | var seasonName = item.FindSeasonName(); |
| 0 | 49 | | if (!string.Equals(item.SeasonName, seasonName, StringComparison.Ordinal)) |
| | 50 | | { |
| 0 | 51 | | item.SeasonName = seasonName; |
| 0 | 52 | | updatedType |= ItemUpdateType.MetadataImport; |
| | 53 | | } |
| | 54 | |
|
| 0 | 55 | | var seriesId = item.FindSeriesId(); |
| 0 | 56 | | if (!item.SeriesId.Equals(seriesId)) |
| | 57 | | { |
| 0 | 58 | | item.SeriesId = seriesId; |
| 0 | 59 | | updatedType |= ItemUpdateType.MetadataImport; |
| | 60 | | } |
| | 61 | |
|
| 0 | 62 | | var seasonId = item.FindSeasonId(); |
| 0 | 63 | | if (!item.SeasonId.Equals(seasonId)) |
| | 64 | | { |
| 0 | 65 | | item.SeasonId = seasonId; |
| 0 | 66 | | updatedType |= ItemUpdateType.MetadataImport; |
| | 67 | | } |
| | 68 | |
|
| 0 | 69 | | var seriesPresentationUniqueKey = item.FindSeriesPresentationUniqueKey(); |
| 0 | 70 | | if (!string.Equals(item.SeriesPresentationUniqueKey, seriesPresentationUniqueKey, StringComparison.Ordinal)) |
| | 71 | | { |
| 0 | 72 | | item.SeriesPresentationUniqueKey = seriesPresentationUniqueKey; |
| 0 | 73 | | updatedType |= ItemUpdateType.MetadataImport; |
| | 74 | | } |
| | 75 | |
|
| 0 | 76 | | return updatedType; |
| | 77 | | } |
| | 78 | |
|
| | 79 | | /// <inheritdoc /> |
| | 80 | | protected override void MergeData(MetadataResult<Episode> source, MetadataResult<Episode> target, MetadataField[ |
| | 81 | | { |
| 0 | 82 | | base.MergeData(source, target, lockedFields, replaceData, mergeMetadataSettings); |
| | 83 | |
|
| 0 | 84 | | var sourceItem = source.Item; |
| 0 | 85 | | var targetItem = target.Item; |
| | 86 | |
|
| 0 | 87 | | if (replaceData || !targetItem.AirsBeforeSeasonNumber.HasValue) |
| | 88 | | { |
| 0 | 89 | | targetItem.AirsBeforeSeasonNumber = sourceItem.AirsBeforeSeasonNumber; |
| | 90 | | } |
| | 91 | |
|
| 0 | 92 | | if (replaceData || !targetItem.AirsAfterSeasonNumber.HasValue) |
| | 93 | | { |
| 0 | 94 | | targetItem.AirsAfterSeasonNumber = sourceItem.AirsAfterSeasonNumber; |
| | 95 | | } |
| | 96 | |
|
| 0 | 97 | | if (replaceData || !targetItem.AirsBeforeEpisodeNumber.HasValue) |
| | 98 | | { |
| 0 | 99 | | targetItem.AirsBeforeEpisodeNumber = sourceItem.AirsBeforeEpisodeNumber; |
| | 100 | | } |
| | 101 | |
|
| 0 | 102 | | if (replaceData || !targetItem.IndexNumberEnd.HasValue) |
| | 103 | | { |
| 0 | 104 | | targetItem.IndexNumberEnd = sourceItem.IndexNumberEnd; |
| | 105 | | } |
| | 106 | |
|
| 0 | 107 | | if (replaceData || !targetItem.ParentIndexNumber.HasValue) |
| | 108 | | { |
| 0 | 109 | | targetItem.ParentIndexNumber = sourceItem.ParentIndexNumber; |
| | 110 | | } |
| 0 | 111 | | } |
| | 112 | | } |
| | 113 | | } |