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
|
||||
/bin/
|
||||
/doc/
|
||||
|
@ -130,6 +130,24 @@ public class URLBuilder {
|
||||
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) {
|
||||
String urlString;
|
||||
try {
|
||||
@ -156,7 +174,7 @@ public class URLBuilder {
|
||||
}
|
||||
|
||||
String day;
|
||||
if(now.getMonthValue() < 10) {
|
||||
if(now.getDayOfMonth() < 10) {
|
||||
day = "0" + now.getDayOfMonth();
|
||||
}else {
|
||||
day = Integer.toString(now.getDayOfMonth());
|
||||
|
@ -58,7 +58,7 @@ class NetworkTest {
|
||||
void testTag() {
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
@ -82,8 +82,27 @@ public class Getter {
|
||||
public static FMObjList getUserTag(String username, String tag) {
|
||||
String url = URLBuilder.getUserPersonalTags(username, tag);
|
||||
Document doc = Network.getResponse(url);
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user