< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.Audio.MusicGenre
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 32
Coverable lines: 32
Total lines: 126
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/Audio/MusicGenre.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.Audio
 13{
 14    /// <summary>
 15    /// Class MusicGenre.
 16    /// </summary>
 17    public class MusicGenre : BaseItem, IItemByName
 18    {
 19        [JsonIgnore]
 020        public override bool SupportsAddingToPlaylist => true;
 21
 22        [JsonIgnore]
 023        public override bool SupportsAncestors => false;
 24
 25        [JsonIgnore]
 026        public override bool IsDisplayedAsFolder => true;
 27
 28        /// <summary>
 29        /// Gets the folder containing the item.
 30        /// If the item is a folder, it returns the folder itself.
 31        /// </summary>
 32        /// <value>The containing folder path.</value>
 33        [JsonIgnore]
 034        public override string ContainingFolderPath => Path;
 35
 36        [JsonIgnore]
 037        public override bool SupportsPeople => false;
 38
 39        public override List<string> GetUserDataKeys()
 40        {
 041            var list = base.GetUserDataKeys();
 42
 043            list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
 044            return list;
 45        }
 46
 47        public override string CreatePresentationUniqueKey()
 48        {
 049            return GetUserDataKeys()[0];
 50        }
 51
 52        public override double GetDefaultPrimaryImageAspectRatio()
 53        {
 054            return 1;
 55        }
 56
 57        public override bool CanDelete()
 58        {
 059            return false;
 60        }
 61
 62        public override bool IsSaveLocalMetadataEnabled()
 63        {
 064            return true;
 65        }
 66
 67        public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
 68        {
 069            query.GenreIds = new[] { Id };
 070            query.IncludeItemTypes = new[] { BaseItemKind.MusicVideo, BaseItemKind.Audio, BaseItemKind.MusicAlbum, BaseI
 71
 072            return LibraryManager.GetItemList(query);
 73        }
 74
 75        public static string GetPath(string name)
 76        {
 077            return GetPath(name, true);
 78        }
 79
 80        public static string GetPath(string name, bool normalizeName)
 81        {
 82            // Trim the period at the end because windows will have a hard time with that
 083            var validName = normalizeName ?
 084                FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
 085                name;
 86
 087            return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.MusicGenrePath, validName);
 88        }
 89
 90        private string GetRebasedPath()
 91        {
 092            return GetPath(System.IO.Path.GetFileName(Path), false);
 93        }
 94
 95        public override bool RequiresRefresh()
 96        {
 097            var newPath = GetRebasedPath();
 098            if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 99            {
 0100                Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
 0101                return true;
 102            }
 103
 0104            return base.RequiresRefresh();
 105        }
 106
 107        /// <summary>
 108        /// This is called before any metadata refresh and returns true or false indicating if changes were made.
 109        /// </summary>
 110        /// <param name="replaceAllMetadata">Option to replace metadata.</param>
 111        /// <returns>True if metadata changed.</returns>
 112        public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
 113        {
 0114            var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
 115
 0116            var newPath = GetRebasedPath();
 0117            if (!string.Equals(Path, newPath, StringComparison.Ordinal))
 118            {
 0119                Path = newPath;
 0120                hasChanges = true;
 121            }
 122
 0123            return hasChanges;
 124        }
 125    }
 126}