added handling for pages in tags
This commit is contained in:
parent
d4a7120df2
commit
b6bc783e3e
1
fmframework/.gitignore
vendored
1
fmframework/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/.project
|
/.project
|
||||||
/bin/
|
/bin/
|
||||||
|
/doc/
|
||||||
|
@ -130,6 +130,24 @@ public class URLBuilder {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getUserPersonalTags(String username, String tag, int page) {
|
||||||
|
String urlString;
|
||||||
|
try {
|
||||||
|
urlString = String.format("http://ws.audioscrobbler.com/2.0/?method=user.getpersonaltags&user=%s&tag=%s&page=%d&taggingtype=artist&api_key=%s",
|
||||||
|
URLEncoder.encode(username, "UTF-8"),
|
||||||
|
URLEncoder.encode(tag, "UTF-8"),
|
||||||
|
page,
|
||||||
|
// URLEncoder.encode(taggingType.toString().toLowerCase(), "UTF-8"),
|
||||||
|
URLEncoder.encode(Key.getKey(), "UTF-8"));
|
||||||
|
return urlString;
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// System.out.println(urlString);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getUserTopTags(String username) {
|
public static String getUserTopTags(String username) {
|
||||||
String urlString;
|
String urlString;
|
||||||
try {
|
try {
|
||||||
@ -156,7 +174,7 @@ public class URLBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String day;
|
String day;
|
||||||
if(now.getMonthValue() < 10) {
|
if(now.getDayOfMonth() < 10) {
|
||||||
day = "0" + now.getDayOfMonth();
|
day = "0" + now.getDayOfMonth();
|
||||||
}else {
|
}else {
|
||||||
day = Integer.toString(now.getDayOfMonth());
|
day = Integer.toString(now.getDayOfMonth());
|
||||||
|
@ -58,7 +58,7 @@ class NetworkTest {
|
|||||||
void testTag() {
|
void testTag() {
|
||||||
|
|
||||||
// System.out.println(Instant.parse("2018-04-05T07:00:00.00Z").getEpochSecond());
|
// System.out.println(Instant.parse("2018-04-05T07:00:00.00Z").getEpochSecond());
|
||||||
System.out.println(Maths.getDaysScrobbling());
|
System.out.println(URLBuilder.getUserPersonalTags("sarsoo", "rap", 2));
|
||||||
|
|
||||||
// System.out.println(url);
|
// System.out.println(url);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class Getter {
|
|||||||
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
|
||||||
Node node = doc.getChildNodes().item(0).getFirstChild();
|
Node node = doc.getChildNodes().item(0).getFirstChild();
|
||||||
NamedNodeMap var = node.getAttributes();
|
NamedNodeMap var = node.getAttributes();
|
||||||
// System.out.println(var.getNamedItem("total").getNodeValue());
|
// System.out.println(var.getNamedItem("total").getNodeValue());
|
||||||
// if (scrobbles != null)
|
// if (scrobbles != null)
|
||||||
return Integer.parseInt(var.getNamedItem("total").getNodeValue());
|
return Integer.parseInt(var.getNamedItem("total").getNodeValue());
|
||||||
}
|
}
|
||||||
@ -82,8 +82,27 @@ public class Getter {
|
|||||||
public static FMObjList getUserTag(String username, String tag) {
|
public static FMObjList getUserTag(String username, String tag) {
|
||||||
String url = URLBuilder.getUserPersonalTags(username, tag);
|
String url = URLBuilder.getUserPersonalTags(username, tag);
|
||||||
Document doc = Network.getResponse(url);
|
Document doc = Network.getResponse(url);
|
||||||
|
|
||||||
if (doc != null) {
|
if (doc != null) {
|
||||||
return Parser.parseUserTagList(doc);
|
int pages = Integer.valueOf(
|
||||||
|
doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
|
||||||
|
|
||||||
|
FMObjList list = Parser.parseUserTagList(doc);
|
||||||
|
|
||||||
|
System.out.println(pages);
|
||||||
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user