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;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ import sarsoo.fmframework.net.Key;
|
|||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.Reference;
|
import sarsoo.fmframework.util.Reference;
|
||||||
|
|
||||||
public class TagPool {
|
public class TagPool{
|
||||||
|
|
||||||
private static TagPool instance;
|
private static TagPool instance;
|
||||||
|
|
@ -128,12 +128,11 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
.getJSONArray("track");
|
.getJSONArray("track");
|
||||||
|
|
||||||
JSONObject track = (JSONObject) obj.get(0);
|
JSONObject track = (JSONObject) obj.get(0);
|
||||||
|
|
||||||
Artist artistObj = getArtist(track.getJSONObject("artist").getString("#text"));
|
Artist artistObj = getArtist(track.getJSONObject("artist").getString("#text"));
|
||||||
|
|
||||||
Track trackObj = getTrack(track.getString("name"), artistObj);
|
Track trackObj = getTrack(track.getString("name"), artistObj);
|
||||||
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"),
|
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"), artistObj));
|
||||||
artistObj));
|
|
||||||
|
|
||||||
return trackObj;
|
return trackObj;
|
||||||
|
|
||||||
@ -233,10 +232,53 @@ 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) {
|
public ArrayList<Scrobble> getRecentScrobbles(int number) {
|
||||||
|
|
||||||
Logger.getLog().log(new LogEntry("getRecentTracks").addArg(Integer.toString(number)));
|
Logger.getLog().log(new LogEntry("getRecentTracks").addArg(Integer.toString(number)));
|
||||||
|
|
||||||
int limit = 50;
|
int limit = 50;
|
||||||
|
|
||||||
int pages = 0;
|
int pages = 0;
|
||||||
@ -259,7 +301,7 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
parameters.put("page", Integer.toString(counter + 1));
|
parameters.put("page", Integer.toString(counter + 1));
|
||||||
|
|
||||||
JSONObject obj = makeGetRequest("user.getrecenttracks", parameters);
|
JSONObject obj = makeGetRequest("user.getrecenttracks", parameters);
|
||||||
|
|
||||||
JSONArray tracks = obj.getJSONObject("recenttracks").getJSONArray("track");
|
JSONArray tracks = obj.getJSONObject("recenttracks").getJSONArray("track");
|
||||||
|
|
||||||
for (int i = 0; i < tracks.length(); i++) {
|
for (int i = 0; i < tracks.length(); i++) {
|
||||||
@ -271,15 +313,15 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
|
|
||||||
Track track = new TrackBuilder(json.getString("name"), artist).build();
|
Track track = new TrackBuilder(json.getString("name"), artist).build();
|
||||||
track.setAlbum(album);
|
track.setAlbum(album);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Scrobble scrobble = new Scrobble(json.getJSONObject("date").getLong("uts"), track);
|
Scrobble scrobble = new Scrobble(json.getJSONObject("date").getLong("uts"), track);
|
||||||
scrobbles.add(scrobble);
|
scrobbles.add(scrobble);
|
||||||
}catch(JSONException e){
|
} catch (JSONException e) {
|
||||||
Logger.getLog().logInfo(new InfoEntry("getRecentTracks").addArg("first track"));
|
Logger.getLog().logInfo(new InfoEntry("getRecentTracks").addArg("first track"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import java.util.Comparator;
|
|||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.scene.chart.PieChart;
|
import javafx.scene.chart.PieChart;
|
||||||
|
import sarsoo.fmframework.cache.TagPool;
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
|
||||||
|
|
||||||
public class GenrePieChart extends PieChart{
|
public class GenrePieChart extends PieChart{
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import javafx.event.ActionEvent;
|
|||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
import sarsoo.fmframework.cache.TagPool;
|
||||||
import sarsoo.fmframework.file.ListPersister;
|
import sarsoo.fmframework.file.ListPersister;
|
||||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
import sarsoo.fmframework.fx.TextAreaConsole;
|
import sarsoo.fmframework.fx.TextAreaConsole;
|
||||||
@ -45,7 +46,6 @@ import sarsoo.fmframework.music.Track;
|
|||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.net.Key;
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
import sarsoo.fmframework.util.Reference;
|
import sarsoo.fmframework.util.Reference;
|
||||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
|
@ -8,10 +8,10 @@ import javafx.concurrent.Task;
|
|||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
|
import sarsoo.fmframework.cache.TagPool;
|
||||||
import sarsoo.fmframework.fx.FmFramework;
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
||||||
import sarsoo.fmframework.music.Tag;
|
import sarsoo.fmframework.music.Tag;
|
||||||
import sarsoo.fmframework.util.tagpool.TagPool;
|
|
||||||
|
|
||||||
public class GetTagMenuItemsService extends Service<ArrayList<MenuItem>> {
|
public class GetTagMenuItemsService extends Service<ArrayList<MenuItem>> {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user