| | | 1 | | #pragma warning disable CS1591 |
| | | 2 | | |
| | | 3 | | using System.Linq; |
| | | 4 | | using MediaBrowser.Controller.Providers; |
| | | 5 | | using MediaBrowser.Model.Entities; |
| | | 6 | | |
| | | 7 | | namespace MediaBrowser.Providers.Music |
| | | 8 | | { |
| | | 9 | | public static class AlbumInfoExtensions |
| | | 10 | | { |
| | | 11 | | public static string? GetAlbumArtist(this AlbumInfo info) |
| | | 12 | | { |
| | 0 | 13 | | var id = info.SongInfos.SelectMany(i => i.AlbumArtists) |
| | 0 | 14 | | .FirstOrDefault(i => !string.IsNullOrEmpty(i)); |
| | | 15 | | |
| | 0 | 16 | | if (!string.IsNullOrEmpty(id)) |
| | | 17 | | { |
| | 0 | 18 | | return id; |
| | | 19 | | } |
| | | 20 | | |
| | 0 | 21 | | return info.AlbumArtists.Count > 0 ? info.AlbumArtists[0] : default; |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | public static string? GetReleaseGroupId(this AlbumInfo info) |
| | | 25 | | { |
| | 0 | 26 | | var id = MusicBrainzId(MetadataProvider.MusicBrainzReleaseGroup, info.GetProviderId(MetadataProvider.MusicBr |
| | | 27 | | |
| | 0 | 28 | | if (string.IsNullOrEmpty(id)) |
| | | 29 | | { |
| | 0 | 30 | | return info.SongInfos.Select(i => MusicBrainzId(MetadataProvider.MusicBrainzReleaseGroup, i.GetProviderI |
| | 0 | 31 | | .FirstOrDefault(i => !string.IsNullOrEmpty(i)); |
| | | 32 | | } |
| | | 33 | | |
| | 0 | 34 | | return id; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public static string? GetReleaseId(this AlbumInfo info) |
| | | 38 | | { |
| | 4 | 39 | | var id = MusicBrainzId(MetadataProvider.MusicBrainzAlbum, info.GetProviderId(MetadataProvider.MusicBrainzAlb |
| | | 40 | | |
| | 4 | 41 | | if (string.IsNullOrEmpty(id)) |
| | | 42 | | { |
| | 3 | 43 | | return info.SongInfos.Select(i => MusicBrainzId(MetadataProvider.MusicBrainzAlbum, i.GetProviderId(Metad |
| | 3 | 44 | | .FirstOrDefault(i => !string.IsNullOrEmpty(i)); |
| | | 45 | | } |
| | | 46 | | |
| | 1 | 47 | | return id; |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public static string? GetMusicBrainzArtistId(this AlbumInfo info) |
| | | 51 | | { |
| | 1 | 52 | | info.ProviderIds.TryGetValue(MetadataProvider.MusicBrainzAlbumArtist.ToString(), out string? id); |
| | 1 | 53 | | id = MusicBrainzId(MetadataProvider.MusicBrainzAlbumArtist, id); |
| | | 54 | | |
| | 1 | 55 | | if (string.IsNullOrEmpty(id)) |
| | | 56 | | { |
| | 1 | 57 | | info.ArtistProviderIds.TryGetValue(MetadataProvider.MusicBrainzArtist.ToString(), out id); |
| | 1 | 58 | | id = MusicBrainzId(MetadataProvider.MusicBrainzArtist, id); |
| | | 59 | | } |
| | | 60 | | |
| | 1 | 61 | | if (string.IsNullOrEmpty(id)) |
| | | 62 | | { |
| | 0 | 63 | | return info.SongInfos.Select(i => MusicBrainzId(MetadataProvider.MusicBrainzAlbumArtist, i.GetProviderId |
| | 0 | 64 | | .FirstOrDefault(i => !string.IsNullOrEmpty(i)); |
| | | 65 | | } |
| | | 66 | | |
| | 1 | 67 | | return id; |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | public static string? GetMusicBrainzArtistId(this ArtistInfo info) |
| | | 71 | | { |
| | 2 | 72 | | info.ProviderIds.TryGetValue(MetadataProvider.MusicBrainzArtist.ToString(), out var id); |
| | 2 | 73 | | id = MusicBrainzId(MetadataProvider.MusicBrainzArtist, id); |
| | | 74 | | |
| | 2 | 75 | | if (string.IsNullOrEmpty(id)) |
| | | 76 | | { |
| | 1 | 77 | | return info.SongInfos.Select(i => MusicBrainzId(MetadataProvider.MusicBrainzAlbumArtist, i.GetProviderId |
| | 1 | 78 | | .FirstOrDefault(i => !string.IsNullOrEmpty(i)); |
| | | 79 | | } |
| | | 80 | | |
| | 1 | 81 | | return id; |
| | | 82 | | } |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Returns the id if it can be an id of the given provider, otherwise <c>null</c>. |
| | | 86 | | /// </summary> |
| | | 87 | | private static string? MusicBrainzId(MetadataProvider provider, string? id) |
| | 9 | 88 | | => ProviderIdsExtensions.IsValidProviderId(provider.ToString(), id) ? id : null; |
| | | 89 | | } |
| | | 90 | | } |