private void AttachSoundtrackIds(BaseItemDto dto, MusicAlbum item, User user) { var tmdb = item.GetProviderId(MetadataProviders.Tmdb); var tvdb = item.GetProviderId(MetadataProviders.Tvdb); var gamesdb = item.GetProviderId(MetadataProviders.Gamesdb); if (string.IsNullOrEmpty(tmdb) && string.IsNullOrEmpty(tvdb) && string.IsNullOrEmpty(gamesdb)) { return; } var recursiveChildren = user == null ? _libraryManager.RootFolder.RecursiveChildren : user.RootFolder.GetRecursiveChildren(user); dto.SoundtrackIds = recursiveChildren .Where(i => { if (!string.IsNullOrEmpty(tmdb) && string.Equals(tmdb, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase) && i is Movie) { return true; } if (!string.IsNullOrEmpty(tvdb) && string.Equals(tvdb, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase) && i is Series) { return true; } if (!string.IsNullOrEmpty(gamesdb) && string.Equals(gamesdb, i.GetProviderId(MetadataProviders.Gamesdb), StringComparison.OrdinalIgnoreCase) && i is Game) { return true; } return false; }) .Select(GetClientItemId) .ToArray(); }
private async Task<LastfmGetAlbumResult> GetAlbumResult(MusicAlbum item, CancellationToken cancellationToken) { // Try album release Id if (!string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Musicbrainz))) { var result = await GetAlbumResult(item.GetProviderId(MetadataProviders.Musicbrainz), cancellationToken).ConfigureAwait(false); if (result != null && result.album != null) { return result; } } // Try album release group Id if (!string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup))) { var result = await GetAlbumResult(item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup), cancellationToken).ConfigureAwait(false); if (result != null && result.album != null) { return result; } } // Get each song, distinct by the combination of AlbumArtist and Album var songs = item.RecursiveChildren.OfType<Audio>().DistinctBy(i => (i.AlbumArtist ?? string.Empty) + (i.Album ?? string.Empty), StringComparer.OrdinalIgnoreCase).ToList(); foreach (var song in songs.Where(song => !string.IsNullOrEmpty(song.Album) && !string.IsNullOrEmpty(song.AlbumArtist))) { var result = await GetAlbumResult(song.AlbumArtist, song.Album, cancellationToken).ConfigureAwait(false); if (result != null && result.album != null) { return result; } } // Try the folder name return await GetAlbumResult(item.Parent.Name, item.Name, cancellationToken); }