Пример #1
0
        public static async System.Threading.Tasks.Task <AlbumArtObject> GetAlbumArtObjects(string MBID)
        {
            AlbumArtObject Result     = null;
            Uri            restAPIUri = null;

            restAPIUri = new Uri("http://coverartarchive.org/release/" + MBID);
            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 <AlbumArtObject>(s);
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception " + e.Message);
            }

            return(Result);
        }
Пример #2
0
        public async System.Threading.Tasks.Task <string> GetAlbumArtUrl(string MBID)
        {
            string result = string.Empty;

            try
            {
                AlbumArtObject albumArt = await GetAlbumArtObjects(MBID);

                if (albumArt != null)
                {
                    if ((albumArt.images != null) &&
                        (albumArt.images.Count >= 1))
                    {
                        if (albumArt.images[0].approved == true)
                        {
                            if (albumArt.images[0].thumbnails != null)
                            {
                                if (!string.IsNullOrEmpty(albumArt.images[0].thumbnails.large))
                                {
                                    result = albumArt.images[0].thumbnails.large;
                                }
                                else if (!string.IsNullOrEmpty(albumArt.images[0].thumbnails.small))
                                {
                                    result = albumArt.images[0].thumbnails.small;
                                }
                                else if (!string.IsNullOrEmpty(albumArt.images[0].image))
                                {
                                    result = albumArt.images[0].image;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception while getting album art url: " + ex.Message);
                result = string.Empty;
            }
            return(result);
        }