< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.TV.SeasonMetadataService
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/TV/SeasonMetadataService.cs
Line coverage
6%
Covered lines: 2
Uncovered lines: 30
Coverable lines: 32
Total lines: 112
Line coverage: 6.2%
Branch coverage
0%
Covered branches: 0
Total branches: 24
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_EnableUpdatingPremiereDateFromChildren()100%210%
BeforeSaveInternal(...)0%210140%
GetChildrenForMetadataUpdates(...)100%210%
UpdateMetadataFromChildren(...)0%2040%
SaveIsVirtualItem(...)0%4260%

File(s)

/srv/git/jellyfin/MediaBrowser.Providers/TV/SeasonMetadataService.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using MediaBrowser.Controller.Configuration;
 5using MediaBrowser.Controller.Entities;
 6using MediaBrowser.Controller.Entities.TV;
 7using MediaBrowser.Controller.Library;
 8using MediaBrowser.Controller.Providers;
 9using MediaBrowser.Model.Entities;
 10using MediaBrowser.Model.IO;
 11using MediaBrowser.Providers.Manager;
 12using Microsoft.Extensions.Logging;
 13
 14namespace 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)
 2135            : base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
 36        {
 2137        }
 38
 39        /// <inheritdoc />
 040        protected override bool EnableUpdatingPremiereDateFromChildren => true;
 41
 42        /// <inheritdoc />
 43        protected override ItemUpdateType BeforeSaveInternal(Season item, bool isFullRefresh, ItemUpdateType updateType)
 44        {
 045            var updatedType = base.BeforeSaveInternal(item, isFullRefresh, updateType);
 46
 047            if (item.IndexNumber == 0 && !item.IsLocked && !item.LockedFields.Contains(MetadataField.Name))
 48            {
 049                var seasonZeroDisplayName = LibraryManager.GetLibraryOptions(item).SeasonZeroDisplayName;
 50
 051                if (!string.Equals(item.Name, seasonZeroDisplayName, StringComparison.OrdinalIgnoreCase))
 52                {
 053                    item.Name = seasonZeroDisplayName;
 054                    updatedType |= ItemUpdateType.MetadataEdit;
 55                }
 56            }
 57
 058            var seriesName = item.FindSeriesName();
 059            if (!string.Equals(item.SeriesName, seriesName, StringComparison.Ordinal))
 60            {
 061                item.SeriesName = seriesName;
 062                updatedType |= ItemUpdateType.MetadataImport;
 63            }
 64
 065            var seriesPresentationUniqueKey = item.FindSeriesPresentationUniqueKey();
 066            if (!string.Equals(item.SeriesPresentationUniqueKey, seriesPresentationUniqueKey, StringComparison.Ordinal))
 67            {
 068                item.SeriesPresentationUniqueKey = seriesPresentationUniqueKey;
 069                updatedType |= ItemUpdateType.MetadataImport;
 70            }
 71
 072            var seriesId = item.FindSeriesId();
 073            if (!item.SeriesId.Equals(seriesId))
 74            {
 075                item.SeriesId = seriesId;
 076                updatedType |= ItemUpdateType.MetadataImport;
 77            }
 78
 079            return updatedType;
 80        }
 81
 82        /// <inheritdoc />
 83        protected override IReadOnlyList<BaseItem> GetChildrenForMetadataUpdates(Season item)
 084            => item.GetEpisodes();
 85
 86        /// <inheritdoc />
 87        protected override ItemUpdateType UpdateMetadataFromChildren(Season item, IReadOnlyList<BaseItem> children, bool
 88        {
 089            var updateType = base.UpdateMetadataFromChildren(item, children, isFullRefresh, currentUpdateType);
 90
 091            if (isFullRefresh || currentUpdateType > ItemUpdateType.None)
 92            {
 093                updateType |= SaveIsVirtualItem(item, children);
 94            }
 95
 096            return updateType;
 97        }
 98
 99        private ItemUpdateType SaveIsVirtualItem(Season item, IReadOnlyList<BaseItem> episodes)
 100        {
 0101            var isVirtualItem = item.LocationType == LocationType.Virtual && (episodes.Count == 0 || episodes.All(i => i
 102
 0103            if (item.IsVirtualItem != isVirtualItem)
 104            {
 0105                item.IsVirtualItem = isVirtualItem;
 0106                return ItemUpdateType.MetadataEdit;
 107            }
 108
 0109            return ItemUpdateType.None;
 110        }
 111    }
 112}