< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.TV.Season
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/TV/Season.cs
Line coverage
10%
Covered lines: 8
Uncovered lines: 69
Coverable lines: 77
Total lines: 297
Line coverage: 10.3%
Branch coverage
4%
Covered branches: 2
Total branches: 44
Branch coverage: 4.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 3/1/2026 - 12:12:03 AM Line coverage: 0% (0/77) Branch coverage: 0% (0/40) Total lines: 2935/4/2026 - 12:15:16 AM Line coverage: 0% (0/76) Branch coverage: 0% (0/40) Total lines: 2915/7/2026 - 12:15:44 AM Line coverage: 3.9% (3/76) Branch coverage: 5% (2/40) Total lines: 2915/27/2026 - 12:15:38 AM Line coverage: 3.8% (3/77) Branch coverage: 4.5% (2/44) Total lines: 2976/2/2026 - 12:15:49 AM Line coverage: 10.3% (8/77) Branch coverage: 4.5% (2/44) Total lines: 297 3/1/2026 - 12:12:03 AM Line coverage: 0% (0/77) Branch coverage: 0% (0/40) Total lines: 2935/4/2026 - 12:15:16 AM Line coverage: 0% (0/76) Branch coverage: 0% (0/40) Total lines: 2915/7/2026 - 12:15:44 AM Line coverage: 3.9% (3/76) Branch coverage: 5% (2/40) Total lines: 2915/27/2026 - 12:15:38 AM Line coverage: 3.8% (3/77) Branch coverage: 4.5% (2/44) Total lines: 2976/2/2026 - 12:15:49 AM Line coverage: 10.3% (8/77) Branch coverage: 4.5% (2/44) Total lines: 297

Coverage delta

Coverage delta 7 -7

