< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.Year
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/Year.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 35
Coverable lines: 35
Total lines: 131
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
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
get_SupportsAncestors()100%210%
get_SupportsPeople()100%210%
get_ContainingFolderPath()100%210%
CanDelete()100%210%
GetUserDataKeys()100%210%
GetDefaultPrimaryImageAspectRatio()100%210%
IsSaveLocalMetadataEnabled()100%210%
GetTaggedItems(...)0%620%
GetYearValue()0%620%
GetPath(...)100%210%
GetPath(...)0%620%
GetRebasedPath()100%210%
RequiresRefresh()0%620%
BeforeMetadataRefresh(...)0%620%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Entities/Year.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Globalization;
 8using System.Text.Json.Serialization;
 9using Microsoft.Extensions.Logging;
 10
 11namespace MediaBrowser.Controller.Entities
 12{
 13    /// <summary>
 14    /// Class Year.
 15    /// </summary>
 16    public class Year : BaseItem, IItemByName
 17    {
 18        [JsonIgnore]
 019        public override bool SupportsAncestors => false;
 20
 21        [JsonIgnore]
 022        public override bool SupportsPeople => false;
 23
 24        /// <summary>
 25        /// Gets the folder containing the item.
 26        /// If the item is a folder, it returns the folder itself.
 27        /// </summary>
 28        /// <value>The containing folder path.</value>
 29        [JsonIgnore]
 030        public override string ContainingFolderPath => Path;
 31
 32        public override bool CanDelete()
 33        {
 034            return false;
 35        }
 36
 37        public override List<string> GetUserDataKeys()
 38        {
 039            var list = base.GetUserDataKeys();
 40
 041            list.Insert(0, "Year-" + Name);
 042            return list;
 43        }
 44
 45        public override double GetDefaultPrimaryImageAspectRatio()
 46        {
 047            double value = 2;
 048            value /= 3;
 49
 050            return value;
 51        }
 52
 53        public override bool IsSaveLocalMetadataEnabled()
 54        {
 055            return true;
 56        }
 57
 58        public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
 59        {
 060            if (!int.TryParse(Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out var year))
 61            {
 062                return new List<BaseItem>();
 63            }
 64
 065            query.Years = new[] { year };
 66
 067            return LibraryManager.GetItemList(query);
 68        }
 69
 70        public int? GetYearValue()
 71        {
 072            if (int.TryParse(Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out var year))
 73            {
 074                return year;
 75            }
 76
 077            return null;
 78        }
 79
 80        public static string GetPath(string name)
 81        {
 082            return GetPath(name, true);
 83        }
 84
 85        public static string GetPath(string name, bool normalizeName)
 86        {
 87            // Trim the period at the end because windows will have a hard time with that
 088            var validName = normalizeName ?
 089                FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
 090                name;
 91
 092            return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.YearPath, validName);
 93        }
 94
 95        private string GetRebasedPath()
 96        {
 097            return GetPath(System.IO.Path.GetFileName(Path), false);
 98        }
 99
 100        public override bool RequiresRefresh()
 101        {
 0102            var newPath = GetRebasedPath();
 0103            if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 104            {
 0105                Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
 0106                return true;
 107            }
 108
 0109            return base.RequiresRefresh();
 110        }
 111
 112        /// <summary>
 113        /// This is called before any metadata refresh and returns true if changes were made.
 114        /// </summary>
 115        /// <param name="replaceAllMetadata">Whether to replace all metadata.</param>
 116        /// <returns>true if the item has change, else false.</returns>
 117        public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
 118        {
 0119            var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
 120
 0121            var newPath = GetRebasedPath();
 0122            if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 123            {
 0124                Path = newPath;
 0125                hasChanges = true;
 126            }
 127
 0128            return hasChanges;
 129        }
 130    }
 131}