public static async System.Threading.Tasks.Task <DiscIDObject> GetCDObjects(string discID) { DiscIDObject Result = null; Uri restAPIUri = null; restAPIUri = new Uri("https://musicbrainz.org/ws/2/discid/" + discID); string url = string.Empty; try { HttpClient hc = new HttpClient(); hc.DefaultRequestHeaders.TryAppendWithoutValidation("Accept", "application/json"); hc.DefaultRequestHeaders.TryAppendWithoutValidation("User-Agent", Information.SystemInformation.ApplicationName + "/" + Information.SystemInformation.ApplicationVersion); hc.DefaultRequestHeaders.Remove("Accept-Encoding"); HttpResponseMessage rep = await hc.GetAsync(restAPIUri); if ((rep != null) && (rep.StatusCode == HttpStatusCode.Ok) && (rep.Content != null)) { string s = rep.Content.ReadAsStringAsync().GetResults(); if (!string.IsNullOrEmpty(s)) { Result = ReadToObject <DiscIDObject>(s); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception " + e.Message); } return(Result); }
public async System.Threading.Tasks.Task <CDMetadata> FillCDWithOnlineMetadata(CDMetadata currentCD, string discid) { try { //Clear CD and Track metadata info: currentCD.ISrc = string.Empty; currentCD.Message = string.Empty; currentCD.Genre = string.Empty; currentCD.AlbumTitle = string.Empty; currentCD.Artist = string.Empty; currentCD.albumArtUrl = string.Empty; currentCD.DiscID = string.Empty; if (!string.IsNullOrEmpty(discid)) { char[] sep = { '?' }; string[] array = discid.Split(sep); if (array.Count() >= 1) { currentCD.DiscID = array[0]; DiscIDObject v = await GetCDObjects(discid); if (v != null) { if ((v.releases != null) && (v.releases.Count > 0)) { int Index = -1; for (int i = 0; i < v.releases.Count; i++) { if (IsCDFound(v.releases[i], currentCD.DiscID, true)) { Index = i; break; } if ((Index < 0) && (IsCDFound(v.releases[i], currentCD.DiscID, false))) { Index = i; } } if (Index >= 0) { // Found currentCD.AlbumTitle = v.releases[Index].title; if ((v.releases[Index].artistcredit != null) && (v.releases[Index].artistcredit.Count > 0)) { currentCD.Artist = v.releases[Index].artistcredit[0].name; } currentCD.albumArtUrl = await GetAlbumArtUrl(v.releases[Index].id); for (int j = 0; j < v.releases[Index].media.Count; j++) { if ((string.Equals(v.releases[Index].media[j].format, "CD", StringComparison.OrdinalIgnoreCase)) && (v.releases[Index].media[j].discs != null) && (v.releases[Index].media[j].discs.Count > 0)) { if ((v.releases[Index].media[j].tracks != null) && (v.releases[Index].media[j].tracks.Count == currentCD.Tracks.Count)) { for (int m = 0; m < v.releases[Index].media[j].tracks.Count; m++) { if (currentCD.Tracks[m].Number == v.releases[Index].media[j].tracks[m].position) { currentCD.Tracks[m].Artist = currentCD.Artist; currentCD.Tracks[m].Album = currentCD.AlbumTitle; currentCD.Tracks[m].Poster = currentCD.albumArtUrl; currentCD.Tracks[m].Title = v.releases[Index].media[j].tracks[m].title; } } break; } } } return(currentCD); } } } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception while getting online Medtadata: " + ex.Message); currentCD = null; } return(currentCD); }