public static async Task <Uri> GetArtistImage(string artist, bool big) { if (string.IsNullOrEmpty(artist)) { return(null); } if (artist.Contains(", ") || artist.Contains(" feat ", StringComparison.OrdinalIgnoreCase) || artist.Contains(" ft. ", StringComparison.OrdinalIgnoreCase)) { //if there are more then 1 artist, get first var artists = artist.Split(new[] { ", ", " feat. ", " feat ", " ft. " }, StringSplitOptions.RemoveEmptyEntries); if (artists.Length > 0) { artist = artists.First(); } } if (big) { try { var results = await _xboxMusic.Find(artist); if (results != null && results.Artists != null) { var resultArtist = results.Artists.Items.FirstOrDefault(); if (resultArtist != null && !string.IsNullOrEmpty(resultArtist.ImageUrl)) { var imageUrl = resultArtist.ImageUrl; var httpClient = new HttpClient(); var response = await httpClient.GetAsync(imageUrl, HttpCompletionOption.ResponseHeadersRead); if (response.IsSuccessStatusCode) { return(new Uri(resultArtist.ImageUrl)); } } } } catch (Exception) { Debug.WriteLine("Xbox Music: Artist " + artist + " not found."); } } var info = await _lastFm.Artist.GetInfo(null, artist); if (info == null || string.IsNullOrEmpty(big ? info.ImageMega : info.ImageExtraLarge)) { return(null); } return(new Uri(big ? info.ImageMega : info.ImageExtraLarge)); }
public async Task FindTest3() { var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften"); var result = await client.Find("caparezza non me lo posso promettere"); Assert.IsNotNull(result); Assert.IsNotNull(result.Error); Assert.IsNotNull(result.Error.Response); Assert.AreEqual("NotFound", result.Error.ErrorCode); }
public async Task FindTest2() { var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften"); var result = await client.Find("Daft Punk", getAlbums: false); Assert.IsNotNull(result); Assert.IsNull(result.Error); Assert.IsNotNull(result.Artists); Assert.IsNotNull(result.Tracks); Assert.IsNull(result.Albums); }
public async Task FindTest1Continued() { var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften"); var result = await client.Find("Daft Punk", _find1ContinuationToken); Assert.IsNotNull(result); Assert.IsNull(result.Error); Assert.IsNotNull(result.Albums); Assert.IsNull(result.Artists); Assert.IsNull(result.Tracks); }
public async Task FindTest2() { var client = new MusicClient("XboxMusicClientTests", "ThisWillBeChangedOften"); var result = await client.Find("Daft Punk", getAlbums : false); Assert.IsNotNull(result); Assert.IsNull(result.Error); Assert.IsNotNull(result.Artists); Assert.IsNotNull(result.Tracks); Assert.IsNull(result.Albums); }