< Summary - Jellyfin

Information
Class: MediaBrowser.Providers.TV.EpisodeMetadataService
Assembly: MediaBrowser.Providers
File(s): /srv/git/jellyfin/MediaBrowser.Providers/TV/EpisodeMetadataService.cs
Line coverage
5%
Covered lines: 2
Uncovered lines: 36
Coverable lines: 38
Total lines: 113
Line coverage: 5.2%
Branch coverage
0%
Covered branches: 0
Total branches: 30
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%
BeforeSaveInternal(...)0%110100%
MergeData(...)0%420200%

File(s)

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

#LineLine coverage
 1using System;
 2using MediaBrowser.Controller.Configuration;
 3using MediaBrowser.Controller.Entities.TV;
 4using MediaBrowser.Controller.Library;
 5using MediaBrowser.Controller.Providers;
 6using MediaBrowser.Model.Entities;
 7using MediaBrowser.Model.IO;
 8using MediaBrowser.Providers.Manager;
 9using Microsoft.Extensions.Logging;
 10
 11namespace 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)
 2132            : base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
 33        {
 2134        }
 35
 36        /// <inheritdoc />
 37        protected override ItemUpdateType BeforeSaveInternal(Episode item, bool isFullRefresh, ItemUpdateType updateType
 38        {
 039            var updatedType = base.BeforeSaveInternal(item, isFullRefresh, updateType);
 40
 041            var seriesName = item.FindSeriesName();
 042            if (!string.Equals(item.SeriesName, seriesName, StringComparison.Ordinal))
 43            {
 044                item.SeriesName = seriesName;
 045                updatedType |= ItemUpdateType.MetadataImport;
 46            }
 47
 048            var seasonName = item.FindSeasonName();
 049            if (!string.Equals(item.SeasonName, seasonName, StringComparison.Ordinal))
 50            {
 051                item.SeasonName = seasonName;
 052                updatedType |= ItemUpdateType.MetadataImport;
 53            }
 54
 055            var seriesId = item.FindSeriesId();
 056            if (!item.SeriesId.Equals(seriesId))
 57            {
 058                item.SeriesId = seriesId;
 059                updatedType |= ItemUpdateType.MetadataImport;
 60            }
 61
 062            var seasonId = item.FindSeasonId();
 063            if (!item.SeasonId.Equals(seasonId))
 64            {
 065                item.SeasonId = seasonId;
 066                updatedType |= ItemUpdateType.MetadataImport;
 67            }
 68
 069            var seriesPresentationUniqueKey = item.FindSeriesPresentationUniqueKey();
 070            if (!string.Equals(item.SeriesPresentationUniqueKey, seriesPresentationUniqueKey, StringComparison.Ordinal))
 71            {
 072                item.SeriesPresentationUniqueKey = seriesPresentationUniqueKey;
 073                updatedType |= ItemUpdateType.MetadataImport;
 74            }
 75
 076            return updatedType;
 77        }
 78
 79        /// <inheritdoc />
 80        protected override void MergeData(MetadataResult<Episode> source, MetadataResult<Episode> target, MetadataField[
 81        {
 082            base.MergeData(source, target, lockedFields, replaceData, mergeMetadataSettings);
 83
 084            var sourceItem = source.Item;
 085            var targetItem = target.Item;
 86
 087            if (replaceData || !targetItem.AirsBeforeSeasonNumber.HasValue)
 88            {
 089                targetItem.AirsBeforeSeasonNumber = sourceItem.AirsBeforeSeasonNumber;
 90            }
 91
 092            if (replaceData || !targetItem.AirsAfterSeasonNumber.HasValue)
 93            {
 094                targetItem.AirsAfterSeasonNumber = sourceItem.AirsAfterSeasonNumber;
 95            }
 96
 097            if (replaceData || !targetItem.AirsBeforeEpisodeNumber.HasValue)
 98            {
 099                targetItem.AirsBeforeEpisodeNumber = sourceItem.AirsBeforeEpisodeNumber;
 100            }
 101
 0102            if (replaceData || !targetItem.IndexNumberEnd.HasValue)
 103            {
 0104                targetItem.IndexNumberEnd = sourceItem.IndexNumberEnd;
 105            }
 106
 0107            if (replaceData || !targetItem.ParentIndexNumber.HasValue)
 108            {
 0109                targetItem.ParentIndexNumber = sourceItem.ParentIndexNumber;
 110            }
 0111        }
 112    }
 113}