ready for cache implementations, started on get artist tracks
This commit is contained in:
parent
2bc9aff667
commit
fdac060b98
@ -1,4 +1,4 @@
|
||||
package sarsoo.fmframework.util.tagpool;
|
||||
package sarsoo.fmframework.cache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -7,7 +7,7 @@ import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class TagPool {
|
||||
public class TagPool{
|
||||
|
||||
private static TagPool instance;
|
||||
|
@ -132,8 +132,7 @@ public class FmUserNetwork extends FmNetwork {
|
||||
Artist artistObj = getArtist(track.getJSONObject("artist").getString("#text"));
|
||||
|
||||
Track trackObj = getTrack(track.getString("name"), artistObj);
|
||||
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"),
|
||||
artistObj));
|
||||
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"), artistObj));
|
||||
|
||||
return trackObj;
|
||||
|
||||
@ -233,6 +232,49 @@ public class FmUserNetwork extends FmNetwork {
|
||||
|
||||
}
|
||||
|
||||
public Artist getArtistTracks(String artistName) {
|
||||
return getArtistTracks(getArtist(artistName));
|
||||
}
|
||||
|
||||
public Artist getArtistTracks(Artist artist) {
|
||||
|
||||
Logger.getLog().log(new LogEntry("getArtistTracks").addArg(artist.getName()));
|
||||
|
||||
int limit = 50;
|
||||
|
||||
ArrayList<Scrobble> scrobbles = new ArrayList<Scrobble>();
|
||||
|
||||
Boolean done = false;
|
||||
int counter = 1;
|
||||
while (!done) {
|
||||
|
||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||
|
||||
parameters.put("user", userName);
|
||||
parameters.put("artist", artist.getName());
|
||||
parameters.put("limit", Integer.toString(limit));
|
||||
parameters.put("page", Integer.toString(counter + 1));
|
||||
|
||||
JSONObject obj = makeGetRequest("user.getartisttracks", parameters);
|
||||
|
||||
JSONArray returnedScrobbles = obj.getJSONObject("artisttracks").getJSONArray("track");
|
||||
|
||||
if (returnedScrobbles.length() > 0) {
|
||||
|
||||
for (int i = 0; i < returnedScrobbles.length(); i++) {
|
||||
|
||||
JSONObject scrob = returnedScrobbles.getJSONObject(i);
|
||||
|
||||
}
|
||||
}else {
|
||||
done = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Scrobble> getRecentScrobbles(int number) {
|
||||
|
||||
Logger.getLog().log(new LogEntry("getRecentTracks").addArg(Integer.toString(number)));
|
||||
@ -275,7 +317,7 @@ public class FmUserNetwork extends FmNetwork {
|
||||
try {
|
||||
Scrobble scrobble = new Scrobble(json.getJSONObject("date").getLong("uts"), track);
|
||||
scrobbles.add(scrobble);
|
||||
}catch(JSONException e){
|
||||
} catch (JSONException e) {
|
||||
Logger.getLog().logInfo(new InfoEntry("getRecentTracks").addArg("first track"));
|
||||
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import java.util.Comparator;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.chart.PieChart;
|
||||
import sarsoo.fmframework.cache.TagPool;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
||||
|
||||
public class GenrePieChart extends PieChart{
|
||||
|
||||
|
@ -16,6 +16,7 @@ import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.stage.FileChooser;
|
||||
import sarsoo.fmframework.cache.TagPool;
|
||||
import sarsoo.fmframework.file.ListPersister;
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.fx.TextAreaConsole;
|
||||
@ -45,7 +46,6 @@ import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
@ -8,10 +8,10 @@ import javafx.concurrent.Task;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import sarsoo.fmframework.cache.TagPool;
|
||||
import sarsoo.fmframework.fx.FmFramework;
|
||||
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
||||
import sarsoo.fmframework.music.Tag;
|
||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
||||
|
||||
public class GetTagMenuItemsService extends Service<ArrayList<MenuItem>> {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user