ready for cache implementations, started on get artist tracks

This commit is contained in:
aj 2019-05-04 13:26:16 +01:00
parent 2bc9aff667
commit fdac060b98
5 changed files with 56 additions and 14 deletions

View File

@ -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;

View File

@ -128,12 +128,11 @@ public class FmUserNetwork extends FmNetwork {
.getJSONArray("track");
JSONObject track = (JSONObject) obj.get(0);
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,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) {
Logger.getLog().log(new LogEntry("getRecentTracks").addArg(Integer.toString(number)));
int limit = 50;
int pages = 0;
@ -259,7 +301,7 @@ public class FmUserNetwork extends FmNetwork {
parameters.put("page", Integer.toString(counter + 1));
JSONObject obj = makeGetRequest("user.getrecenttracks", parameters);
JSONArray tracks = obj.getJSONObject("recenttracks").getJSONArray("track");
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.setAlbum(album);
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"));
}
}
}
}

View File

@ -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{

View File

@ -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;

View File

@ -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>> {