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