streamlining for reduced api calls
This commit is contained in:
parent
b56bfec0b7
commit
191b38524a
@ -39,6 +39,10 @@ public class FmNetwork {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public Album getAlbum(String name, String artist) {
|
||||
return getAlbum(name, getArtist(artist));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an album from Last.FM
|
||||
*
|
||||
@ -46,15 +50,15 @@ public class FmNetwork {
|
||||
* @param artist Artist Name
|
||||
* @return Album
|
||||
*/
|
||||
public Album getAlbum(String name, String artist) {
|
||||
public Album getAlbum(String name, Artist artist) {
|
||||
|
||||
Log log = Logger.getLog();
|
||||
log.log(new LogEntry("getAlbum").addArg(name).addArg(artist));
|
||||
log.log(new LogEntry("getAlbum").addArg(name).addArg(artist.getName()));
|
||||
|
||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||
|
||||
parameters.put("album", name);
|
||||
parameters.put("artist", artist);
|
||||
parameters.put("artist", artist.getName());
|
||||
|
||||
if (userName != null)
|
||||
parameters.put("username", userName);
|
||||
@ -62,16 +66,14 @@ public class FmNetwork {
|
||||
JSONObject obj = makeGetRequest("album.getinfo", parameters);
|
||||
|
||||
String nameIn;
|
||||
String artistIn;
|
||||
|
||||
try {
|
||||
|
||||
JSONObject albumJson = obj.getJSONObject("album");
|
||||
|
||||
nameIn = albumJson.getString("name");
|
||||
artistIn = albumJson.getString("artist");
|
||||
|
||||
AlbumBuilder builder = new AlbumBuilder(nameIn, getArtist(artistIn));
|
||||
AlbumBuilder builder = new AlbumBuilder(nameIn, artist);
|
||||
|
||||
try {
|
||||
builder.setMbid(albumJson.getString("mbid"));
|
||||
@ -212,6 +214,10 @@ public class FmNetwork {
|
||||
|
||||
}
|
||||
|
||||
public Track getTrack(String name, String artist) {
|
||||
return getTrack(name, getArtist(artist));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a track from Last.FM
|
||||
*
|
||||
@ -219,14 +225,14 @@ public class FmNetwork {
|
||||
* @param artist Artist Name
|
||||
* @return Track
|
||||
*/
|
||||
public Track getTrack(String name, String artist) {
|
||||
public Track getTrack(String name, Artist artist) {
|
||||
|
||||
Log log = Logger.getLog();
|
||||
log.log(new LogEntry("getTrack").addArg(name).addArg(artist));
|
||||
log.log(new LogEntry("getTrack").addArg(name).addArg(artist.getName()));
|
||||
|
||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||
|
||||
parameters.put("artist", artist);
|
||||
parameters.put("artist", artist.getName());
|
||||
parameters.put("track", name);
|
||||
|
||||
if (userName != null)
|
||||
@ -235,16 +241,14 @@ public class FmNetwork {
|
||||
JSONObject obj = makeGetRequest("track.getinfo", parameters);
|
||||
|
||||
String nameIn;
|
||||
String artistIn;
|
||||
|
||||
try {
|
||||
|
||||
JSONObject trackJson = obj.getJSONObject("track");
|
||||
|
||||
nameIn = trackJson.getString("name");
|
||||
artistIn = trackJson.getJSONObject("artist").getString("name");
|
||||
|
||||
TrackBuilder builder = new TrackBuilder(nameIn, getArtist(artistIn));
|
||||
TrackBuilder builder = new TrackBuilder(nameIn, artist);
|
||||
|
||||
try {
|
||||
builder.setMbid(trackJson.getString("mbid"));
|
||||
@ -335,9 +339,11 @@ public class FmNetwork {
|
||||
|
||||
Logger.getLog().log(new LogEntry("refreshTrack").addArg(track.getName()).addArg(track.getArtist().getName()));
|
||||
|
||||
Track refreshedTrack = getTrack(track.getName(), track.getArtist().getName());
|
||||
Artist refreshedArtist = getArtist(track.getArtist().getName());
|
||||
|
||||
refreshedTrack.setAlbum(refresh(track.getAlbum()));
|
||||
Track refreshedTrack = getTrack(track.getName(), refreshedArtist);
|
||||
|
||||
refreshedTrack.setAlbum(getAlbum(track.getAlbum().getName(), refreshedArtist));
|
||||
|
||||
return refreshedTrack;
|
||||
}
|
||||
|
@ -128,9 +128,11 @@ public class FmUserNetwork extends FmNetwork {
|
||||
|
||||
JSONObject track = (JSONObject) obj.get(0);
|
||||
|
||||
Track trackObj = getTrack(track.getString("name"), track.getJSONObject("artist").getString("#text"));
|
||||
Artist artistObj = getArtist(track.getJSONObject("artist").getString("#text"));
|
||||
|
||||
Track trackObj = getTrack(track.getString("name"), artistObj);
|
||||
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"),
|
||||
track.getJSONObject("artist").getString("#text")));
|
||||
artistObj));
|
||||
|
||||
return trackObj;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user