2019-01-13 13:03:10 -07:00
|
|
|
using System.Linq;
|
2019-01-13 12:26:31 -07:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-02-07 15:40:03 -07:00
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Music
|
|
|
|
{
|
|
|
|
public static class Extensions
|
|
|
|
{
|
|
|
|
public static string GetAlbumArtist(this AlbumInfo info)
|
|
|
|
{
|
2014-08-28 17:49:25 -07:00
|
|
|
var id = info.SongInfos.SelectMany(i => i.AlbumArtists)
|
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
2014-02-07 15:40:03 -07:00
|
|
|
|
2014-08-28 17:49:25 -07:00
|
|
|
if (!string.IsNullOrEmpty(id))
|
2014-02-07 15:40:03 -07:00
|
|
|
{
|
2014-08-28 17:49:25 -07:00
|
|
|
return id;
|
2014-02-07 15:40:03 -07:00
|
|
|
}
|
|
|
|
|
2014-08-28 17:49:25 -07:00
|
|
|
return info.AlbumArtists.FirstOrDefault();
|
2014-02-07 15:40:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetReleaseGroupId(this AlbumInfo info)
|
|
|
|
{
|
|
|
|
var id = info.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup))
|
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetReleaseId(this AlbumInfo info)
|
|
|
|
{
|
|
|
|
var id = info.GetProviderId(MetadataProviders.MusicBrainzAlbum);
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProviders.MusicBrainzAlbum))
|
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2014-02-09 00:27:44 -07:00
|
|
|
public static string GetMusicBrainzArtistId(this AlbumInfo info)
|
2014-02-07 15:40:03 -07:00
|
|
|
{
|
2019-01-17 12:24:39 -07:00
|
|
|
info.ProviderIds.TryGetValue(MetadataProviders.MusicBrainzAlbumArtist.ToString(), out string id);
|
2014-02-07 15:40:03 -07:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
|
|
|
info.ArtistProviderIds.TryGetValue(MetadataProviders.MusicBrainzArtist.ToString(), out id);
|
|
|
|
}
|
2019-01-07 16:27:46 -07:00
|
|
|
|
2014-02-07 15:40:03 -07:00
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProviders.MusicBrainzAlbumArtist))
|
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2014-02-08 13:02:35 -07:00
|
|
|
|
2014-02-09 00:27:44 -07:00
|
|
|
public static string GetMusicBrainzArtistId(this ArtistInfo info)
|
2014-02-08 13:02:35 -07:00
|
|
|
{
|
2019-01-13 13:46:33 -07:00
|
|
|
info.ProviderIds.TryGetValue(MetadataProviders.MusicBrainzArtist.ToString(), out var id);
|
2014-02-08 13:02:35 -07:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProviders.MusicBrainzAlbumArtist))
|
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2014-02-07 15:40:03 -07:00
|
|
|
}
|
|
|
|
}
|