added gettrackscrobbles
This commit is contained in:
parent
7ae40b1c8c
commit
6b465e25fe
@ -372,32 +372,33 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
return artists;
|
return artists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Artist getArtistTracks(String artistName) {
|
public ArrayList<Scrobble> getTrackScrobbles(Track track) {
|
||||||
return getArtistTracks(getArtist(artistName));
|
|
||||||
|
Logger.getLog()
|
||||||
|
.log(new LogEntry("getTrackScrobbles").addArg(track.getName()).addArg(track.getArtist().getName()));
|
||||||
|
|
||||||
|
return getRecursiveTrackScrobbles(track, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Artist getArtistTracks(Artist artist) {
|
private ArrayList<Scrobble> getRecursiveTrackScrobbles(Track track, int page) {
|
||||||
|
|
||||||
Logger.getLog().log(new LogEntry("getArtistTracks").addArg(artist.getName()));
|
|
||||||
|
|
||||||
int limit = 50;
|
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>();
|
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||||
|
|
||||||
parameters.put("user", userName);
|
parameters.put("user", userName);
|
||||||
parameters.put("artist", artist.getName());
|
parameters.put("track", track.getName());
|
||||||
|
parameters.put("artist", track.getArtist().getName());
|
||||||
parameters.put("limit", Integer.toString(limit));
|
parameters.put("limit", Integer.toString(limit));
|
||||||
parameters.put("page", Integer.toString(counter + 1));
|
parameters.put("page", Integer.toString(page));
|
||||||
|
|
||||||
JSONObject obj = makeGetRequest("user.getartisttracks", parameters);
|
ArrayList<Scrobble> scrobbles = new ArrayList<Scrobble>();
|
||||||
|
|
||||||
JSONArray returnedScrobbles = obj.getJSONObject("artisttracks").getJSONArray("track");
|
JSONObject obj = makeGetRequest("user.gettrackscrobbles", parameters);
|
||||||
|
|
||||||
|
JSONArray returnedScrobbles = obj.getJSONObject("trackscrobbles").getJSONArray("track");
|
||||||
|
|
||||||
|
System.out.println(returnedScrobbles.length() + " length");
|
||||||
|
|
||||||
if (returnedScrobbles.length() > 0) {
|
if (returnedScrobbles.length() > 0) {
|
||||||
|
|
||||||
@ -405,14 +406,22 @@ public class FmUserNetwork extends FmNetwork {
|
|||||||
|
|
||||||
JSONObject scrob = returnedScrobbles.getJSONObject(i);
|
JSONObject scrob = returnedScrobbles.getJSONObject(i);
|
||||||
|
|
||||||
}
|
Scrobble scrobble = new Scrobble(scrob.getJSONObject("date").getLong("uts"), track);
|
||||||
} else {
|
|
||||||
done = true;
|
scrobbles.add(scrobble);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int totalPages = obj.getJSONObject("trackscrobbles").getJSONObject("@attr").getInt("totalPages");
|
||||||
|
|
||||||
|
if (totalPages > page) {
|
||||||
|
|
||||||
|
scrobbles.addAll(getRecursiveTrackScrobbles(track, page + 1));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return scrobbles;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Scrobble> getRecentScrobbles(int number) {
|
public ArrayList<Scrobble> getRecentScrobbles(int number) {
|
||||||
|
@ -3,6 +3,9 @@ package sarsoo.fmframework.fm;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import sarsoo.fmframework.music.Scrobble;
|
import sarsoo.fmframework.music.Scrobble;
|
||||||
|
import sarsoo.fmframework.music.Track;
|
||||||
|
import sarsoo.fmframework.music.Track.TrackBuilder;
|
||||||
|
import sarsoo.fmframework.music.Artist.ArtistBuilder;
|
||||||
import sarsoo.fmframework.net.Key;
|
import sarsoo.fmframework.net.Key;
|
||||||
import sarsoo.fmframework.util.FMObjList;
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
|
|
||||||
@ -26,7 +29,7 @@ public class FmUserNetworkTest {
|
|||||||
public void testGetRecentTracks() {
|
public void testGetRecentTracks() {
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
||||||
ArrayList<Scrobble> scrobbles = net.getRecentScrobbles(50);
|
ArrayList<Scrobble> scrobbles = net.getRecentScrobbles(50);
|
||||||
scrobbles.stream().forEach(System.out::println);
|
// scrobbles.stream().forEach(System.out::println);
|
||||||
System.out.println(scrobbles.size());
|
System.out.println(scrobbles.size());
|
||||||
assertNotNull(1);
|
assertNotNull(1);
|
||||||
}
|
}
|
||||||
@ -35,7 +38,7 @@ public class FmUserNetworkTest {
|
|||||||
public void testGetTopAlbums() {
|
public void testGetTopAlbums() {
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
||||||
FMObjList list = net.getTopAlbums("7day", 15);
|
FMObjList list = net.getTopAlbums("7day", 15);
|
||||||
list.stream().forEach(System.out::println);
|
// list.stream().forEach(System.out::println);
|
||||||
assertEquals(15, list.size());
|
assertEquals(15, list.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +46,7 @@ public class FmUserNetworkTest {
|
|||||||
public void testGetTopArtists() {
|
public void testGetTopArtists() {
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
||||||
FMObjList list = net.getTopArtists("7day", 15);
|
FMObjList list = net.getTopArtists("7day", 15);
|
||||||
list.stream().forEach(System.out::println);
|
// list.stream().forEach(System.out::println);
|
||||||
assertEquals(15, list.size());
|
assertEquals(15, list.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +54,20 @@ public class FmUserNetworkTest {
|
|||||||
public void testGetTopTracks() {
|
public void testGetTopTracks() {
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
||||||
FMObjList list = net.getTopTracks("7day", 15);
|
FMObjList list = net.getTopTracks("7day", 15);
|
||||||
list.stream().forEach(System.out::println);
|
// list.stream().forEach(System.out::println);
|
||||||
assertEquals(15, list.size());
|
assertEquals(15, list.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTrackScrobbles() {
|
||||||
|
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
|
||||||
|
|
||||||
|
Track track = new TrackBuilder("shitsville", new ArtistBuilder("freddie gibbs").build()).build();
|
||||||
|
|
||||||
|
ArrayList<Scrobble> scrobbles = net.getTrackScrobbles(track);
|
||||||
|
|
||||||
|
scrobbles.stream().forEach(System.out::println);
|
||||||
|
System.out.println(scrobbles.size());
|
||||||
|
assertEquals(53, scrobbles.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user