new network implemented, daily count working again
This commit is contained in:
parent
7dcd3b9994
commit
3ed4d691b7
19
build.gradle
19
build.gradle
@ -14,6 +14,10 @@ apply plugin: 'eclipse'
|
||||
|
||||
mainClassName = 'sarsoo.fmframework.fx.FmFramework'
|
||||
|
||||
version = '0.1.0'
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
// In this section you declare where to find the dependencies of your project
|
||||
repositories {
|
||||
// Use 'jcenter' for resolving your dependencies.
|
||||
@ -36,6 +40,7 @@ dependencies {
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
/*
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Implementation-Title': 'fmframework',
|
||||
@ -43,5 +48,17 @@ jar {
|
||||
'Main-Class': 'sarsoo.fmframework.fx.FmFramework'
|
||||
}
|
||||
baseName = 'fmframework'
|
||||
version = '0.1.0'
|
||||
version = version
|
||||
}*/
|
||||
|
||||
//create a single Jar with all dependencies
|
||||
task fatJar(type: Jar) {
|
||||
manifest {
|
||||
attributes 'Implementation-Title': 'fmframework',
|
||||
'Implementation-Version': version,
|
||||
'Main-Class': 'sarsoo.fmframework.fx.FmFramework'
|
||||
}
|
||||
baseName = project.name + '-all'
|
||||
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
with jar
|
||||
}
|
||||
|
@ -358,14 +358,23 @@ public class FmNetwork {
|
||||
}
|
||||
|
||||
public Album refresh(Album album) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>refreshAlbum: " + album.getName() + " " + album.getArtist().getName());
|
||||
|
||||
return getAlbum(album.getName(), album.getArtist().getName());
|
||||
}
|
||||
|
||||
public Artist refresh(Artist artist) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>refreshArtist: " + artist.getName());
|
||||
|
||||
return getArtist(artist.getName());
|
||||
}
|
||||
|
||||
public Track refresh(Track track) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>refreshTrack: " + track.getName() + " " + track.getArtist().getName());
|
||||
|
||||
Track refreshedTrack = getTrack(track.getName(), track.getArtist().getName());
|
||||
|
||||
refreshedTrack.setAlbum(refresh(track.getAlbum()));
|
||||
|
@ -1,5 +1,9 @@
|
||||
package sarsoo.fmframework.fm;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -8,33 +12,36 @@ import com.mashape.unirest.http.JsonNode;
|
||||
import com.mashape.unirest.http.Unirest;
|
||||
import com.mashape.unirest.http.exceptions.UnirestException;
|
||||
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.Tag;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.util.ConsoleHandler;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
|
||||
public class FmUserNetwork extends FmNetwork{
|
||||
public class FmUserNetwork extends FmNetwork {
|
||||
|
||||
public enum TaggingType {
|
||||
ARTIST, ALBUM, TRACK
|
||||
}
|
||||
|
||||
public FmUserNetwork(String key, String userName) {
|
||||
super(key, userName);
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>getUser");
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.getinfo").
|
||||
queryString("user", userName).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/")
|
||||
.header("Accept", "application/json").header("User-Agent", "fmframework")
|
||||
.queryString("method", "user.getinfo").queryString("user", userName).queryString("api_key", key)
|
||||
.queryString("format", "json").asJson();
|
||||
|
||||
JSONObject obj = new JSONObject(response.getBody().toString()).getJSONObject("user");
|
||||
|
||||
return new User(obj.getString("name"),
|
||||
obj.getString("realname"),
|
||||
obj.getString("url"),
|
||||
obj.getString("country"),
|
||||
obj.getInt("age"),
|
||||
obj.getString("gender").charAt(0),
|
||||
return new User(obj.getString("name"), obj.getString("realname"), obj.getString("url"),
|
||||
obj.getString("country"), obj.getInt("age"), obj.getString("gender").charAt(0),
|
||||
obj.getInt("playcount"));
|
||||
|
||||
} catch (UnirestException e) {
|
||||
@ -45,33 +52,37 @@ public class FmUserNetwork extends FmNetwork{
|
||||
}
|
||||
|
||||
public String getUserRealName() {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>getUserRealname");
|
||||
|
||||
return getUser().getRealName();
|
||||
}
|
||||
|
||||
public int getUserScrobbleCount() {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>getUserScrobbleCount");
|
||||
|
||||
return getUser().getScrobbleCount();
|
||||
}
|
||||
|
||||
public Track getLastTrack() {
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.getrecenttracks").
|
||||
queryString("user", userName).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
queryString("limit", "1").
|
||||
asJson();
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>getLastTrack");
|
||||
|
||||
JSONArray obj = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks").getJSONArray("track");
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/")
|
||||
.header("Accept", "application/json").header("User-Agent", "fmframework")
|
||||
.queryString("method", "user.getrecenttracks").queryString("user", userName)
|
||||
.queryString("api_key", key).queryString("format", "json").queryString("limit", "1").asJson();
|
||||
|
||||
JSONArray obj = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks")
|
||||
.getJSONArray("track");
|
||||
|
||||
JSONObject track = (JSONObject) obj.get(0);
|
||||
|
||||
Track trackObj = getTrack(track.getString("name"), track.getJSONObject("artist").getString("#text"));
|
||||
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"), track.getJSONObject("artist").getString("#text")));
|
||||
trackObj.setAlbum(getAlbum(track.getJSONObject("album").getString("#text"),
|
||||
track.getJSONObject("artist").getString("#text")));
|
||||
|
||||
return trackObj;
|
||||
|
||||
@ -81,4 +92,127 @@ public class FmUserNetwork extends FmNetwork{
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getScrobblesToday() {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>getScrobblesToday");
|
||||
|
||||
LocalDate local = LocalDate.now();
|
||||
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
long epoch = local.atStartOfDay(zoneId).toEpochSecond();
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.getrecenttracks").
|
||||
queryString("user", userName).
|
||||
queryString("from", epoch).
|
||||
queryString("limit", 1).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
|
||||
int total = new JSONObject(response.getBody().toString()).getJSONObject("recenttracks").getJSONObject("@attr").getInt("total");
|
||||
|
||||
return total;
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ArrayList<Tag> getTags(){
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>getTags");
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.gettoptags").
|
||||
queryString("user", userName).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
|
||||
JSONArray tagJsonArray = new JSONObject(response.getBody().toString()).getJSONObject("toptags").getJSONArray("tag");
|
||||
|
||||
JSONObject tagJson;
|
||||
|
||||
ArrayList<Tag> tags = new ArrayList<Tag>();
|
||||
|
||||
int counter;
|
||||
for(counter = 0; counter < tagJsonArray.length(); counter++) {
|
||||
|
||||
tagJson = (JSONObject) tagJsonArray.get(counter);
|
||||
|
||||
Tag tag = new Tag(tagJson.getString("name"), tagJson.getString("url"), tagJson.getInt("count"));
|
||||
|
||||
tags.add(tag);
|
||||
|
||||
}
|
||||
|
||||
return tags;
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public FMObjList getTag(String tagName) {
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">>getTag: " + tagName);
|
||||
|
||||
try {
|
||||
HttpResponse<JsonNode> response = Unirest.get("http://ws.audioscrobbler.com/2.0/").
|
||||
header("Accept", "application/json").
|
||||
header("User-Agent", "fmframework").
|
||||
queryString("method","user.getpersonaltags").
|
||||
queryString("user", userName).
|
||||
queryString("tag", tagName).
|
||||
queryString("taggingtype", "artist").
|
||||
queryString("limit", 70).
|
||||
queryString("api_key", key).
|
||||
queryString("format", "json").
|
||||
asJson();
|
||||
|
||||
JSONArray tagJsonArray = new JSONObject(response.getBody().toString()).getJSONObject("taggings").getJSONObject("artists").getJSONArray("artist");
|
||||
|
||||
JSONObject artistJson;
|
||||
|
||||
FMObjList list = new FMObjList();
|
||||
|
||||
list.setGroupName(tagName);
|
||||
|
||||
int counter;
|
||||
for(counter = 0; counter < tagJsonArray.length(); counter++) {
|
||||
|
||||
artistJson = (JSONObject) tagJsonArray.get(counter);
|
||||
|
||||
Artist artist = getArtist(artistJson.getString("name"));
|
||||
|
||||
if (ConsoleHandler.isVerbose())
|
||||
ConsoleHandler.getConsole().write(">Tag: " + tagName + ", " + artist.getName());
|
||||
|
||||
list.add(artist);
|
||||
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
} catch (UnirestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.ConsoleHandler;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Getter;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.chart.*;
|
||||
@ -69,7 +68,7 @@ public class ControllerMain {
|
||||
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
|
||||
String scrobblesToday = numberFormat.format(0);
|
||||
String scrobblesToday = numberFormat.format(net.getScrobblesToday());
|
||||
String scrobbles = numberFormat.format(net.getUserScrobbleCount());
|
||||
|
||||
TrackTab tab = new TrackTab(net.getLastTrack());
|
||||
@ -105,7 +104,9 @@ public class ControllerMain {
|
||||
}
|
||||
|
||||
public void refreshTagMenu() {
|
||||
tags = Getter.getUserTags(Reference.getUserName());
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
|
||||
tags = net.getTags();
|
||||
|
||||
Collections.sort(tags);
|
||||
|
||||
@ -131,7 +132,7 @@ public class ControllerMain {
|
||||
protected Void call() throws Exception {
|
||||
|
||||
FMObjListTab tab = new FMObjListTab(
|
||||
Getter.getUserTag(Reference.getUserName(), name));
|
||||
net.getTag(name));
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Platform.runLater(new Runnable() {
|
||||
@ -167,24 +168,26 @@ public class ControllerMain {
|
||||
@Override
|
||||
protected Void call() throws Exception {
|
||||
|
||||
int total = Getter.getScrobbles(Reference.getUserName());
|
||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||
|
||||
FMObjList rap = Getter.getUserTag(Reference.getUserName(), "rap");
|
||||
FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic rap");
|
||||
FMObjList grime = Getter.getUserTag(Reference.getUserName(), "grime");
|
||||
int total = net.getUserScrobbleCount();
|
||||
|
||||
FMObjList classicRock = Getter.getUserTag(Reference.getUserName(), "classic rock");
|
||||
FMObjList popPunk = Getter.getUserTag(Reference.getUserName(), "pop punk");
|
||||
FMObjList electronic = Getter.getUserTag(Reference.getUserName(), "electronic");
|
||||
FMObjList metal = Getter.getUserTag(Reference.getUserName(), "metal");
|
||||
FMObjList indie = Getter.getUserTag(Reference.getUserName(), "indie");
|
||||
FMObjList rock = Getter.getUserTag(Reference.getUserName(), "rock");
|
||||
FMObjList jazz = Getter.getUserTag(Reference.getUserName(), "jazz");
|
||||
FMObjList blues = Getter.getUserTag(Reference.getUserName(), "blues");
|
||||
FMObjList core = Getter.getUserTag(Reference.getUserName(), "core");
|
||||
FMObjList rnb = Getter.getUserTag(Reference.getUserName(), "rnb");
|
||||
FMObjList soulFunk = Getter.getUserTag(Reference.getUserName(), "soulfunk");
|
||||
FMObjList punk = Getter.getUserTag(Reference.getUserName(), "punk");
|
||||
FMObjList rap = net.getTag("rap");
|
||||
FMObjList classicRap = net.getTag("classic rap");
|
||||
FMObjList grime = net.getTag("grime");
|
||||
|
||||
FMObjList classicRock = net.getTag("classic rock");
|
||||
FMObjList popPunk = net.getTag("pop punk");
|
||||
FMObjList electronic = net.getTag("electronic");
|
||||
FMObjList metal = net.getTag("metal");
|
||||
FMObjList indie = net.getTag("indie");
|
||||
FMObjList rock = net.getTag("rock");
|
||||
FMObjList jazz = net.getTag("jazz");
|
||||
FMObjList blues = net.getTag("blues");
|
||||
FMObjList core = net.getTag("core");
|
||||
FMObjList rnb = net.getTag("rnb");
|
||||
FMObjList soulFunk = net.getTag("soulfunk");
|
||||
FMObjList punk = net.getTag("punk");
|
||||
|
||||
int rapTotal = rap.getTotalUserScrobbles() + classicRap.getTotalUserScrobbles()
|
||||
+ grime.getTotalUserScrobbles();
|
||||
|
@ -21,7 +21,6 @@ import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Getter;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
import javafx.scene.layout.*;
|
||||
@ -53,7 +52,7 @@ public class FMObjListPaneController {
|
||||
double percent = Maths.getPercentListening(list, Reference.getUserName());
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
labelTotalScrobbles.setText("Σ " + list.getTotalUserScrobbles());
|
||||
labelTotalScrobbles.setText("" + list.getTotalUserScrobbles());
|
||||
labelPercent.setText(String.format("%.2f%%", percent));
|
||||
|
||||
Collections.sort(list);
|
||||
@ -124,7 +123,7 @@ public class FMObjListPaneController {
|
||||
@FXML
|
||||
protected void handleRefresh(ActionEvent event) {
|
||||
|
||||
list = Getter.getUserTag(Reference.getUserName(), list.getGroupName());
|
||||
list = new FmUserNetwork(Key.getKey(), Reference.getUserName()).getTag(list.getGroupName());
|
||||
|
||||
|
||||
double percent = Maths.getPercentListening(list, Reference.getUserName());
|
||||
|
@ -27,7 +27,6 @@ import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.music.Track;
|
||||
import sarsoo.fmframework.net.Key;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Getter;
|
||||
import sarsoo.fmframework.util.Maths;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
import javafx.scene.layout.*;
|
||||
@ -144,17 +143,21 @@ public class FMObjListPaneEditController {
|
||||
|
||||
FmNetwork net = new FmNetwork(Key.getKey(), Reference.getUserName());
|
||||
|
||||
FMObjList newList = new FMObjList();
|
||||
int counter;
|
||||
for (counter = 0; counter < list.size(); counter++) {
|
||||
net.refresh(list.get(counter));
|
||||
|
||||
newList.add(net.refresh(list.get(counter)));
|
||||
}
|
||||
|
||||
setList(newList);
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
double percent = Maths.getPercentListening(list, Reference.getUserName());
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
labelTotalScrobbles.setText("Σ " + list.getTotalUserScrobbles());
|
||||
labelTotalScrobbles.setText("" + list.getTotalUserScrobbles());
|
||||
labelPercent.setText(String.format("%.2f%%", percent));
|
||||
|
||||
Collections.sort(list);
|
||||
|
@ -66,6 +66,7 @@ public class Artist extends FMObj implements Serializable{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Artist getArtistByMbid(String mbid, String username) {
|
||||
String url = URLBuilder.getArtistInfoMbidUrl(mbid, username);
|
||||
Document response = Network.getResponse(url);
|
||||
|
@ -13,6 +13,13 @@ public class Tag implements Comparable<Tag>, Serializable{
|
||||
private String summary;
|
||||
private String content;
|
||||
|
||||
public Tag(String name, String url, int count) {
|
||||
this.setName(name);
|
||||
this.setUrl(url);
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Tag(String name, String url) {
|
||||
this.setName(name);
|
||||
this.setUrl(url);
|
||||
|
@ -9,6 +9,7 @@ import java.net.URLEncoder;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Deprecated
|
||||
public class Authenticator {
|
||||
public String write() {
|
||||
URL url;
|
||||
|
@ -16,6 +16,7 @@ import org.xml.sax.SAXException;
|
||||
|
||||
import sarsoo.fmframework.error.ApiCallException;
|
||||
|
||||
@Deprecated
|
||||
public class Network {
|
||||
|
||||
public static Document getResponse(String urlString) {
|
||||
|
@ -1,13 +0,0 @@
|
||||
package sarsoo.fmframework.net;
|
||||
|
||||
public class ParamAssembler {
|
||||
public static byte[] getToken() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void getSignature() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
@Deprecated
|
||||
public class TestCall {
|
||||
|
||||
public static void test(String urlString) {
|
||||
|
@ -7,6 +7,7 @@ import java.time.LocalDateTime;
|
||||
|
||||
import sarsoo.fmframework.music.Track;
|
||||
|
||||
@Deprecated
|
||||
public class URLBuilder {
|
||||
|
||||
public enum FMObjType{
|
||||
|
@ -12,6 +12,7 @@ import sarsoo.fmframework.parser.Parser;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
import sarsoo.fmframework.util.Reference;
|
||||
|
||||
@Deprecated
|
||||
public class User {
|
||||
|
||||
protected String userName;
|
||||
|
@ -4,12 +4,16 @@ import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import sarsoo.fmframework.music.Artist;
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
|
||||
public class FmUserNetworkTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
FmUserNetwork network = new FmUserNetwork("54a9f5c4c36f5d2cba0d4ffe3846e8b4", "sarsoo");
|
||||
|
||||
System.out.println(network.getLastTrack());
|
||||
network.getScrobblesToday();
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class FMObjListTest {
|
||||
|
||||
// Album album = new Album();
|
||||
|
||||
fail("Not yet implemented");
|
||||
// fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user