| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using MediaBrowser.Controller.Configuration; |
| | 5 | | using MediaBrowser.Controller.Entities; |
| | 6 | | using MediaBrowser.Controller.Entities.TV; |
| | 7 | | using MediaBrowser.Controller.Library; |
| | 8 | | using MediaBrowser.Controller.Providers; |
| | 9 | | using MediaBrowser.Model.Entities; |
| | 10 | | using MediaBrowser.Model.IO; |
| | 11 | | using MediaBrowser.Providers.Manager; |
| | 12 | | using Microsoft.Extensions.Logging; |
| | 13 | |
|
| | 14 | | namespace MediaBrowser.Providers.TV |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Service to manage season metadata. |
| | 18 | | /// </summary> |
| | 19 | | public class SeasonMetadataService : MetadataService<Season, SeasonInfo> |
| | 20 | | { |
| | 21 | | /// <summary> |
| | 22 | | /// Initializes a new instance of the <see cref="SeasonMetadataService"/> class. |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface |
| | 25 | | /// <param name="logger">Instance of the <see cref="ILogger{SeasonMetadataService}"/> interface.</param> |
| | 26 | | /// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param> |
| | 27 | | /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param> |
| | 28 | | /// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param> |
| | 29 | | public SeasonMetadataService( |
| | 30 | | IServerConfigurationManager serverConfigurationManager, |
| | 31 | | ILogger<SeasonMetadataService> logger, |
| | 32 | | IProviderManager providerManager, |
| | 33 | | IFileSystem fileSystem, |
| | 34 | | ILibraryManager libraryManager) |
| 21 | 35 | | : base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager) |
| | 36 | | { |
| 21 | 37 | | } |
| | 38 | |
|
| | 39 | | /// <inheritdoc /> |
| 0 | 40 | | protected override bool EnableUpdatingPremiereDateFromChildren => true; |
| | 41 | |
|
| | 42 | | /// <inheritdoc /> |
| | 43 | | protected override ItemUpdateType BeforeSaveInternal(Season item, bool isFullRefresh, ItemUpdateType updateType) |
| | 44 | | { |
| 0 | 45 | | var updatedType = base.BeforeSaveInternal(item, isFullRefresh, updateType); |
| | 46 | |
|
| 0 | 47 | | if (item.IndexNumber == 0 && !item.IsLocked && !item.LockedFields.Contains(MetadataField.Name)) |
| | 48 | | { |
| 0 | 49 | | var seasonZeroDisplayName = LibraryManager.GetLibraryOptions(item).SeasonZeroDisplayName; |
| | 50 | |
|
| 0 | 51 | | if (!string.Equals(item.Name, seasonZeroDisplayName, StringComparison.OrdinalIgnoreCase)) |
| | 52 | | { |
| 0 | 53 | | item.Name = seasonZeroDisplayName; |
| 0 | 54 | | updatedType |= ItemUpdateType.MetadataEdit; |
| | 55 | | } |
| | 56 | | } |
| | 57 | |
|
| 0 | 58 | | var seriesName = item.FindSeriesName(); |
| 0 | 59 | | if (!string.Equals(item.SeriesName, seriesName, StringComparison.Ordinal)) |
| | 60 | | { |
| 0 | 61 | | item.SeriesName = seriesName; |
| 0 | 62 | | updatedType |= ItemUpdateType.MetadataImport; |
| | 63 | | } |
| | 64 | |
|
| 0 | 65 | | var seriesPresentationUniqueKey = item.FindSeriesPresentationUniqueKey(); |
| 0 | 66 | | if (!string.Equals(item.SeriesPresentationUniqueKey, seriesPresentationUniqueKey, StringComparison.Ordinal)) |
| | 67 | | { |
| 0 | 68 | | item.SeriesPresentationUniqueKey = seriesPresentationUniqueKey; |
| 0 | 69 | | updatedType |= ItemUpdateType.MetadataImport; |
| | 70 | | } |
| | 71 | |
|
| 0 | 72 | | var seriesId = item.FindSeriesId(); |
| 0 | 73 | | if (!item.SeriesId.Equals(seriesId)) |
| | 74 | | { |
| 0 | 75 | | item.SeriesId = seriesId; |
| 0 | 76 | | updatedType |= ItemUpdateType.MetadataImport; |
| | 77 | | } |
| | 78 | |
|
| 0 | 79 | | return updatedType; |
| | 80 | | } |
| | 81 | |
|
| | 82 | | /// <inheritdoc /> |
| | 83 | | protected override IReadOnlyList<BaseItem> GetChildrenForMetadataUpdates(Season item) |
| 0 | 84 | | => item.GetEpisodes(); |
| | 85 | |
|
| | 86 | | /// <inheritdoc /> |
| | 87 | | protected override ItemUpdateType UpdateMetadataFromChildren(Season item, IReadOnlyList<BaseItem> children, bool |
| | 88 | | { |
| 0 | 89 | | var updateType = base.UpdateMetadataFromChildren(item, children, isFullRefresh, currentUpdateType); |
| | 90 | |
|
| 0 | 91 | | if (isFullRefresh || currentUpdateType > ItemUpdateType.None) |
| | 92 | | { |
| 0 | 93 | | updateType |= SaveIsVirtualItem(item, children); |
| | 94 | | } |
| | 95 | |
|
| 0 | 96 | | return updateType; |
| | 97 | | } |
| | 98 | |
|
| | 99 | | private ItemUpdateType SaveIsVirtualItem(Season item, IReadOnlyList<BaseItem> episodes) |
| | 100 | | { |
| 0 | 101 | | var isVirtualItem = item.LocationType == LocationType.Virtual && (episodes.Count == 0 || episodes.All(i => i |
| | 102 | |
|
| 0 | 103 | | if (item.IsVirtualItem != isVirtualItem) |
| | 104 | | { |
| 0 | 105 | | item.IsVirtualItem = isVirtualItem; |
| 0 | 106 | | return ItemUpdateType.MetadataEdit; |
| | 107 | | } |
| | 108 | |
|
| 0 | 109 | | return ItemUpdateType.None; |
| | 110 | | } |
| | 111 | | } |
| | 112 | | } |