| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Linq; |
| | 8 | | using System.Text.Json.Serialization; |
| | 9 | | using System.Threading; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | | using Jellyfin.Data.Entities; |
| | 12 | | using Jellyfin.Data.Enums; |
| | 13 | | using Jellyfin.Extensions; |
| | 14 | | using MediaBrowser.Controller.Providers; |
| | 15 | | using MediaBrowser.Model.Entities; |
| | 16 | | using Microsoft.Extensions.Logging; |
| | 17 | | using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider; |
| | 18 | |
|
| | 19 | | namespace MediaBrowser.Controller.Entities.Audio |
| | 20 | | { |
| | 21 | | /// <summary> |
| | 22 | | /// Class MusicArtist. |
| | 23 | | /// </summary> |
| | 24 | | public class MusicArtist : Folder, IItemByName, IHasMusicGenres, IHasDualAccess, IHasLookupInfo<ArtistInfo> |
| | 25 | | { |
| | 26 | | [JsonIgnore] |
| 1 | 27 | | public bool IsAccessedByName => ParentId.IsEmpty(); |
| | 28 | |
|
| | 29 | | [JsonIgnore] |
| 1 | 30 | | public override bool IsFolder => !IsAccessedByName; |
| | 31 | |
|
| | 32 | | [JsonIgnore] |
| 0 | 33 | | public override bool SupportsInheritedParentImages => false; |
| | 34 | |
|
| | 35 | | [JsonIgnore] |
| 0 | 36 | | public override bool SupportsCumulativeRunTimeTicks => true; |
| | 37 | |
|
| | 38 | | [JsonIgnore] |
| 0 | 39 | | public override bool IsDisplayedAsFolder => true; |
| | 40 | |
|
| | 41 | | [JsonIgnore] |
| 0 | 42 | | public override bool SupportsAddingToPlaylist => true; |
| | 43 | |
|
| | 44 | | [JsonIgnore] |
| 0 | 45 | | public override bool SupportsPlayedStatus => false; |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Gets the folder containing the item. |
| | 49 | | /// If the item is a folder, it returns the folder itself. |
| | 50 | | /// </summary> |
| | 51 | | /// <value>The containing folder path.</value> |
| | 52 | | [JsonIgnore] |
| 0 | 53 | | public override string ContainingFolderPath => Path; |
| | 54 | |
|
| | 55 | | [JsonIgnore] |
| | 56 | | public override IEnumerable<BaseItem> Children |
| | 57 | | { |
| | 58 | | get |
| | 59 | | { |
| 0 | 60 | | if (IsAccessedByName) |
| | 61 | | { |
| 0 | 62 | | return Enumerable.Empty<BaseItem>(); |
| | 63 | | } |
| | 64 | |
|
| 0 | 65 | | return base.Children; |
| | 66 | | } |
| | 67 | | } |
| | 68 | |
|
| | 69 | | [JsonIgnore] |
| 0 | 70 | | public override bool SupportsPeople => false; |
| | 71 | |
|
| | 72 | | public static string GetPath(string name) |
| | 73 | | { |
| 0 | 74 | | return GetPath(name, true); |
| | 75 | | } |
| | 76 | |
|
| | 77 | | public override double GetDefaultPrimaryImageAspectRatio() |
| | 78 | | { |
| 0 | 79 | | return 1; |
| | 80 | | } |
| | 81 | |
|
| | 82 | | public override bool CanDelete() |
| | 83 | | { |
| 0 | 84 | | return !IsAccessedByName; |
| | 85 | | } |
| | 86 | |
|
| | 87 | | public IList<BaseItem> GetTaggedItems(InternalItemsQuery query) |
| | 88 | | { |
| 0 | 89 | | if (query.IncludeItemTypes.Length == 0) |
| | 90 | | { |
| 0 | 91 | | query.IncludeItemTypes = new[] { BaseItemKind.Audio, BaseItemKind.MusicVideo, BaseItemKind.MusicAlbum }; |
| 0 | 92 | | query.ArtistIds = new[] { Id }; |
| | 93 | | } |
| | 94 | |
|
| 0 | 95 | | return LibraryManager.GetItemList(query); |
| | 96 | | } |
| | 97 | |
|
| | 98 | | public override int GetChildCount(User user) |
| | 99 | | { |
| 0 | 100 | | return IsAccessedByName ? 0 : base.GetChildCount(user); |
| | 101 | | } |
| | 102 | |
|
| | 103 | | public override bool IsSaveLocalMetadataEnabled() |
| | 104 | | { |
| 0 | 105 | | if (IsAccessedByName) |
| | 106 | | { |
| 0 | 107 | | return true; |
| | 108 | | } |
| | 109 | |
|
| 0 | 110 | | return base.IsSaveLocalMetadataEnabled(); |
| | 111 | | } |
| | 112 | |
|
| | 113 | | protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMe |
| | 114 | | { |
| 0 | 115 | | if (IsAccessedByName) |
| | 116 | | { |
| | 117 | | // Should never get in here anyway |
| 0 | 118 | | return Task.CompletedTask; |
| | 119 | | } |
| | 120 | |
|
| 0 | 121 | | return base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, false, refreshOptions, direc |
| | 122 | | } |
| | 123 | |
|
| | 124 | | public override List<string> GetUserDataKeys() |
| | 125 | | { |
| 0 | 126 | | var list = base.GetUserDataKeys(); |
| | 127 | |
|
| 0 | 128 | | list.InsertRange(0, GetUserDataKeys(this)); |
| 0 | 129 | | return list; |
| | 130 | | } |
| | 131 | |
|
| | 132 | | /// <summary> |
| | 133 | | /// Gets the user data key. |
| | 134 | | /// </summary> |
| | 135 | | /// <param name="item">The item.</param> |
| | 136 | | /// <returns>System.String.</returns> |
| | 137 | | private static List<string> GetUserDataKeys(MusicArtist item) |
| | 138 | | { |
| 0 | 139 | | var list = new List<string>(); |
| 0 | 140 | | var id = item.GetProviderId(MetadataProvider.MusicBrainzArtist); |
| | 141 | |
|
| 0 | 142 | | if (!string.IsNullOrEmpty(id)) |
| | 143 | | { |
| 0 | 144 | | list.Add("Artist-Musicbrainz-" + id); |
| | 145 | | } |
| | 146 | |
|
| 0 | 147 | | list.Add("Artist-" + (item.Name ?? string.Empty).RemoveDiacritics()); |
| 0 | 148 | | return list; |
| | 149 | | } |
| | 150 | |
|
| | 151 | | public override string CreatePresentationUniqueKey() |
| | 152 | | { |
| 0 | 153 | | return "Artist-" + (Name ?? string.Empty).RemoveDiacritics(); |
| | 154 | | } |
| | 155 | |
|
| | 156 | | protected override bool GetBlockUnratedValue(User user) |
| | 157 | | { |
| 0 | 158 | | return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Music); |
| | 159 | | } |
| | 160 | |
|
| | 161 | | public override UnratedItem GetBlockUnratedType() |
| | 162 | | { |
| 0 | 163 | | return UnratedItem.Music; |
| | 164 | | } |
| | 165 | |
|
| | 166 | | public ArtistInfo GetLookupInfo() |
| | 167 | | { |
| 0 | 168 | | var info = GetItemLookupInfo<ArtistInfo>(); |
| | 169 | |
|
| 0 | 170 | | info.SongInfos = GetRecursiveChildren(i => i is Audio) |
| 0 | 171 | | .Cast<Audio>() |
| 0 | 172 | | .Select(i => i.GetLookupInfo()) |
| 0 | 173 | | .ToList(); |
| | 174 | |
|
| 0 | 175 | | return info; |
| | 176 | | } |
| | 177 | |
|
| | 178 | | public static string GetPath(string name, bool normalizeName) |
| | 179 | | { |
| | 180 | | // Trim the period at the end because windows will have a hard time with that |
| 0 | 181 | | var validName = normalizeName ? |
| 0 | 182 | | FileSystem.GetValidFilename(name).Trim().TrimEnd('.') : |
| 0 | 183 | | name; |
| | 184 | |
|
| 0 | 185 | | return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.ArtistsPath, validName); |
| | 186 | | } |
| | 187 | |
|
| | 188 | | private string GetRebasedPath() |
| | 189 | | { |
| 0 | 190 | | return GetPath(System.IO.Path.GetFileName(Path), false); |
| | 191 | | } |
| | 192 | |
|
| | 193 | | public override bool RequiresRefresh() |
| | 194 | | { |
| 0 | 195 | | if (IsAccessedByName) |
| | 196 | | { |
| 0 | 197 | | var newPath = GetRebasedPath(); |
| 0 | 198 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | 199 | | { |
| 0 | 200 | | Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath); |
| 0 | 201 | | return true; |
| | 202 | | } |
| | 203 | | } |
| | 204 | |
|
| 0 | 205 | | return base.RequiresRefresh(); |
| | 206 | | } |
| | 207 | |
|
| | 208 | | /// <summary> |
| | 209 | | /// This is called before any metadata refresh and returns true or false indicating if changes were made. |
| | 210 | | /// </summary> |
| | 211 | | /// <param name="replaceAllMetadata">Option to replace metadata.</param> |
| | 212 | | /// <returns>True if metadata changed.</returns> |
| | 213 | | public override bool BeforeMetadataRefresh(bool replaceAllMetadata) |
| | 214 | | { |
| 0 | 215 | | var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata); |
| | 216 | |
|
| 0 | 217 | | if (IsAccessedByName) |
| | 218 | | { |
| 0 | 219 | | var newPath = GetRebasedPath(); |
| 0 | 220 | | if (!string.Equals(Path, newPath, StringComparison.Ordinal)) |
| | 221 | | { |
| 0 | 222 | | Path = newPath; |
| 0 | 223 | | hasChanges = true; |
| | 224 | | } |
| | 225 | | } |
| | 226 | |
|
| 0 | 227 | | return hasChanges; |
| | 228 | | } |
| | 229 | | } |
| | 230 | | } |