2020-06-19 18:24:13 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 20:03:10 +00:00
|
|
|
using System.Linq;
|
2019-01-13 19:26:31 +00:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-02-07 22:40:03 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
namespace MediaBrowser.Providers.Music
|
|
|
|
{
|
2020-08-07 17:26:28 +00:00
|
|
|
public static class AlbumInfoExtensions
|
2014-02-07 22:40:03 +00:00
|
|
|
{
|
2021-10-26 13:49:01 +00:00
|
|
|
public static string? GetAlbumArtist(this AlbumInfo info)
|
2014-02-07 22:40:03 +00:00
|
|
|
{
|
2014-08-29 00:49:25 +00:00
|
|
|
var id = info.SongInfos.SelectMany(i => i.AlbumArtists)
|
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
2014-02-07 22:40:03 +00:00
|
|
|
|
2014-08-29 00:49:25 +00:00
|
|
|
if (!string.IsNullOrEmpty(id))
|
2014-02-07 22:40:03 +00:00
|
|
|
{
|
2014-08-29 00:49:25 +00:00
|
|
|
return id;
|
2014-02-07 22:40:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 17:26:28 +00:00
|
|
|
return info.AlbumArtists.Count > 0 ? info.AlbumArtists[0] : default;
|
2014-02-07 22:40:03 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 13:49:01 +00:00
|
|
|
public static string? GetReleaseGroupId(this AlbumInfo info)
|
2014-02-07 22:40:03 +00:00
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
var id = info.GetProviderId(MetadataProvider.MusicBrainzReleaseGroup);
|
2014-02-07 22:40:03 +00:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzReleaseGroup))
|
2014-02-07 22:40:03 +00:00
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2021-10-26 13:49:01 +00:00
|
|
|
public static string? GetReleaseId(this AlbumInfo info)
|
2014-02-07 22:40:03 +00:00
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
var id = info.GetProviderId(MetadataProvider.MusicBrainzAlbum);
|
2014-02-07 22:40:03 +00:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzAlbum))
|
2014-02-07 22:40:03 +00:00
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2021-10-26 13:49:01 +00:00
|
|
|
public static string? GetMusicBrainzArtistId(this AlbumInfo info)
|
2014-02-07 22:40:03 +00:00
|
|
|
{
|
2021-10-26 13:49:01 +00:00
|
|
|
info.ProviderIds.TryGetValue(MetadataProvider.MusicBrainzAlbumArtist.ToString(), out string? id);
|
2014-02-07 22:40:03 +00:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
info.ArtistProviderIds.TryGetValue(MetadataProvider.MusicBrainzArtist.ToString(), out id);
|
2014-02-07 22:40:03 +00:00
|
|
|
}
|
2019-01-07 23:27:46 +00:00
|
|
|
|
2014-02-07 22:40:03 +00:00
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzAlbumArtist))
|
2014-02-07 22:40:03 +00:00
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2014-02-08 20:02:35 +00:00
|
|
|
|
2021-10-26 13:49:01 +00:00
|
|
|
public static string? GetMusicBrainzArtistId(this ArtistInfo info)
|
2014-02-08 20:02:35 +00:00
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
info.ProviderIds.TryGetValue(MetadataProvider.MusicBrainzArtist.ToString(), out var id);
|
2014-02-08 20:02:35 +00:00
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
{
|
2020-06-06 19:17:49 +00:00
|
|
|
return info.SongInfos.Select(i => i.GetProviderId(MetadataProvider.MusicBrainzAlbumArtist))
|
2014-02-08 20:02:35 +00:00
|
|
|
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2014-02-07 22:40:03 +00:00
|
|
|
}
|
|
|
|
}
|