/// <summary> /// Makes a requst to ConvertArchive to try and retrive the album art cover image /// </summary> /// <param name="path">Full path to the music file</param> /// <returns>Thumbnail image</returns> public Image GetAlbumArtworkFromCoverArtArchive(string pathOrMbid, bool isPath) { try { string mbid = isPath ? GetReleaseMbId(pathOrMbid, true).Result : pathOrMbid; if (!string.IsNullOrEmpty(mbid)) { var uri = CoverArtArchive.GetCoverArtUri(mbid); if (uri != null) { try { byte[] imageBytes = GetImageBytesFromUrl(uri.ToString()); if (imageBytes != null) { using (var ms = new MemoryStream(imageBytes)) return(ResizeBitmap(new Bitmap(ms))); } } catch { // There's no front cover } } } } catch { } return(null); }
private async Task LoadPlayLists(string mbid) { activityIndicator.IsRunning = true; PlayLists.Clear(); var response = await Artist.GetAsync(mbid, ArtistIncludeEntityHelper.Releases); var releases = response.ReleaseLists.Items.GroupBy(x => x.Title).Select(y => y.Last()); foreach (var release in releases) { release.CoverArtArchive = new CoverArtArchive(); release.CoverArtArchive.CoverArtUri = CoverArtArchive.GetCoverArtUri(release.Id).ToString(); PlayLists.Add(release); } activityIndicator.IsRunning = false; }
/// <summary> /// Tries to find an album corresponding to a particular track, artist and locale. /// </summary> /// <param name="track">The track or song that is contained on the album.</param> /// <param name="artist">The artist who released the album.</param> /// <param name="locale">The locale of the artist when they released the album.</param> /// <returns>AlbumData or null</returns> public async override Task <AlbumData> TryFindAlbumAsync(string track, string artist, string locale = "JP") { AlbumData data = new AlbumData(); var recordingQuery = new Hqub.MusicBrainz.API.QueryParameters <Hqub.MusicBrainz.API.Entities.Recording>(); recordingQuery.Add("artistname", artist); recordingQuery.Add("country", locale); recordingQuery.Add("recording", track); var recordings = await Recording.SearchAsync(recordingQuery); if (recordings?.QueryCount > 0) { foreach (var potentialRecording in recordings?.Items) { if (potentialRecording.Title.ToLower().StartsWith(track.ToLower()) || potentialRecording.Title.ToLower().Trim().FuzzyEquals(track.ToLower().Trim())) { var firstRelease = potentialRecording.Releases.Items.FirstOrDefault(); if (firstRelease != null) { //data.AlbumCoverUrl = CoverArtArchive.GetCoverArtUri(firstRelease.Id)?.ToString(); if (firstRelease.CoverArtArchive != null) { if (firstRelease.CoverArtArchive.Artwork) { string albumImg = CoverArtArchive.GetCoverArtUri(firstRelease.Id)?.ToString(); if (!string.IsNullOrWhiteSpace(albumImg)) { if (await CheckIfUrlIsWebAccessibleAsync(new Uri(albumImg))) { data.AlbumCoverUrl = albumImg; } } } } else { string albumImg = "http://coverartarchive.org/release/" + firstRelease?.Id + "/front-250.jpg"; if (!string.IsNullOrWhiteSpace(albumImg)) { if (await CheckIfUrlIsWebAccessibleAsync(new Uri(albumImg))) { data.AlbumCoverUrl = albumImg; } } } data.Artist = potentialRecording.Credits.First().Artist.Name; data.ArtistID = potentialRecording.Credits.First().Artist.Id; data.Album = firstRelease.Title; data.AlbumID = firstRelease.Id; data.AlbumLinkUrl = "https://musicbrainz.org/release/" + firstRelease.Id; if (!string.IsNullOrWhiteSpace(firstRelease.Date)) { try { data.ReleaseDate = DateTime.Parse(firstRelease.Date); } catch (FormatException) { } } return(data); } } } } return(null); }