initial implementation of artist info

This commit is contained in:
aj 2019-05-01 16:22:17 +01:00
parent ade7211ea8
commit 69627ffe96

View File

@ -175,20 +175,28 @@ public class FmNetwork {
if (ConsoleHandler.isVerbose()) if (ConsoleHandler.isVerbose())
ConsoleHandler.getConsole().write(">>getArtist: " + name); ConsoleHandler.getConsole().write(">>getArtist: " + name);
HttpRequest request; //HttpRequest request;
try { // try {
request = Unirest.get("http://ws.audioscrobbler.com/2.0/").header("Accept", "application/json") // request = Unirest.get("http://ws.audioscrobbler.com/2.0/").header("Accept", "application/json")
.header("User-Agent", "fmframework").queryString("method", "artist.getinfo") // .header("User-Agent", "fmframework").queryString("method", "artist.getinfo")
.queryString("artist", name).queryString("api_key", key).queryString("format", "json"); // .queryString("artist", name).queryString("api_key", key).queryString("format", "json");
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("artist", name);
if (userName != null) if (userName != null)
request.queryString("username", userName); parameters.put("username", userName);
//request.queryString("username", userName);
HttpResponse<JsonNode> response = request.asJson(); // HttpResponse<JsonNode> response = request.asJson();
if (response.getStatus() == 200) { if (true) {
// if (response.getStatus() == 200) {
JSONObject obj = new JSONObject(response.getBody().toString()); // JSONObject obj = new JSONObject(response.getBody().toString());
JSONObject obj = makeGetRequest("artist.getinfo", parameters);
String artistName; String artistName;
@ -278,9 +286,10 @@ public class FmNetwork {
return null; return null;
} }
} catch (UnirestException e) { // }
e.printStackTrace(); // catch (UnirestException e) {
} // e.printStackTrace();
// }
return null; return null;
@ -477,6 +486,7 @@ public class FmNetwork {
for (String key : parameters.keySet()) { for (String key : parameters.keySet()) {
request = request.queryString(key, parameters.get(key)); request = request.queryString(key, parameters.get(key));
System.out.println(key + " " + parameters.get(key));
} }
HttpResponse<JsonNode> response = request.asJson(); HttpResponse<JsonNode> response = request.asJson();