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; }
///
/// 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;
}
}
}