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);
        }
        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);
        }
Example #3
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);
        }