adding status code check on http requests for error catching
This commit is contained in:
parent
73373a6565
commit
6ecf2ad982
@ -28,6 +28,7 @@ public class FmNetwork {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FmNetwork(String key, String userName) {
|
||||
this.key = key;
|
||||
this.userName = userName;
|
||||
@ -61,85 +62,97 @@ public class FmNetwork {
|
||||
|
||||
HttpResponse<JsonNode> response = request.asJson();
|
||||
|
||||
JSONObject obj = new JSONObject(response.getBody().toString());
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
String nameIn;
|
||||
String artistIn;
|
||||
JSONObject obj = new JSONObject(response.getBody().toString());
|
||||
|
||||
try {
|
||||
|
||||
JSONObject albumJson = obj.getJSONObject("album");
|
||||
|
||||
nameIn = albumJson.getString("name");
|
||||
artistIn = albumJson.getString("artist");
|
||||
|
||||
AlbumBuilder builder = new AlbumBuilder(nameIn, getArtist(artistIn));
|
||||
String nameIn;
|
||||
String artistIn;
|
||||
|
||||
try {
|
||||
builder.setMbid(albumJson.getString("mbid"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.setUrl(albumJson.getString("url"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
JSONObject albumJson = obj.getJSONObject("album");
|
||||
|
||||
try {
|
||||
builder.setListeners(albumJson.getInt("listeners"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
nameIn = albumJson.getString("name");
|
||||
artistIn = albumJson.getString("artist");
|
||||
|
||||
try {
|
||||
builder.setPlayCount(albumJson.getInt("playcount"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
AlbumBuilder builder = new AlbumBuilder(nameIn, getArtist(artistIn));
|
||||
|
||||
try {
|
||||
builder.setUserPlayCount(albumJson.getInt("userplaycount"));
|
||||
} catch (JSONException e) {
|
||||
try {
|
||||
builder.setMbid(albumJson.getString("mbid"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
builder.setUrl(albumJson.getString("url"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject wikiJson = albumJson.getJSONObject("wiki");
|
||||
try {
|
||||
builder.setListeners(albumJson.getInt("listeners"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
Wiki wiki = new Wiki(wikiJson.getString("published"), wikiJson.getString("summary"),
|
||||
wikiJson.getString("content"));
|
||||
try {
|
||||
builder.setPlayCount(albumJson.getInt("playcount"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
builder.setWiki(wiki);
|
||||
try {
|
||||
builder.setUserPlayCount(albumJson.getInt("userplaycount"));
|
||||
} catch (JSONException e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject wikiJson = albumJson.getJSONObject("wiki");
|
||||
|
||||
Wiki wiki = new Wiki(wikiJson.getString("published"), wikiJson.getString("summary"),
|
||||
wikiJson.getString("content"));
|
||||
|
||||
builder.setWiki(wiki);
|
||||
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
||||
ConsoleHandler.getConsole().write("ERROR: Album Name Not Found, " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
||||
System.err.println("ERROR: Album Name Not Found, " + e.getMessage());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
|
||||
} catch (JSONException e) {
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: Album Name Not Found, " + e.getMessage());
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR (getAlbum): " + name + " " + artist + " HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR: Album Name Not Found, " + e.getMessage());
|
||||
System.err.println("ERROR (getAlbum): " + name + " " + artist + " HTTP REQUEST ERROR");
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (UnirestException e) {
|
||||
@ -165,84 +178,96 @@ public class FmNetwork {
|
||||
|
||||
HttpResponse<JsonNode> response = request.asJson();
|
||||
|
||||
JSONObject obj = new JSONObject(response.getBody().toString());
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
String artistName;
|
||||
JSONObject obj = new JSONObject(response.getBody().toString());
|
||||
|
||||
try {
|
||||
|
||||
JSONObject artistJson = obj.getJSONObject("artist");
|
||||
|
||||
artistName = artistJson.getString("name");
|
||||
|
||||
ArtistBuilder builder = new ArtistBuilder(artistName);
|
||||
String artistName;
|
||||
|
||||
try {
|
||||
builder.setMbid(artistJson.getString("mbid"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No MBID for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No MBID for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.setUrl(artistJson.getString("url"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No Url for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No Url for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
JSONObject artistJson = obj.getJSONObject("artist");
|
||||
|
||||
try {
|
||||
builder.setListeners(artistJson.getJSONObject("stats").getInt("listeners"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No listeners for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No listeners for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
artistName = artistJson.getString("name");
|
||||
|
||||
try {
|
||||
builder.setPlayCount(artistJson.getJSONObject("stats").getInt("playcount"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No play count for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No play count for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
ArtistBuilder builder = new ArtistBuilder(artistName);
|
||||
|
||||
try {
|
||||
builder.setUserPlayCount(artistJson.getJSONObject("stats").getInt("userplaycount"));
|
||||
} catch (JSONException e) {
|
||||
try {
|
||||
builder.setMbid(artistJson.getString("mbid"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No MBID for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No MBID for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
builder.setUrl(artistJson.getString("url"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No Url for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No Url for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject wikiJson = artistJson.getJSONObject("bio");
|
||||
try {
|
||||
builder.setListeners(artistJson.getJSONObject("stats").getInt("listeners"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No listeners for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No listeners for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
Wiki wiki = new Wiki(wikiJson.getString("published"), wikiJson.getString("summary"),
|
||||
wikiJson.getString("content"));
|
||||
try {
|
||||
builder.setPlayCount(artistJson.getJSONObject("stats").getInt("playcount"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No play count for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No play count for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
builder.setWiki(wiki);
|
||||
try {
|
||||
builder.setUserPlayCount(artistJson.getJSONObject("stats").getInt("userplaycount"));
|
||||
} catch (JSONException e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject wikiJson = artistJson.getJSONObject("bio");
|
||||
|
||||
Wiki wiki = new Wiki(wikiJson.getString("published"), wikiJson.getString("summary"),
|
||||
wikiJson.getString("content"));
|
||||
|
||||
builder.setWiki(wiki);
|
||||
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No wiki for " + artistName + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No wiki for " + artistName + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No wiki for " + artistName + " , " + e.getMessage());
|
||||
ConsoleHandler.getConsole().write("ERROR: Arist Name Not Found, " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No wiki for " + artistName + " , " + e.getMessage());
|
||||
System.err.println("ERROR: Arist Name Not Found, " + e.getMessage());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
|
||||
} catch (JSONException e) {
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: Arist Name Not Found, " + e.getMessage());
|
||||
ConsoleHandler.getConsole().write("ERROR (getArtist): " + name + " HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR: Arist Name Not Found, " + e.getMessage());
|
||||
System.err.println("ERROR (getArtist): " + name + " HTTP REQUEST ERROR");
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (UnirestException e) {
|
||||
@ -269,85 +294,96 @@ public class FmNetwork {
|
||||
|
||||
HttpResponse<JsonNode> response = request.asJson();
|
||||
|
||||
JSONObject obj = new JSONObject(response.getBody().toString());
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
String nameIn;
|
||||
String artistIn;
|
||||
JSONObject obj = new JSONObject(response.getBody().toString());
|
||||
|
||||
try {
|
||||
|
||||
JSONObject trackJson = obj.getJSONObject("track");
|
||||
|
||||
nameIn = trackJson.getString("name");
|
||||
artistIn = trackJson.getJSONObject("artist").getString("name");
|
||||
|
||||
TrackBuilder builder = new TrackBuilder(nameIn, getArtist(artistIn));
|
||||
String nameIn;
|
||||
String artistIn;
|
||||
|
||||
try {
|
||||
builder.setMbid(trackJson.getString("mbid"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
builder.setUrl(trackJson.getString("url"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
JSONObject trackJson = obj.getJSONObject("track");
|
||||
|
||||
try {
|
||||
builder.setListeners(trackJson.getInt("listeners"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
nameIn = trackJson.getString("name");
|
||||
artistIn = trackJson.getJSONObject("artist").getString("name");
|
||||
|
||||
try {
|
||||
builder.setPlayCount(trackJson.getInt("playcount"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
TrackBuilder builder = new TrackBuilder(nameIn, getArtist(artistIn));
|
||||
|
||||
try {
|
||||
builder.setUserPlayCount(trackJson.getInt("userplaycount"));
|
||||
} catch (JSONException e) {
|
||||
try {
|
||||
builder.setMbid(trackJson.getString("mbid"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No MBID for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
builder.setUrl(trackJson.getString("url"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No Url for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject wikiJson = trackJson.getJSONObject("wiki");
|
||||
try {
|
||||
builder.setListeners(trackJson.getInt("listeners"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No listeners for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
Wiki wiki = new Wiki(wikiJson.getString("published"), wikiJson.getString("summary"),
|
||||
wikiJson.getString("content"));
|
||||
try {
|
||||
builder.setPlayCount(trackJson.getInt("playcount"));
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No play count for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
builder.setWiki(wiki);
|
||||
try {
|
||||
builder.setUserPlayCount(trackJson.getInt("userplaycount"));
|
||||
} catch (JSONException e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject wikiJson = trackJson.getJSONObject("wiki");
|
||||
|
||||
Wiki wiki = new Wiki(wikiJson.getString("published"), wikiJson.getString("summary"),
|
||||
wikiJson.getString("content"));
|
||||
|
||||
builder.setWiki(wiki);
|
||||
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
|
||||
} catch (JSONException e) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
||||
ConsoleHandler.getConsole().write("ERROR: Album Name Not Found, " + e.getMessage());
|
||||
else
|
||||
System.err.println("ERROR: No wiki for " + nameIn + " , " + e.getMessage());
|
||||
System.err.println("ERROR: Album Name Not Found, " + e.getMessage());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
|
||||
} catch (JSONException e) {
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR: Album Name Not Found, " + e.getMessage());
|
||||
ConsoleHandler.getConsole().write("ERROR (getTrack): " + name + " " + artist + " HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR: Album Name Not Found, " + e.getMessage());
|
||||
System.err.println("ERROR (getTrack): " + name + " " + artist + " HTTP REQUEST ERROR");
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (UnirestException e) {
|
||||
@ -383,9 +419,12 @@ public class FmNetwork {
|
||||
}
|
||||
|
||||
public FMObj refresh(FMObj obj) {
|
||||
if(obj.getClass() == Track.class) return refresh((Track)obj);
|
||||
if(obj.getClass() == Album.class) return refresh((Album)obj);
|
||||
if(obj.getClass() == Artist.class) return refresh((Artist)obj);
|
||||
if (obj.getClass() == Track.class)
|
||||
return refresh((Track) obj);
|
||||
if (obj.getClass() == Album.class)
|
||||
return refresh((Album) obj);
|
||||
if (obj.getClass() == Artist.class)
|
||||
return refresh((Artist) obj);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,13 @@ import sarsoo.fmframework.util.FMObjList;
|
||||
public class FmUserNetwork extends FmNetwork {
|
||||
|
||||
public enum TaggingType {
|
||||
ARTIST, ALBUM, TRACK
|
||||
ARTIST, ALBUM, TRACK
|
||||
}
|
||||
|
||||
public FmUserNetwork(String key, String userName) {
|
||||
super(key, userName);
|
||||
// super(key, userName);
|
||||
super(key);
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
@ -38,11 +40,21 @@ public class FmUserNetwork extends FmNetwork {
|
||||
.queryString("method", "user.getinfo").queryString("user", userName).queryString("api_key", key)
|
||||
.queryString("format", "json").asJson();
|
||||
|
||||
JSONObject obj = new JSONObject(response.getBody().toString()).getJSONObject("user");
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
return new User(obj.getString("name"), obj.getString("realname"), obj.getString("url"),
|
||||
obj.getString("country"), obj.getInt("age"), obj.getString("gender").charAt(0),
|
||||
obj.getInt("playcount"));
|
||||
JSONObject obj = new JSONObject(response.getBody().toString()).getJSONObject("user");
|
||||
|
||||
return new User(obj.getString("name"), obj.getString("realname"), obj.getString("url"),
|
||||
obj.getString("country"), obj.getInt("age"), obj.getString("gender").charAt(0),
|
||||
obj.getInt("playcount"));
|
||||
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR (getUser): HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR (getUser): HTTP REQUEST ERROR");
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
@ -75,16 +87,26 @@ public class FmUserNetwork extends FmNetwork {
|
||||
.queryString("method", "user.getrecenttracks").queryString("user", userName)
|
||||
.queryString("api_key", key).queryString("format", "json").queryString("limit", "1").asJson();
|
||||
|
||||
JSONArray obj = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks")
|
||||
.getJSONArray("track");
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
JSONObject track = (JSONObject) obj.get(0);
|
||||
JSONArray obj = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks")
|
||||
.getJSONArray("track");
|
||||
|
||||
Track trackObj = getTrack(track.getString("name"), track.getJSONObject("artist").getString("#text"));
|
||||
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"),
|
||||
track.getJSONObject("artist").getString("#text")));
|
||||
JSONObject track = (JSONObject) obj.get(0);
|
||||
|
||||
return trackObj;
|
||||
Track trackObj = getTrack(track.getString("name"), track.getJSONObject("artist").getString("#text"));
|
||||
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"),
|
||||
track.getJSONObject("artist").getString("#text")));
|
||||
|
||||
return trackObj;
|
||||
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR (getLastTrack): HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR (getLastTrack): HTTP REQUEST ERROR");
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
@ -103,20 +125,26 @@ public class FmUserNetwork extends FmNetwork {
|
||||
long epoch = local.atStartOfDay(zoneId).toEpochSecond();
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.getrecenttracks").
|
||||
queryString("user", userName).
|
||||
queryString("from", epoch).
|
||||
queryString("limit", 1).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/")
|
||||
.header("Accept", "application/json").header("User-Agent", "fmframework")
|
||||
.queryString("method", "user.getrecenttracks").queryString("user", userName)
|
||||
.queryString("from", epoch).queryString("limit", 1).queryString("api_key", key)
|
||||
.queryString("format", "json").asJson();
|
||||
|
||||
int total = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks").getJSONObject("@attr").getInt("total");
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
return total;
|
||||
int total = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks")
|
||||
.getJSONObject("@attr").getInt("total");
|
||||
|
||||
return total;
|
||||
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR (getScrobblesToday): HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR (getScrobblesToday): HTTP REQUEST ERROR");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
@ -133,24 +161,31 @@ public class FmUserNetwork extends FmNetwork {
|
||||
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
long epoch = startDate.atStartOfDay(zoneId).toEpochSecond();
|
||||
long endEpoch = epoch + (24*60*60);
|
||||
long endEpoch = epoch + (24 * 60 * 60);
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.getrecenttracks").
|
||||
queryString("user", userName).
|
||||
queryString("from", epoch).
|
||||
queryString("to", endEpoch).
|
||||
queryString("limit", 1).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/")
|
||||
.header("Accept", "application/json").header("User-Agent", "fmframework")
|
||||
.queryString("method", "user.getrecenttracks").queryString("user", userName)
|
||||
.queryString("from", epoch).queryString("to", endEpoch).queryString("limit", 1)
|
||||
.queryString("api_key", key).queryString("format", "json").asJson();
|
||||
|
||||
int total = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks").getJSONObject("@attr").getInt("total");
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
return total;
|
||||
int total = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks")
|
||||
.getJSONObject("@attr").getInt("total");
|
||||
|
||||
return total;
|
||||
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR (getScrobbleCountByDate): " + day + " " + month + " "
|
||||
+ year + " HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR (getScrobbleCountByDate): " + day + " " + month + " " + year
|
||||
+ " HTTP REQUEST ERROR");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
@ -167,25 +202,31 @@ public class FmUserNetwork extends FmNetwork {
|
||||
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
long epoch = local.atStartOfDay(zoneId).toEpochSecond();
|
||||
epoch -= (day * (24*60*60));
|
||||
long endEpoch = epoch + (24*60*60);
|
||||
epoch -= (day * (24 * 60 * 60));
|
||||
long endEpoch = epoch + (24 * 60 * 60);
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.getrecenttracks").
|
||||
queryString("user", userName).
|
||||
queryString("from", epoch).
|
||||
queryString("to", endEpoch).
|
||||
queryString("limit", 1).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/")
|
||||
.header("Accept", "application/json").header("User-Agent", "fmframework")
|
||||
.queryString("method", "user.getrecenttracks").queryString("user", userName)
|
||||
.queryString("from", epoch).queryString("to", endEpoch).queryString("limit", 1)
|
||||
.queryString("api_key", key).queryString("format", "json").asJson();
|
||||
|
||||
int total = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks").getJSONObject("@attr").getInt("total");
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
return total;
|
||||
int total = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks")
|
||||
.getJSONObject("@attr").getInt("total");
|
||||
|
||||
return total;
|
||||
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole()
|
||||
.write("ERROR (getScrobbleCountByDeltaDay): " + day + " HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR (getScrobbleCountByDeltaDay): " + day + " HTTP REQUEST ERROR");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
@ -194,39 +235,46 @@ public class FmUserNetwork extends FmNetwork {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ArrayList<Tag> getTags(){
|
||||
public ArrayList<Tag> getTags() {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>getTags");
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.gettoptags").
|
||||
queryString("user", userName).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/")
|
||||
.header("Accept", "application/json").header("User-Agent", "fmframework")
|
||||
.queryString("method", "user.gettoptags").queryString("user", userName).queryString("api_key", key)
|
||||
.queryString("format", "json").asJson();
|
||||
|
||||
JSONArray tagJsonArray = new JSONObject(response.getBody().toString()).getJSONObject("toptags").getJSONArray("tag");
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
JSONObject tagJson;
|
||||
JSONArray tagJsonArray = new JSONObject(response.getBody().toString()).getJSONObject("toptags")
|
||||
.getJSONArray("tag");
|
||||
|
||||
ArrayList<Tag> tags = new ArrayList<Tag>();
|
||||
JSONObject tagJson;
|
||||
|
||||
int counter;
|
||||
for(counter = 0; counter < tagJsonArray.length(); counter++) {
|
||||
ArrayList<Tag> tags = new ArrayList<Tag>();
|
||||
|
||||
tagJson = (JSONObject) tagJsonArray.get(counter);
|
||||
int counter;
|
||||
for (counter = 0; counter < tagJsonArray.length(); counter++) {
|
||||
|
||||
Tag tag = new Tag(tagJson.getString("name"), tagJson.getString("url"), tagJson.getInt("count"));
|
||||
tagJson = (JSONObject) tagJsonArray.get(counter);
|
||||
|
||||
tags.add(tag);
|
||||
Tag tag = new Tag(tagJson.getString("name"), tagJson.getString("url"), tagJson.getInt("count"));
|
||||
|
||||
tags.add(tag);
|
||||
|
||||
}
|
||||
|
||||
return tags;
|
||||
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write("ERROR (getTags): HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR (getTags): HTTP REQUEST ERROR");
|
||||
return null;
|
||||
}
|
||||
|
||||
return tags;
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -240,42 +288,47 @@ public class FmUserNetwork extends FmNetwork {
|
||||
ConsoleHandler.getConsole().write(">>getTag: " + tagName);
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.getpersonaltags").
|
||||
queryString("user", userName).
|
||||
queryString("tag", tagName).
|
||||
queryString("taggingtype", "artist").
|
||||
queryString("limit", 70).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/")
|
||||
.header("Accept", "application/json").header("User-Agent", "fmframework")
|
||||
.queryString("method", "user.getpersonaltags").queryString("user", userName)
|
||||
.queryString("tag", tagName).queryString("taggingtype", "artist").queryString("limit", 70)
|
||||
.queryString("api_key", key).queryString("format", "json").asJson();
|
||||
|
||||
JSONArray tagJsonArray = new JSONObject(response.getBody().toString()).getJSONObject("taggings").getJSONObject("artists").getJSONArray("artist");
|
||||
if (response.getStatus() == 200) {
|
||||
|
||||
JSONObject artistJson;
|
||||
JSONArray tagJsonArray = new JSONObject(response.getBody().toString()).getJSONObject("taggings")
|
||||
.getJSONObject("artists").getJSONArray("artist");
|
||||
|
||||
FMObjList list = new FMObjList();
|
||||
JSONObject artistJson;
|
||||
|
||||
list.setGroupName(tagName);
|
||||
FMObjList list = new FMObjList();
|
||||
|
||||
int counter;
|
||||
for(counter = 0; counter < tagJsonArray.length(); counter++) {
|
||||
list.setGroupName(tagName);
|
||||
|
||||
artistJson = (JSONObject) tagJsonArray.get(counter);
|
||||
int counter;
|
||||
for (counter = 0; counter < tagJsonArray.length(); counter++) {
|
||||
|
||||
Artist artist = getArtist(artistJson.getString("name"));
|
||||
artistJson = (JSONObject) tagJsonArray.get(counter);
|
||||
|
||||
Artist artist = getArtist(artistJson.getString("name"));
|
||||
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">Tag: " + tagName + ", " + artist.getName());
|
||||
|
||||
list.add(artist);
|
||||
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
} else {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">Tag: " + tagName + ", " + artist.getName());
|
||||
|
||||
list.add(artist);
|
||||
|
||||
ConsoleHandler.getConsole().write("ERROR (getTag): " + tagName + " HTTP REQUEST ERROR");
|
||||
else
|
||||
System.err.println("ERROR (getTag): " + tagName + " HTTP REQUEST ERROR");
|
||||
return null;
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user