public void GetWithParams() { var expected = "http://ws.audioscrobbler.com/2.0/?method=someMethod&api_key=344e9141fffeb02201e1ae455d92ae9f&x=y&a=b&format=json"; var creator = new FakeWebRequestCreator (); var req = new LastfmRequest ("someMethod", RequestType.Read, ResponseFormat.Json, creator); req.AddParameter ("x", "y"); req.AddParameter ("a", "b"); req.Send (); UrisAreEquivalent (expected, creator.Uri.ToString ()); }
public void JsonPostWithParams() { var expected = "http://ws.audioscrobbler.com/2.0/?method=someMethod&api_key=344e9141fffeb02201e1ae455d92ae9f&x=y&a=b&format=json&sk=&api_sig=6b369269588df3d3b1ac67834d703c6d"; var creator = new FakeWebRequestCreator(); var req = new LastfmRequest("someMethod", RequestType.Write, ResponseFormat.Json, creator); req.AddParameter("x", "y"); req.AddParameter("a", "b"); req.Send(); UrisAreEquivalent(expected, creator.Uri.ToString()); }
public void JsonRawWithParams() { var expected = "http://ws.audioscrobbler.com/2.0/?method=someMethod&api_key=344e9141fffeb02201e1ae455d92ae9f&x=y&a=b&raw=true&sk=&api_sig=3b419688648ce7e124c0056aba9a6438"; var creator = new FakeWebRequestCreator(); var req = new LastfmRequest("someMethod", RequestType.Write, ResponseFormat.Raw, creator); req.AddParameter("x", "y"); req.AddParameter("a", "b"); req.Send(); UrisAreEquivalent(expected, creator.Uri.ToString()); }
void FetchMetadata(TrackInfo track, int fpid) { var request = new LastfmRequest("track.getFingerprintMetadata"); request.AddParameter("fingerprintid", fpid.ToString()); request.Send(); var response = request.GetResponseObject(); if (response == null) { return; } var json_tracks = (JsonObject)response["tracks"]; var obj_track = json_tracks["track"]; JsonObject json_track = null; if (obj_track is JsonArray) { json_track = (JsonObject)(((JsonArray)obj_track)[0]); } else if (obj_track is JsonObject) { json_track = (JsonObject)obj_track; } if (json_track != null) { track.TrackTitle = (string)json_track["name"]; track.MusicBrainzId = (string)json_track["mbid"]; track.MoreInfoUri = new SafeUri((string)json_track["url"]); var json_artist = (JsonObject)json_track["artist"]; if (json_artist != null) { track.ArtistName = (string)json_artist["name"]; track.ArtistMusicBrainzId = (string)json_artist["mbid"]; } GetMoreInfo(track); track.Update(); if (track == ServiceManager.PlayerEngine.CurrentTrack) { ServiceManager.PlayerEngine.TrackInfoUpdated(); } } }
void GetMoreInfo(TrackInfo track) { var request = new LastfmRequest("track.getInfo"); request.AddParameter("artist", track.ArtistName); request.AddParameter("track", track.TrackTitle); request.AddParameter("mbid", track.MusicBrainzId); request.Send(); var response = request.GetResponseObject(); if (response == null) { return; } try { var json_track = (JsonObject)response["track"]; //track.Duration = TimeSpan.FromMilliseconds (double.Parse ((string)json_track["duration"])); if (!json_track.ContainsKey("album")) { return; } var json_album = (JsonObject)json_track["album"]; if (json_album != null) { var attr = (JsonObject)json_album["@attr"]; int pos = 0; if (int.TryParse((string)attr["position"], out pos)) { track.TrackNumber = pos; } track.AlbumTitle = (string)json_album["title"]; track.AlbumMusicBrainzId = (string)json_album["mbid"]; track.AlbumArtist = (string)json_album["artist"]; } } catch (Exception e) { Log.DebugException(e); response.Dump(); } }
public void JsonRawWithParams() { var expected = "http://ws.audioscrobbler.com/2.0/?method=someMethod&api_key=344e9141fffeb02201e1ae455d92ae9f&x=y&a=b&raw=true&sk=&api_sig=3b419688648ce7e124c0056aba9a6438"; var creator = new FakeWebRequestCreator (); var req = new LastfmRequest ("someMethod", RequestType.Write, ResponseFormat.Raw, creator); req.AddParameter ("x", "y"); req.AddParameter ("a", "b"); req.Send (); UrisAreEquivalent (expected, creator.Uri.ToString ()); }