jellyfin/MediaBrowser.Providers/Music/Extensions.cs

82 lines
2.6 KiB
C#
Raw Normal View History

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