From 17bacee0890cb03a579f9469e435d922bbdfdd50 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 21 Nov 2013 15:48:26 -0500 Subject: consolidate Artist & MusicArtist --- MediaBrowser.Controller/Entities/Audio/Artist.cs | 86 ---------------------- .../Entities/Audio/MusicArtist.cs | 69 ++++++++++++++++- MediaBrowser.Controller/Entities/BaseItem.cs | 5 ++ MediaBrowser.Controller/Entities/Folder.cs | 20 ++--- MediaBrowser.Controller/Entities/IItemByName.cs | 5 ++ MediaBrowser.Controller/Library/ILibraryManager.cs | 15 +++- .../MediaBrowser.Controller.csproj | 1 - 7 files changed, 97 insertions(+), 104 deletions(-) delete mode 100644 MediaBrowser.Controller/Entities/Audio/Artist.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Entities/Audio/Artist.cs b/MediaBrowser.Controller/Entities/Audio/Artist.cs deleted file mode 100644 index 947ee1122..000000000 --- a/MediaBrowser.Controller/Entities/Audio/Artist.cs +++ /dev/null @@ -1,86 +0,0 @@ -using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Runtime.Serialization; - -namespace MediaBrowser.Controller.Entities.Audio -{ - /// - /// Class Artist - /// - public class Artist : BaseItem, IItemByName, IHasMusicGenres - { - public Artist() - { - UserItemCounts = new Dictionary(); - } - - public string LastFmImageUrl { get; set; } - public string LastFmImageSize { get; set; } - - /// - /// Gets the user data key. - /// - /// System.String. - public override string GetUserDataKey() - { - return GetUserDataKey(this); - } - - [IgnoreDataMember] - public Dictionary UserItemCounts { get; set; } - - /// - /// Finds the music artist. - /// - /// The artist. - /// The library manager. - /// MusicArtist. - public static MusicArtist FindMusicArtist(Artist artist, ILibraryManager libraryManager) - { - return FindMusicArtist(artist, libraryManager.RootFolder.RecursiveChildren.OfType()); - } - - /// - /// Finds the music artist. - /// - /// The artist. - /// All music artists. - /// MusicArtist. - public static MusicArtist FindMusicArtist(Artist artist, IEnumerable allMusicArtists) - { - var musicBrainzId = artist.GetProviderId(MetadataProviders.Musicbrainz); - - return allMusicArtists.FirstOrDefault(i => - { - if (!string.IsNullOrWhiteSpace(musicBrainzId) && string.Equals(musicBrainzId, i.GetProviderId(MetadataProviders.Musicbrainz), StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - return string.Compare(i.Name, artist.Name, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols) == 0; - }); - } - - /// - /// Gets the user data key. - /// - /// The item. - /// System.String. - public static string GetUserDataKey(BaseItem item) - { - var id = item.GetProviderId(MetadataProviders.Musicbrainz); - - if (!string.IsNullOrEmpty(id)) - { - return "Artist-Musicbrainz-" + id; - } - - return "Artist-" + item.Name; - } - } -} diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs index d791c92ae..a234844ff 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs @@ -1,11 +1,52 @@ - +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + namespace MediaBrowser.Controller.Entities.Audio { /// /// Class MusicArtist /// - public class MusicArtist : Folder + public class MusicArtist : Folder, IItemByName, IHasMusicGenres, IHasDualAccess { + [IgnoreDataMember] + public Dictionary UserItemCounts { get; set; } + + public bool IsAccessedByName { get; set; } + + public override bool IsFolder + { + get + { + return !IsAccessedByName; + } + } + + protected override IEnumerable ActualChildren + { + get + { + if (IsAccessedByName) + { + throw new InvalidOperationException("Artists accessed by name do not have children."); + } + + return base.ActualChildren; + } + } + + public override string GetClientTypeName() + { + if (IsAccessedByName) + { + //return "Artist"; + } + + return base.GetClientTypeName(); + } + /// /// Gets or sets the last fm image URL. /// @@ -13,13 +54,35 @@ namespace MediaBrowser.Controller.Entities.Audio public string LastFmImageUrl { get; set; } public string LastFmImageSize { get; set; } + public MusicArtist() + { + UserItemCounts = new Dictionary(); + } + /// /// Gets the user data key. /// /// System.String. public override string GetUserDataKey() { - return Artist.GetUserDataKey(this); + return GetUserDataKey(this); + } + + /// + /// Gets the user data key. + /// + /// The item. + /// System.String. + public static string GetUserDataKey(BaseItem item) + { + var id = item.GetProviderId(MetadataProviders.Musicbrainz); + + if (!string.IsNullOrEmpty(id)) + { + return "Artist-Musicbrainz-" + id; + } + + return "Artist-" + item.Name; } } } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 29765fe12..a10a2c263 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1145,6 +1145,11 @@ namespace MediaBrowser.Controller.Entities return changed; } + public virtual string GetClientTypeName() + { + return GetType().Name; + } + /// /// Determines if the item is considered new based on user settings /// diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 8dbc98193..5c561dc0f 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -1038,16 +1038,13 @@ namespace MediaBrowser.Controller.Entities } } - if (recursive) + if (recursive && child.IsFolder) { - var folder = child as Folder; + var folder = (Folder)child; - if (folder != null) + if (folder.AddChildrenToList(user, includeLinkedChildren, list, true, filter)) { - if (folder.AddChildrenToList(user, includeLinkedChildren, list, true, filter)) - { - hasLinkedChildren = true; - } + hasLinkedChildren = true; } } } @@ -1150,14 +1147,11 @@ namespace MediaBrowser.Controller.Entities list.Add(child); } - if (recursive) + if (recursive && child.IsFolder) { - var folder = child as Folder; + var folder = (Folder)child; - if (folder != null) - { - folder.AddChildrenToList(list, true, filter); - } + folder.AddChildrenToList(list, true, filter); } } } diff --git a/MediaBrowser.Controller/Entities/IItemByName.cs b/MediaBrowser.Controller/Entities/IItemByName.cs index 7284bf101..1cb375374 100644 --- a/MediaBrowser.Controller/Entities/IItemByName.cs +++ b/MediaBrowser.Controller/Entities/IItemByName.cs @@ -12,6 +12,11 @@ namespace MediaBrowser.Controller.Entities Dictionary UserItemCounts { get; set; } } + public interface IHasDualAccess : IItemByName + { + bool IsAccessedByName { get; } + } + public static class IItemByNameExtensions { public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, User user) diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 0a89c0df8..338edd568 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -60,7 +60,7 @@ namespace MediaBrowser.Controller.Library /// /// The name. /// Task{Artist}. - Artist GetArtist(string name); + MusicArtist GetArtist(string name); /// /// Gets a Studio @@ -302,5 +302,18 @@ namespace MediaBrowser.Controller.Library /// Type of the update. /// Task. Task SaveMetadata(BaseItem item, ItemUpdateType updateType); + + /// + /// Gets all artists. + /// + /// IEnumerable{System.String}. + IEnumerable GetAllArtists(); + + /// + /// Gets all artists. + /// + /// The items. + /// IEnumerable{System.String}. + IEnumerable GetAllArtists(IEnumerable items); } } \ No newline at end of file diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 8837d04f5..393107f1e 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -115,7 +115,6 @@ - -- cgit v1.2.3