public async Task <List <Artist> > GetSimilarArtists(string artistName) { try { var lastFmClient = new HttpClient(); var response = await lastFmClient.GetStringAsync(new Uri(string.Format("http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&format=json&limit=8&api_key={0}&artist={1}", MusicMDFetcher.ApiKeyLastFm, artistName))); var artists = JsonConvert.DeserializeObject <SimilarArtistInformation>(response); if (artists == null || artists.Similarartists == null || !artists.Similarartists.Artist.Any()) { return(null); } var similarArtists = artists.Similarartists.Artist; var artistList = new List <Artist>(); foreach (var similarArtist in similarArtists) { var artist = new Artist(); artist.MapFrom(similarArtist); artistList.Add(artist); } return(artistList); } catch { Debug.WriteLine("Error getting similar artists from this artist."); } return(null); }
public async Task <List <Artist> > GetSimilarArtists(string artistId) { try { var deezerClient = new HttpClient(); string json = await deezerClient.GetStringAsync(new Uri(string.Format("http://api.deezer.com/artist/{0}/related?appid={1}", artistId, MusicMDFetcher.DeezerAppId))); var deezerArtists = JsonConvert.DeserializeObject <Artists>(json); var artistList = new List <Artist>(); if (deezerArtists.Data != null) { foreach (var deezerArtist in deezerArtists.Data) { var artist = new Artist(); artist.MapFrom(deezerArtist); artistList.Add(artist); } } return(artistList); } catch (Exception e) { Debug.WriteLine("DeezerClient.GetSimilarArtists", e); } return(null); }
public async Task <Artist> GetArtistInfo(string artistName) { try { var deezerClient = new HttpClient(); string json = await deezerClient.GetStringAsync(new Uri(string.Format("http://api.deezer.com/search/artist?q={0}&appid={1}", System.Net.WebUtility.HtmlEncode(artistName), MusicMDFetcher.DeezerAppId))); // TODO: See if this is even needed. It should just map an empty object. if (json == "{\"data\":[],\"total\":0}") { return(null); } var deezerArtists = JsonConvert.DeserializeObject <Artists>(json); if (deezerArtists.Data != null && deezerArtists.Total > 0) { var deezerArtist = deezerArtists.Data.FirstOrDefault(); var artist = new Artist(); artist.MapFrom(deezerArtist); return(artist); } } catch (Exception e) { Debug.WriteLine("DeezerClient.GetArtistInfo", e); } return(null); }
public async Task <Artist> GetArtistInfo(string artistName) { try { var lastFmClient = new HttpClient(); // Get users language/region // If their region is not support by LastFM, it won't return an artist biography. var region = new Windows.Globalization.GeographicRegion(); string regionCode = "en"; // LastFM does not take in normal windows region codes as valid language values. // We must set them ourselves. switch (Windows.System.UserProfile.GlobalizationPreferences.Languages.First()) { case "en-US": regionCode = "en"; break; case "ja": regionCode = "ja"; break; } string url = string.Format("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist={1}&api_key={0}&lang={2}&format=json", MusicMDFetcher.ApiKeyLastFm, artistName, regionCode); var reponse = await lastFmClient.GetStringAsync(new Uri(url)); { var artistInfo = JsonConvert.DeserializeObject <ArtistInformation>(reponse); if (artistInfo == null) { return(null); } if (artistInfo.Artist == null) { return(null); } var artist = new Artist(); artist.MapFrom(artistInfo); return(artist); } } catch (Exception exception) { Debug.WriteLine("Failed to get artist biography from LastFM. Returning nothing." + exception.ToString()); } return(null); }
public async Task <List <Artist> > GetTopArtistsGenre(string genre) { var lastFmClient = new HttpClient(); var response = await lastFmClient.GetStringAsync( new Uri( string.Format( "http://ws.audioscrobbler.com/2.0/?method=tag.gettopartists&tag={1}&api_key={0}&format=json", MusicMDFetcher.ApiKeyLastFm, genre))); var topartists = JsonConvert.DeserializeObject <TopArtistInformation>(response); var artistList = new List <Artist>(); foreach (var topArtistArtist in topartists.topartists.artist) { var artist = new Artist(); artist.Name = topArtistArtist.name; artistList.Add(artist); } return(artistList); }