From b6bc783e3e98ccc2f14485909b687d31dc4c02d4 Mon Sep 17 00:00:00 2001 From: aj Date: Tue, 17 Apr 2018 14:21:57 -0700 Subject: [PATCH] added handling for pages in tags --- fmframework/.gitignore | 1 + .../sarsoo/fmframework/net/URLBuilder.java | 20 +++++++++++++++- .../sarsoo/fmframework/test/NetworkTest.java | 2 +- .../src/sarsoo/fmframework/util/Getter.java | 23 +++++++++++++++++-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/fmframework/.gitignore b/fmframework/.gitignore index 660f56d..591c73f 100644 --- a/fmframework/.gitignore +++ b/fmframework/.gitignore @@ -1,2 +1,3 @@ /.project /bin/ +/doc/ diff --git a/fmframework/src/sarsoo/fmframework/net/URLBuilder.java b/fmframework/src/sarsoo/fmframework/net/URLBuilder.java index 5a31c30..59e06ec 100644 --- a/fmframework/src/sarsoo/fmframework/net/URLBuilder.java +++ b/fmframework/src/sarsoo/fmframework/net/URLBuilder.java @@ -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()); diff --git a/fmframework/src/sarsoo/fmframework/test/NetworkTest.java b/fmframework/src/sarsoo/fmframework/test/NetworkTest.java index aae7100..4f31d74 100644 --- a/fmframework/src/sarsoo/fmframework/test/NetworkTest.java +++ b/fmframework/src/sarsoo/fmframework/test/NetworkTest.java @@ -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); } diff --git a/fmframework/src/sarsoo/fmframework/util/Getter.java b/fmframework/src/sarsoo/fmframework/util/Getter.java index 1196543..4374aaf 100644 --- a/fmframework/src/sarsoo/fmframework/util/Getter.java +++ b/fmframework/src/sarsoo/fmframework/util/Getter.java @@ -72,7 +72,7 @@ public class Getter { 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()); + // System.out.println(var.getNamedItem("total").getNodeValue()); // if (scrobbles != null) return Integer.parseInt(var.getNamedItem("total").getNodeValue()); } @@ -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; }