added abstract getScrobbles method, fixed get recent scrobbles
This commit is contained in:
parent
f1f85ada87
commit
b776e91436
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import sarsoo.fmframework.log.Logger;
|
||||
@ -232,7 +233,7 @@ public class FmUserNetwork extends FmNetwork {
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Scrobble> getRecentTracks(int number) {
|
||||
public ArrayList<Scrobble> getRecentScrobbles(int number) {
|
||||
|
||||
Logger.getLog().log(new LogEntry("getRecentTracks").addArg(Integer.toString(number)));
|
||||
|
||||
@ -270,10 +271,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){
|
||||
Logger.getLog().logInfo(new InfoEntry("getRecentTracks").addArg("first track"));
|
||||
|
||||
Scrobble scrobble = new Scrobble(json.getJSONObject("date").getLong("uts"), track);
|
||||
|
||||
scrobbles.add(scrobble);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,4 +136,18 @@ public class Album extends FMObj implements Serializable{
|
||||
return new Album(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Scrobble> getScrobbles() {
|
||||
if(trackList != null) {
|
||||
if (trackList.size() > 0) {
|
||||
ArrayList<Scrobble> scrobbles = new ArrayList<Scrobble>();
|
||||
for (Track i: trackList) {
|
||||
scrobbles.addAll(i.getScrobbles());
|
||||
}
|
||||
return scrobbles;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package sarsoo.fmframework.music;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Artist extends FMObj implements Serializable{
|
||||
|
||||
public class Artist extends FMObj implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -17,22 +17,21 @@ public class Artist extends FMObj implements Serializable{
|
||||
|
||||
private Artist(ArtistBuilder builder) {
|
||||
this.name = builder.name;
|
||||
|
||||
|
||||
this.url = builder.url;
|
||||
|
||||
|
||||
this.listeners = builder.listeners;
|
||||
this.playCount = builder.playCount;
|
||||
this.userPlayCount = builder.userPlayCount;
|
||||
|
||||
|
||||
this.wiki = builder.wiki;
|
||||
|
||||
|
||||
this.mbid = builder.mbid;
|
||||
|
||||
|
||||
this.albums = builder.albums;
|
||||
this.similarArtists = builder.similarArtists;
|
||||
this.tagList = builder.tagList;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Album> getAlbum() {
|
||||
@ -72,80 +71,93 @@ public class Artist extends FMObj implements Serializable{
|
||||
return "Artist: " + name;
|
||||
}
|
||||
|
||||
|
||||
public static class ArtistBuilder{
|
||||
|
||||
public static class ArtistBuilder {
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
protected String url;
|
||||
|
||||
|
||||
protected int listeners;
|
||||
protected int playCount;
|
||||
protected int userPlayCount;
|
||||
|
||||
|
||||
protected Wiki wiki;
|
||||
|
||||
|
||||
protected String mbid;
|
||||
|
||||
|
||||
protected ArrayList<Album> albums;
|
||||
protected ArrayList<Artist> similarArtists;
|
||||
protected ArrayList<Tag> tagList;
|
||||
|
||||
|
||||
|
||||
public ArtistBuilder(String name) {
|
||||
|
||||
|
||||
this.name = name;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setUrl(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setListeners(int listeners) {
|
||||
this.listeners = listeners;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setPlayCount(int playCount) {
|
||||
this.playCount = playCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setUserPlayCount(int userPlayCount) {
|
||||
this.userPlayCount = userPlayCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setWiki(Wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setMbid(String Mbid) {
|
||||
this.mbid = Mbid;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setAlbums(ArrayList<Album> albums) {
|
||||
this.albums = albums;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setSimilarArtists(ArrayList<Artist> similarArtists) {
|
||||
this.similarArtists = similarArtists;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArtistBuilder setTagList(ArrayList<Tag> tagList) {
|
||||
this.tagList = tagList;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Artist build() {
|
||||
return new Artist(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Scrobble> getScrobbles() {
|
||||
if (albums != null) {
|
||||
if (albums.size() > 0) {
|
||||
ArrayList<Scrobble> scrobbles = new ArrayList<Scrobble>();
|
||||
for (Album i : albums) {
|
||||
scrobbles.addAll(i.getScrobbles());
|
||||
}
|
||||
return scrobbles;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package sarsoo.fmframework.music;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
@ -72,5 +73,7 @@ public abstract class FMObj implements Comparable<FMObj>, Serializable{
|
||||
}
|
||||
|
||||
abstract public String getMusicBrainzURL();
|
||||
|
||||
public abstract ArrayList<Scrobble> getScrobbles();
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,21 @@
|
||||
package sarsoo.fmframework.music;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
public class Scrobble {
|
||||
|
||||
private long utc;
|
||||
private LocalDateTime dateTime;
|
||||
private Track track;
|
||||
|
||||
public Scrobble(long utc, Track track) {
|
||||
this.utc = utc;
|
||||
this.track = track;
|
||||
public Scrobble(long uts, Track track) {
|
||||
this.track = track;
|
||||
this.dateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(uts), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
public long getUTC() {
|
||||
return utc;
|
||||
public LocalDateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public Track getTrack() {
|
||||
@ -19,7 +23,7 @@ public class Scrobble {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return utc + " " + track.toString();
|
||||
return dateTime + " " + track.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,11 +3,6 @@ package sarsoo.fmframework.music;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import sarsoo.fmframework.net.Network;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
public class Track extends FMObj implements Serializable {
|
||||
|
||||
/**
|
||||
@ -213,4 +208,9 @@ public class Track extends FMObj implements Serializable {
|
||||
return new Track(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Scrobble> getScrobbles() {
|
||||
return scrobbles;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class FmUserNetworkTest {
|
||||
@Test
|
||||
public void testGetRecentTracks() {
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
||||
ArrayList<Scrobble> scrobbles = net.getRecentTracks(50);
|
||||
ArrayList<Scrobble> scrobbles = net.getRecentScrobbles(50);
|
||||
scrobbles.stream().forEach(System.out::println);
|
||||
System.out.println(scrobbles.size());
|
||||
assertNotNull(1);
|
||||
|
Loading…
Reference in New Issue
Block a user