Metrics

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Entities/TV/Season.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Globalization;
 8using System.Linq;
 9using System.Text.Json.Serialization;
 10using System.Threading;
 11using Jellyfin.Data.Enums;
 12using Jellyfin.Database.Implementations.Entities;
 13using Jellyfin.Extensions;
 14using MediaBrowser.Common;
 15using MediaBrowser.Controller.Dto;
 16using MediaBrowser.Controller.Providers;
 17using MediaBrowser.Model.Querying;
 18
 19namespace MediaBrowser.Controller.Entities.TV
 20{
 21    /// <summary>
 22    /// Class Season.
 23    /// </summary>
 24    [RequiresSourceSerialisation]
 25    public class Season : Folder, IHasSeries, IHasLookupInfo<SeasonInfo>
 26    {
 27        [JsonIgnore]
 028        public override bool SupportsAddingToPlaylist => true;
 29
 30        [JsonIgnore]
 031        public override bool IsPreSorted => true;
 32
 33        [JsonIgnore]
 034        public override bool SupportsDateLastMediaAdded => false;
 35
 36        [JsonIgnore]
 037        public override bool SupportsPeople => true;
 38
 39        [JsonIgnore]
 340        public override bool SupportsInheritedParentImages => true;
 41
 42        [JsonIgnore]
 343        public override Guid DisplayParentId => SeriesId;
 44
 45        /// <summary>
 46        /// Gets this Episode's Series Instance.
 47        /// </summary>
 48        /// <value>The series.</value>
 49        [JsonIgnore]
 50        public Series Series
 51        {
 52            get
 53            {
 1054                var seriesId = SeriesId;
 1055                if (seriesId.IsEmpty())
 56                {
 057                    seriesId = FindSeriesId();
 58                }
 59
 1060                return seriesId.IsEmpty() ? null : (LibraryManager.GetItemById(seriesId) as Series);
 61            }
 62        }
 63
 64        [JsonIgnore]
 65        public string SeriesPath
 66        {
 67            get
 68            {
 069                var series = Series;
 70
 071                if (series is not null)
 72                {
 073                    return series.Path;
 74                }
 75
 076                return System.IO.Path.GetDirectoryName(Path);
 77            }
 78        }
 79
 80        [JsonIgnore]
 81        public string SeriesPresentationUniqueKey { get; set; }
 82
 83        [JsonIgnore]
 84        public string SeriesName { get; set; }
 85
 86        [JsonIgnore]
 87        public Guid SeriesId { get; set; }
 88
 89        public override double GetDefaultPrimaryImageAspectRatio()
 90        {
 291            double value = 2;
 292            value /= 3;
 93
 294            return value;
 95        }
 96
 97        public string FindSeriesSortName()
 98        {
 099            var series = Series;
 0100            return series is null ? SeriesName : series.SortName;
 101        }
 102
 103        public override List<string> GetUserDataKeys()
 104        {
 0105            var list = base.GetUserDataKeys();
 106
 0107            var series = Series;
 0108            if (series is not null)
 109            {
 0110                var newList = series.GetUserDataKeys();
 0111                var suffix = (IndexNumber ?? 0).ToString("000", CultureInfo.InvariantCulture);
 0112                for (int i = 0; i < newList.Count; i++)
 113                {
 0114                    newList[i] = newList[i] + suffix;
 115                }
 116
 0117                newList.AddRange(list);
 0118                list = newList;
 119            }
 120
 0121            return list;
 122        }
 123
 124        public override int GetChildCount(User user)
 125        {
 0126            var result = GetChildren(user, true, null).Count;
 127
 0128            return result;
 129        }
 130
 131        /// <inheritdoc />
 132        public override string GetInheritedOriginalLanguage()
 133        {
 0134            return OriginalLanguage ?? Series?.GetInheritedOriginalLanguage();
 135        }
 136
 137        public override string CreatePresentationUniqueKey()
 138        {
 0139            if (IndexNumber.HasValue)
 140            {
 0141                var series = Series;
 0142                if (series is not null)
 143                {
 0144                    return series.PresentationUniqueKey + "-" + IndexNumber.Value.ToString("000", CultureInfo.InvariantC
 145                }
 146            }
 147
 0148            return base.CreatePresentationUniqueKey();
 149        }
 150
 151        /// <summary>
 152        /// Creates the name of the sort.
 153        /// </summary>
 154        /// <returns>System.String.</returns>
 155        protected override string CreateSortName()
 156        {
 0157            return IndexNumber is not null ? IndexNumber.Value.ToString("0000", CultureInfo.InvariantCulture) : Name;
 158        }
 159
 160        protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
 161        {
 0162            if (SourceType == SourceType.Channel)
 163            {
 164                try
 165                {
 0166                    query.Parent = this;
 0167                    query.ChannelIds = new[] { ChannelId };
 0168                    return ChannelManager.GetChannelItemsInternal(query, new Progress<double>(), CancellationToken.None)
 169                }
 0170                catch
 171                {
 172                    // Already logged at lower levels
 0173                    return new QueryResult<BaseItem>();
 174                }
 175            }
 176
 0177            if (query.User is null)
 178            {
 0179                return base.GetItemsInternal(query);
 180            }
 181
 0182            var user = query.User;
 183
 0184            var items = UserViewBuilder.Filter(GetEpisodes(user, query.DtoOptions, true), user, query, UserDataManager, 
 185
 0186            return PostFilterAndSort(items, query);
 0187        }
 188
 189        /// <summary>
 190        /// Gets the episodes.
 191        /// </summary>
 192        /// <param name="user">The user.</param>
 193        /// <param name="options">The options to use.</param>
 194        /// <param name="shouldIncludeMissingEpisodes">If missing episodes should be included.</param>
 195        /// <returns>Set of episodes.</returns>
 196        public List<BaseItem> GetEpisodes(User user, DtoOptions options, bool shouldIncludeMissingEpisodes)
 197        {
 0198            return GetEpisodes(Series, user, options, shouldIncludeMissingEpisodes);
 199        }
 200
 201        public List<BaseItem> GetEpisodes(Series series, User user, DtoOptions options, bool shouldIncludeMissingEpisode
 202        {
 0203            return GetEpisodes(series, user, null, options, shouldIncludeMissingEpisodes);
 204        }
 205
 206        public List<BaseItem> GetEpisodes(Series series, User user, IEnumerable<Episode> allSeriesEpisodes, DtoOptions o
 207        {
 0208            if (series is null)
 209            {
 0210                return [];
 211            }
 212
 0213            return series.GetSeasonEpisodes(this, user, allSeriesEpisodes, options, shouldIncludeMissingEpisodes);
 214        }
 215
 216        public List<BaseItem> GetEpisodes()
 217        {
 0218            return GetEpisodes(Series, null, null, new DtoOptions(true), true);
 219        }
 220
 221        public override List<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery query)
 222        {
 0223            return GetEpisodes(user, new DtoOptions(true), true);
 224        }
 225
 226        protected override bool GetBlockUnratedValue(User user)
 227        {
 228            // Don't block. Let either the entire series rating or episode rating determine it
 0229            return false;
 230        }
 231
 232        public override UnratedItem GetBlockUnratedType()
 233        {
 0234            return UnratedItem.Series;
 235        }
 236
 237        public string FindSeriesPresentationUniqueKey()
 238        {
 0239            var series = Series;
 0240            return series is null ? null : series.PresentationUniqueKey;
 241        }
 242
 243        public string FindSeriesName()
 244        {
 0245            var series = Series;
 0246            return series is null ? SeriesName : series.Name;
 247        }
 248
 249        public Guid FindSeriesId()
 250        {
 0251            var series = FindParent<Series>();
 0252            return series?.Id ?? Guid.Empty;
 253        }
 254
 255        /// <summary>
 256        /// Gets the lookup information.
 257        /// </summary>
 258        /// <returns>SeasonInfo.</returns>
 259        public SeasonInfo GetLookupInfo()
 260        {
 0261            var id = GetItemLookupInfo<SeasonInfo>();
 262
 0263            var series = Series;
 264
 0265            if (series is not null)
 266            {
 0267                id.SeriesProviderIds = series.ProviderIds;
 0268                id.SeriesDisplayOrder = series.DisplayOrder;
 269            }
 270
 0271            return id;
 272        }
 273
 274        /// <summary>
 275        /// This is called before any metadata refresh and returns true or false indicating if changes were made.
 276        /// </summary>
 277        /// <param name="replaceAllMetadata"><c>true</c> to replace metadata, <c>false</c> to not.</param>
 278        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 279        public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
 280        {
 0281            var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
 282
 0283            if (!IndexNumber.HasValue && !string.IsNullOrEmpty(Path))
 284            {
 0285                IndexNumber ??= LibraryManager.GetSeasonNumberFromPath(Path, ParentId);
 286
 287                // If a change was made record it
 0288                if (IndexNumber.HasValue)
 289                {
 0290                    hasChanges = true;
 291                }
 292            }
 293
 0294            return hasChanges;
 295        }
 296    }
 297}