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)
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
var id = info.GetProviderId(MetadataProvider.MusicBrainzReleaseGroup);
|
2014-02-07 15:40:03 -07:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzReleaseGroup))
|
2014-02-07 15:40:03 -07:00
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetReleaseId(this AlbumInfo info)
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
var id = info.GetProviderId(MetadataProvider.MusicBrainzAlbum);
|
2014-02-07 15:40:03 -07:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzAlbum))
|
2014-02-07 15:40:03 -07:00
|
|
|
.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
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
info.ProviderIds.TryGetValue(MetadataProvider.MusicBrainzAlbumArtist.ToString(), out string id);
|
2014-02-07 15:40:03 -07:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
info.ArtistProviderIds.TryGetValue(MetadataProvider.MusicBrainzArtist.ToString(), out id);
|
2014-02-07 15:40:03 -07:00
|
|
|
}
|
2019-01-07 16:27:46 -07:00
|
|
|
|
2014-02-07 15:40:03 -07:00
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzAlbumArtist))
|
2014-02-07 15:40:03 -07:00
|
|
|
.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
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
info.ProviderIds.TryGetValue(MetadataProvider.MusicBrainzArtist.ToString(), out var id);
|
2014-02-08 13:02:35 -07:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 12:17:49 -07:00
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzAlbumArtist))
|
2014-02-08 13:02:35 -07:00
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2014-02-07 15:40:03 -07:00
|
|
|
}
|
|
|
|
}
|