Example #1
0
        /// <summary>
        /// Get Track by MusicBrainz ID (Avoid using this)
        /// </summary>
        /// <param name="mbid">MusicBrainz ID</param>
        /// <returns></returns>
        public async Task <LastFmTrack> GetTrackByMbid(string mbid)
        {
            string args = string.Format("?method=track.getInfo&mbid={0}&{1}&format=json", mbid, _credentials);
            Uri    url  = new Uri(Domain + args);

            HttpClient webClient = new HttpClient();

            string jsonSource = await webClient.GetStringAsync(url);

            JObject json = JObject.Parse(jsonSource);
            JToken  temp;

            if (json.TryGetValue("error", out temp))
            {
                LastFmApiExceptionArgs arg = new LastFmApiExceptionArgs(temp.ToObject <int>(),
                                                                        json.GetValue("message").ToString());
                throw new LastFmApiException(arg);
            }

            LastFmTrack album = LastFmTrack.Parse(json);

            return(album);
        }
Example #2
0
        public async Task <IList <LastFmSearchTrackResult> > SearchTrack(string trackTitle, string trackArtist)
        {
            string args = $"?method=track.search&track={trackTitle}&artist={trackArtist}&{_credentials}&format=json";
            Uri    url  = new Uri(Domain + args);

            HttpClient webClient = new HttpClient();

            string jsonSource = await webClient.GetStringAsync(url);

            JObject json = JObject.Parse(jsonSource);
            JToken  temp;

            if (json.TryGetValue("error", out temp))
            {
                LastFmApiExceptionArgs arg = new LastFmApiExceptionArgs(temp.ToObject <int>(),
                                                                        json.GetValue("message").ToString());
                throw new LastFmApiException(arg);
            }

            var resuts = ParseSearchTrackResults(json);

            return(resuts);
        }
Example #3
0
 public LastFmApiException(LastFmApiExceptionArgs args)
     : base(args.Message)
 {
     Args = args;
 }