Example #1
0
        public async Task <IEnumerable <LastFmArtist> > GetRecommendedArtists(int count = 0)
        {
            var parameters = new Dictionary <string, string>();

            if (count > 0)
            {
                parameters.Add("limit", count.ToString());
            }

            parameters.Add("api_key", _lastFm.ApiKey);
            parameters.Add("sk", _lastFm.SessionKey);
            parameters.Add("api_sig", LastFmUtils.BuildSig(_lastFm.ApiSecret, "user.getRecommendedArtists", parameters));

            var response = await new CoreRequest(new Uri(LastFmConst.UrlBase), parameters, "POST").Execute();

            LastFmErrorProcessor.ProcessError(response);


            if (response.SelectToken("recommendations.artist") != null)
            {
                return(from a in response.SelectToken("recommendations.artist") select LastFmArtist.FromJson(a));
            }

            return(null);
        }
Example #2
0
        public async Task <List <LastFmAlbum> > Search(string album, int limit = 0)
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add("album", album);
            if (limit > 0)
            {
                parameters.Add("limit", limit.ToString());
            }
            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "album.search"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);


            if (response.SelectToken("results.albummatches.album") != null)
            {
                var albumJson = response.SelectToken("results.albummatches.album");
                if (albumJson is JArray)
                {
                    return
                        ((from a in response.SelectToken("results.albummatches.album") select LastFmAlbum.FromJson(a)).ToList());
                }
                else
                {
                    return new List <LastFmAlbum>()
                           {
                               LastFmAlbum.FromJson(albumJson)
                           }
                };
            }

            return(null);
        }
