| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Text.Json.Serialization; |
| | 8 | | using Jellyfin.Data.Enums; |
| | 9 | | using Jellyfin.Extensions; |
| | 10 | | using Microsoft.Extensions.Logging; |
| | 11 | |
|
| | 12 | | namespace 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] |
| 0 | 25 | | public override string ContainingFolderPath => Path; |
| | 26 | |
|
| | 27 | | [JsonIgnore] |
| 0 | 28 | | public override bool IsDisplayedAsFolder => true; |
| | 29 | |
|
| | 30 | | [JsonIgnore] |
| 0 | 31 | | public override bool SupportsAncestors => false; |
| | 32 | |
|
| | 33 | | [JsonIgnore] |
| 0 | 34 | | public override bool SupportsPeople => false; |
| | 35 | |
|
| | 36 | | public override List<string> GetUserDataKeys() |
| | 37 | | { |
| 0 | 38 | | var list = base.GetUserDataKeys(); |
| | 39 | |
|
| 0 | 40 | | list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics()); |
| 0 | 41 | | return list; |
| | 42 | | } |
| | 43 | |
|
| | 44 | | public override string CreatePresentationUniqueKey() |
| | 45 | | { |
| 0 | 46 | | return GetUserDataKeys()[0]; |
| | 47 | | } |
| | 48 | |
|
| | 49 | | public override double GetDefaultPrimaryImageAspectRatio() |
| | 50 | | { |
| 0 | 51 | | return 1; |
| | 52 | | } |
| | 53 | |
|
| | 54 | | public override bool IsSaveLocalMetadataEnabled() |
| | 55 | | { |
| 0 | 56 | | return true; |
| | 57 | | } |
| | 58 | |
|
| | 59 | | public override bool CanDelete() |
| | 60 | | { |
| 0 | 61 | | return false; |
| | 62 | | } |
| | 63 | |
|
| | 64 | | public IList<BaseItem> GetTaggedItems(InternalItemsQuery query) |
| | 65 | | { |
| 0 | 66 | | query.GenreIds = new[] { Id }; |
| 0 | 67 | | query.ExcludeItemTypes = new[] |
| 0 | 68 | | { |
| 0 | 69 | | BaseItemKind.MusicVideo, |
| 0 | 70 | | BaseItemKind.Audio, |
| 0 | 71 | | BaseItemKind.MusicAlbum, |
| 0 | 72 | | BaseItemKind.MusicArtist |
| 0 | 73 | | }; |
| | 74 | |
|
| 0 | 75 | | return LibraryManager.GetItemList(query); |
| | 76 | | } |
| | 77 | |
|
| | 78 | | public static string GetPath(string name) |
| | 79 | | { |
| 0 | 80 | | 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 |
| 0 | 86 | | var validName = normalizeName ? |
| 0 | 87 | | FileSystem.GetValidFilename(name).Trim().TrimEnd('.') : |
| 0 | 88 | | name; |
| | 89 | |
|
| 0 | 90 | | return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.GenrePath, validName); |
| | 91 | | } |
| | 92 | |
|
| | 93 | | private string GetRebasedPath() |
| | 94 | | { |
| 0 | 95 | | return GetPath(System.IO.Path.GetFileName(Path), false); |
| | 96 | | } |
| | 97 | |
|
| | 98 | | public override bool RequiresRefresh() |
| | 99 | | { |
| 0 | 100 | | var newPath = GetRebasedPath(); |
| 0 | 101 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | 102 | | { |
| 0 | 103 | | Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath); |
| 0 | 104 | | return true; |
| | 105 | | } |
| | 106 | |
|
| 0 | 107 | | 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 | | { |
| 0 | 117 | | var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata); |
| | 118 | |
|
| 0 | 119 | | var newPath = GetRebasedPath(); |
| 0 | 120 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | 121 | | { |
| 0 | 122 | | Path = newPath; |
| 0 | 123 | | hasChanges = true; |
| | 124 | | } |
| | 125 | |
|
| 0 | 126 | | return hasChanges; |
| | 127 | | } |
| | 128 | | } |
| | 129 | | } |