begin network remodel
This commit is contained in:
parent
b443d4d719
commit
65e3766a62
@ -26,6 +26,9 @@ dependencies {
|
|||||||
// The production code uses the SLF4J logging API at compile time
|
// The production code uses the SLF4J logging API at compile time
|
||||||
compile 'org.slf4j:slf4j-api:1.7.25'
|
compile 'org.slf4j:slf4j-api:1.7.25'
|
||||||
|
|
||||||
|
compile 'com.mashape.unirest:unirest-java:1.4.9'
|
||||||
|
compile group: 'org.json', name: 'json', version: '20180130'
|
||||||
|
|
||||||
// Declare the dependency for your favourite test framework you want to use in your tests.
|
// Declare the dependency for your favourite test framework you want to use in your tests.
|
||||||
// TestNG is also supported by the Gradle Test task. Just change the
|
// TestNG is also supported by the Gradle Test task. Just change the
|
||||||
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
|
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
|
||||||
|
5
src/main/java/sarsoo/fmframework/fm/FmAuthNetwork.java
Normal file
5
src/main/java/sarsoo/fmframework/fm/FmAuthNetwork.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package sarsoo.fmframework.fm;
|
||||||
|
|
||||||
|
public class FmAuthNetwork extends FmUserNetwork {
|
||||||
|
|
||||||
|
}
|
5
src/main/java/sarsoo/fmframework/fm/FmNetwork.java
Normal file
5
src/main/java/sarsoo/fmframework/fm/FmNetwork.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package sarsoo.fmframework.fm;
|
||||||
|
|
||||||
|
public class FmNetwork {
|
||||||
|
|
||||||
|
}
|
5
src/main/java/sarsoo/fmframework/fm/FmUserNetwork.java
Normal file
5
src/main/java/sarsoo/fmframework/fm/FmUserNetwork.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package sarsoo.fmframework.fm;
|
||||||
|
|
||||||
|
public class FmUserNetwork extends FmNetwork {
|
||||||
|
|
||||||
|
}
|
5
src/main/java/sarsoo/fmframework/fm/User.java
Normal file
5
src/main/java/sarsoo/fmframework/fm/User.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package sarsoo.fmframework.fm;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
package sarsoo.fmframework.fx;
|
|
||||||
|
|
||||||
import javafx.concurrent.*;
|
|
||||||
import sarsoo.fmframework.util.Getter;
|
|
||||||
import sarsoo.fmframework.util.Reference;
|
|
||||||
|
|
||||||
public class TagCaller extends Task{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object call() throws Exception {
|
|
||||||
|
|
||||||
return Getter.getUserTags(Reference.getUserName());
|
|
||||||
}
|
|
||||||
}
|
|
177
src/main/java/sarsoo/fmframework/net/User.java
Normal file
177
src/main/java/sarsoo/fmframework/net/User.java
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
package sarsoo.fmframework.net;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.NamedNodeMap;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
import sarsoo.fmframework.music.Tag;
|
||||||
|
import sarsoo.fmframework.music.Track;
|
||||||
|
import sarsoo.fmframework.parser.Parser;
|
||||||
|
import sarsoo.fmframework.util.FMObjList;
|
||||||
|
import sarsoo.fmframework.util.Reference;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
protected String userName;
|
||||||
|
|
||||||
|
public User(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Track getLastTrack() {
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write(">>getLastTrack");
|
||||||
|
|
||||||
|
String url = URLBuilder.getLastTrackUrl(userName);
|
||||||
|
// TestCall.test(url);
|
||||||
|
Document doc = Network.getResponse(url);
|
||||||
|
|
||||||
|
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
||||||
|
if (doc != null) {
|
||||||
|
// System.out.println(doc.getDocumentElement().getAttribute("status"));
|
||||||
|
Parser.stripSpace(doc.getDocumentElement());
|
||||||
|
Track track = Parser.parseLastTrack(doc);
|
||||||
|
// if(Reference.isVerbose())
|
||||||
|
// System.out.println(track);
|
||||||
|
// return null;
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScrobbles() {
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write(">>getScrobbles");
|
||||||
|
|
||||||
|
String url = URLBuilder.getUserInfoUrl(userName);
|
||||||
|
Document doc = Network.getResponse(url);
|
||||||
|
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||||
|
String scrobbles = doc.getElementsByTagName("playcount").item(0).getTextContent();
|
||||||
|
if (scrobbles != null)
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write("total scrobbles: " + scrobbles);
|
||||||
|
return Integer.parseInt(scrobbles);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScrobblesToday() {
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write(">>getScrobblesToday");
|
||||||
|
|
||||||
|
String url = URLBuilder.getTodayScrobbles(userName);
|
||||||
|
Document doc = Network.getResponse(url);
|
||||||
|
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||||
|
Node node = doc.getChildNodes().item(0).getFirstChild();
|
||||||
|
NamedNodeMap var = node.getAttributes();
|
||||||
|
// System.out.println(var.getNamedItem("total").getNodeValue());
|
||||||
|
// if (scrobbles != null)
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write("scrobbles today: " + var.getNamedItem("total").getNodeValue());
|
||||||
|
return Integer.parseInt(var.getNamedItem("total").getNodeValue());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FMObjList getUserTag(String tag) {
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write(">>getUserTag");
|
||||||
|
|
||||||
|
String url = URLBuilder.getUserPersonalTags(userName, tag);
|
||||||
|
Document doc = Network.getResponse(url);
|
||||||
|
|
||||||
|
if (doc != null) {
|
||||||
|
int pages = Integer.valueOf(
|
||||||
|
doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write("tag pages: " + pages);
|
||||||
|
|
||||||
|
FMObjList list = Parser.parseUserTagList(doc);
|
||||||
|
list.setGroupName(tag);
|
||||||
|
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write("tag: " + tag);
|
||||||
|
|
||||||
|
if (pages > 1) {
|
||||||
|
int counter;
|
||||||
|
for (counter = 2; counter <= pages; counter++) {
|
||||||
|
String urlNew = URLBuilder.getUserPersonalTags(userName, tag, counter);
|
||||||
|
Document docNew = Network.getResponse(urlNew);
|
||||||
|
|
||||||
|
if (docNew != null) {
|
||||||
|
list.addAll(Parser.parseUserTagList(docNew));
|
||||||
|
// return Parser.parseUserTagList(docNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FMObjList getArtistTracks(String artist) {
|
||||||
|
|
||||||
|
// String url = URLBuilder.getArtistTracks(artist, 1, username);
|
||||||
|
// Document doc = Network.getResponse(url);
|
||||||
|
|
||||||
|
// if (doc != null) {
|
||||||
|
// int pages = Integer.valueOf(
|
||||||
|
// doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
|
||||||
|
//
|
||||||
|
// FMObjList list = Parser.parseArtistTracks(doc);
|
||||||
|
//// list.setGroupName(artist + " tracks");
|
||||||
|
//
|
||||||
|
// System.out.println(pages);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// return list;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write(">>getArtistTracks");
|
||||||
|
|
||||||
|
FMObjList totalList = new FMObjList();
|
||||||
|
FMObjList list = new FMObjList();
|
||||||
|
|
||||||
|
int counter = 1;
|
||||||
|
do {
|
||||||
|
String url = URLBuilder.getArtistTracks(artist, counter, userName);
|
||||||
|
Document doc = Network.getResponse(url);
|
||||||
|
|
||||||
|
list = Parser.parseArtistTracks(doc);
|
||||||
|
|
||||||
|
totalList.addAll(list);
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
}while(list.size() > 0);
|
||||||
|
|
||||||
|
return totalList;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Tag> getUserTags() {
|
||||||
|
if(Reference.isVerbose())
|
||||||
|
Reference.getConsole().write(">>getUserTags");
|
||||||
|
|
||||||
|
String url = URLBuilder.getUserTopTags(userName);
|
||||||
|
Document doc = Network.getResponse(url);
|
||||||
|
if (doc != null) {
|
||||||
|
return Parser.parseUserTags(doc);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,32 +0,0 @@
|
|||||||
package sarsoo.fmframework.util;
|
|
||||||
import sarsoo.fmframework.music.Artist;
|
|
||||||
|
|
||||||
public class ScrobbleSumming {
|
|
||||||
|
|
||||||
public static int getTopDawgScrobbles() {
|
|
||||||
FMObjList tde = new FMObjList();
|
|
||||||
|
|
||||||
// Artist kendrick = Artist.getArtist("Kendrick Lamar", "sarsoo");
|
|
||||||
// Artist jay = Artist.getArtist("Jay Rock", "sarsoo");
|
|
||||||
// Artist school = Artist.getArtist("ScHoolboy Q", "sarsoo");
|
|
||||||
// Artist ab = Artist.getArtist("Ab-Soul", "sarsoo");
|
|
||||||
// Artist blackHippy = Artist.getArtist("Black Hippy", "sarsoo");
|
|
||||||
// Artist isaiah = Artist.getArtist("Isaiah Rashad", "sarsoo");
|
|
||||||
// Artist sza = Artist.getArtist("SZA", "sarsoo");
|
|
||||||
// Artist lance = Artist.getArtist("Lance Skiiiwalker", "sarsoo");
|
|
||||||
// Artist sir = Artist.getArtist("SiR", "sarsoo");
|
|
||||||
|
|
||||||
tde.add(Artist.getArtist("Kendrick Lamar", "sarsoo"));
|
|
||||||
tde.add(Artist.getArtist("Jay Rock", "sarsoo"));
|
|
||||||
tde.add(Artist.getArtist("ScHoolboy Q", "sarsoo"));
|
|
||||||
tde.add(Artist.getArtist("Ab-Soul", "sarsoo"));
|
|
||||||
tde.add(Artist.getArtist("Black Hippy", "sarsoo"));
|
|
||||||
tde.add(Artist.getArtist("Isaiah Rashad", "sarsoo"));
|
|
||||||
tde.add(Artist.getArtist("SZA", "sarsoo"));
|
|
||||||
tde.add(Artist.getArtist("Lance Skiiiwalker", "sarsoo"));
|
|
||||||
tde.add(Artist.getArtist("SiR", "sarsoo"));
|
|
||||||
|
|
||||||
return tde.getTotalUserScrobbles();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
18
src/test/java/sarsoo/fmframework/util/FMObjListTest.java
Normal file
18
src/test/java/sarsoo/fmframework/util/FMObjListTest.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package sarsoo.fmframework.util;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FMObjListTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSeparateAlbumAddition() {
|
||||||
|
FMObjList list = new FMObjList();
|
||||||
|
|
||||||
|
// Album album = new Album();
|
||||||
|
|
||||||
|
fail("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user