Example #3
0
        public async Task <LastFmAlbum> GetInfo(string mbid, string album, string artist, bool autoCorrect = true)
        {
            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(mbid))
            {
                parameters.Add("mbid", mbid);
            }
            else
            {
                parameters.Add("album", album);
                parameters.Add("artist", artist);
            }

            if (autoCorrect)
            {
                parameters.Add("autocorrect", "1");
            }

            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "album.getInfo"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);


            if (response["album"] != null)
            {
                return(LastFmAlbum.FromJson(response["album"]));
            }

            return(null);
        }
        public async Task<LastFmTrack> GetInfo(string title, string artist, bool autoCorrect = true, string mbid = null)
        {
            var parameters = new Dictionary<string, string>();

            if (!string.IsNullOrEmpty(mbid))
                parameters.Add("mbid", mbid);
            else
            {
                parameters.Add("artist", artist);
                parameters.Add("track", title);
            }

            if (autoCorrect)
                parameters.Add("autocorrect", "1");

            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await new CoreRequest(new Uri(LastFmConst.MethodBase + "track.getInfo"), parameters).Execute();

            LastFmErrorProcessor.ProcessError(response);


            if (response["track"] != null)
            {
                return LastFmTrack.FromJson(response["track"]);
            }

            return null;
        }
        public async Task <IEnumerable <LastFmTrack> > GetTopTracks(string tag, int limit = 20, int page = 0)
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add("tag", tag);

            if (limit > 0)
            {
                parameters.Add("limit", limit.ToString());
            }

            if (page > 0)
            {
                parameters.Add("page", page.ToString());
            }

            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await new CoreRequest(new Uri(LastFmConst.MethodBase + "tag.getTopTracks"), parameters).Execute();

            LastFmErrorProcessor.ProcessError(response);


            if (response.SelectToken("tracks.track") != null)
            {
                return(from t in response.SelectToken("tracks.track") select LastFmTrack.FromJson(t));
            }

            return(null);
        }
        public async Task<List<LastFmTrack>> Search(string track, string artist)
        {
            var parameters = new Dictionary<string, string>();

            parameters.Add("track", track);
            if (!string.IsNullOrEmpty(artist))
                parameters.Add("artist", artist);

            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await new CoreRequest(new Uri(LastFmConst.MethodBase + "track.search"), parameters).Execute();

            LastFmErrorProcessor.ProcessError(response);

            if (response.SelectToken("results.trackmatches.track") != null)
            {
                var trackJson = response.SelectToken("results.trackmatches.track");
                if (trackJson is JArray)
                    return (from t in response.SelectToken("results.trackmatches.track")
                           select LastFmTrack.FromJson(t)).ToList();
                else
                    return new List<LastFmTrack>() { LastFmTrack.FromJson(trackJson) };
            }

            return null;
        }
        public async Task <LastFmArtist> GetInfo(string mbid, string artist)
        {
            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(mbid))
            {
                parameters.Add("mbid", mbid);
            }
            else
            {
                parameters.Add("artist", artist);
            }
            if (!string.IsNullOrEmpty(_lastFm.Lang))
            {
                parameters.Add("lang", _lastFm.Lang);
            }
            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "artist.getInfo"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);

            if (response["artist"] != null)
            {
                return(LastFmArtist.FromJson(response["artist"]));
            }

            return(null);
        }
        public async Task <List <LastFmArtist> > Search(string artist)
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add("artist", artist);
            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "artist.search"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);


            if (response.SelectToken("results.artistmatches.artist") != null)
            {
                var artistJson = response.SelectToken("results.artistmatches.artist");
                if (artistJson is JArray)
                {
                    return((from a in response.SelectToken("results.artistmatches.artist")
                            select LastFmArtist.FromJson(a)).ToList());
                }
                else
                {
                    return new List <LastFmArtist>()
                           {
                               LastFmArtist.FromJson(artistJson)
                           }
                };
            }

            return(null);
        }
        public async Task <List <LastFmImage> > GetImages(string artist, string mbid, int limit, bool autoCorrect = true, int minWidth = 500, int minHeight = 200)
        {
            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(mbid))
            {
                parameters.Add("mbid", mbid);
            }
            else
            {
                parameters.Add("artist", artist);
            }

            if (autoCorrect)
            {
                parameters.Add("autocorrect", "1");
            }

            if (limit > 0)
            {
                parameters.Add("limit", limit.ToString());
            }

            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "artist.getImages"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);

            if (response["images"] != null && response["images"]["image"] != null)
            {
                var ie = new List <LastFmImage>();
                foreach (var image in response["images"]["image"])
                {
                    ie.Add(LastFmImage.FromJson(image));
                }
                return(ie);
            }

            return(null);
        }
        public async Task <List <LastFmTrack> > GetTopTracks(string mbid, string artist, int count = 0)
        {
            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(mbid))
            {
                parameters.Add("mbid", mbid);
            }
            else
            {
                parameters.Add("artist", artist);
            }
            if (count > 0)
            {
                parameters.Add("limit", count.ToString());
            }
            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "artist.getTopTracks"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);


            if (response.SelectToken("toptracks.track") != null)
            {
                var tracksJson = response.SelectToken("toptracks.track");
                if (tracksJson is JArray)
                {
                    return((from a in tracksJson select LastFmTrack.FromJson(a)).ToList());
                }
                else
                {
                    return new List <LastFmTrack>()
                           {
                               LastFmTrack.FromJson(tracksJson)
                           }
                };
            }

            return(null);
        }
        public async Task <List <LastFmAlbum> > GetTopAlbums(string mbid, string artist, int count = 0)
        {
            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(mbid))
            {
                parameters.Add("mbid", mbid);
            }
            else
            {
                parameters.Add("artist", artist);
            }
            if (count > 0)
            {
                parameters.Add("limit", count.ToString());
            }
            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "artist.getTopAlbums"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);


            if (response.SelectToken("topalbums.album") != null)
            {
                var albumToken = response.SelectToken("topalbums.album");
                if (albumToken.GetType() == typeof(JArray))
                {
                    return((from a in albumToken select LastFmAlbum.FromJson(a)).ToList());
                }
                else if (albumToken.GetType() == typeof(JObject))
                {
                    var result = new List <LastFmAlbum>();
                    result.Add(LastFmAlbum.FromJson(albumToken));
                    return(result);
                }
            }

            return(null);
        }
        public async Task Scrobble(string artist, string track, string timeStamp, string mbid = null, int duration = 0,
                                   string album = null, int trackNumber = -1, string albumArtist = null)
        {

            const string method = "track.scrobble";

            var parameters = new Dictionary<string, string>();

            parameters.Add("artist", artist);
            parameters.Add("track", track);
            parameters.Add("timestamp", timeStamp);

            if (album != null)
                parameters.Add("album", album);

            if (trackNumber > -1)
                parameters.Add("trackNumber", trackNumber.ToString());

            if (mbid != null)
                parameters.Add("mbid", mbid);

            if (albumArtist != null)
                parameters.Add("albumArtist", albumArtist);

            if (duration > 0)
                parameters.Add("duration", duration.ToString());

            parameters.Add("api_key", _lastFm.ApiKey);
            parameters.Add("sk", _lastFm.SessionKey);
            parameters.Add("api_sig", LastFmUtils.BuildSig(_lastFm.ApiSecret, method, parameters));


            parameters["track"] = Uri.EscapeDataString(track); //fix ampersand scrobbling
            parameters["artist"] = Uri.EscapeDataString(artist); //fix ampersand scrobbling

            var response = await new CoreRequest(new Uri(LastFmConst.UrlBaseSecure), null, "POST", parameters).Execute();

            LastFmErrorProcessor.ProcessError(response);
        }
        public async Task <IEnumerable <LastFmTrack> > GetHypedTracks(int count = 0)
        {
            var parameters = new Dictionary <string, string>();

            if (count > 0)
            {
                parameters.Add("limit", count.ToString());
            }
            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "chart.getHypedTracks"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);


            if (response.SelectToken("tracks.track") != null)
            {
                return(from a in response.SelectToken("tracks.track") select LastFmTrack.FromJson(a));
            }

            return(null);
        }
        public async Task <List <LastFmArtist> > GetSimilar(string artist, int count = 0)
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add("artist", artist);
            if (count > 0)
            {
                parameters.Add("limit", count.ToString());
            }
            parameters.Add("api_key", _lastFm.ApiKey);

            var response = await(new CoreRequest(new Uri(LastFmConst.MethodBase + "artist.getSimilar"), parameters).Execute());

            LastFmErrorProcessor.ProcessError(response);


            if (response.SelectToken("similarartists.artist") != null)
            {
                return((from a in response.SelectToken("similarartists.artist") select LastFmArtist.FromJson(a)).ToList());
            }

            return(null);
        }
Example #15
0
        public async Task <LastFmAuthResult> GetMobileSession(string username, string password)
        {
            var parameters = new Dictionary <string, string>();

            parameters.Add("username", username);
            parameters.Add("password", password);

            parameters.Add("api_key", _lastFm.ApiKey);
            parameters.Add("api_sig", LastFmUtils.BuildSig(_lastFm.ApiSecret, "auth.getMobileSession", parameters));

            var response = await new CoreRequest(new Uri(LastFmConst.MethodBaseSecure + "auth.getMobileSession"), null, "POST", parameters).Execute();

            if (!LastFmErrorProcessor.ProcessError(response))
            {
                return(null);
            }

            if (response["session"] != null)
            {
                return(LastFmAuthResult.FromJson(response["session"]));
            }

            return(null);
        }