< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.Genre
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/Genre.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 37
Coverable lines: 37
Total lines: 129
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
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

File(s)

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

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Text.Json.Serialization;
 8using Jellyfin.Data.Enums;
 9using Jellyfin.Extensions;
 10using Microsoft.Extensions.Logging;
 11
 12namespace MediaBrowser.Controller.Entities
 13{
 14    /// <summary>
 15    /// Class Genre.
 16    /// </summary>
 17    public class Genre : BaseItem, IItemByName
 18    {
 19        /// <summary>
 20        /// Gets the folder containing the item.
 21        /// If the item is a folder, it returns the folder itself.
 22        /// </summary>
 23        /// <value>The containing folder path.</value>
 24        [JsonIgnore]
 025        public override string ContainingFolderPath => Path;
 26
 27        [JsonIgnore]
 028        public override bool IsDisplayedAsFolder => true;
 29
 30        [JsonIgnore]
 031        public override bool SupportsAncestors => false;
 32
 33        [JsonIgnore]
 034        public override bool SupportsPeople => false;
 35
 36        public override List<string> GetUserDataKeys()
 37        {
 038            var list = base.GetUserDataKeys();
 39
 040            list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
 041            return list;
 42        }
 43
 44        public override string CreatePresentationUniqueKey()
 45        {
 046            return GetUserDataKeys()[0];
 47        }
 48
 49        public override double GetDefaultPrimaryImageAspectRatio()
 50        {
 051            return 1;
 52        }
 53
 54        public override bool IsSaveLocalMetadataEnabled()
 55        {
 056            return true;
 57        }
 58
 59        public override bool CanDelete()
 60        {
 061            return false;
 62        }
 63
 64        public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
 65        {
 066            query.GenreIds = new[] { Id };
 067            query.ExcludeItemTypes = new[]
 068            {
 069                BaseItemKind.MusicVideo,
 070                BaseItemKind.Audio,
 071                BaseItemKind.MusicAlbum,
 072                BaseItemKind.MusicArtist
 073            };
 74
 075            return LibraryManager.GetItemList(query);
 76        }
 77
 78        public static string GetPath(string name)
 79        {
 080            return GetPath(name, true);
 81        }
 82
 83        public static string GetPath(string name, bool normalizeName)
 84        {
 85            // Trim the period at the end because windows will have a hard time with that
 086            var validName = normalizeName ?
 087                FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
 088                name;
 89
 090            return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.GenrePath, validName);
 91        }
 92
 93        private string GetRebasedPath()
 94        {
 095            return GetPath(System.IO.Path.GetFileName(Path), false);
 96        }
 97
 98        public override bool RequiresRefresh()
 99        {
 0100            var newPath = GetRebasedPath();
 0101            if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 102            {
 0103                Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
 0104                return true;
 105            }
 106
 0107            return base.RequiresRefresh();
 108        }
 109
 110        /// <summary>
 111        /// This is called before any metadata refresh and returns true if changes were made.
 112        /// </summary>
 113        /// <param name="replaceAllMetadata">Whether to replace all metadata.</param>
 114        /// <returns>true if the item has change, else false.</returns>
 115        public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
 116        {
 0117            var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
 118
 0119            var newPath = GetRebasedPath();
 0120            if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 121            {
 0122                Path = newPath;
 0123                hasChanges = true;
 124            }
 125
 0126            return hasChanges;
 127        }
 128    }
 129}