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(); } }