X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FReddit.java;h=c89feff671e1f963948f14780e3cf725d9f1220f;hb=ff49bc765089d37d20ad950350d02876435c73f8;hp=f5ae131474c83ab32c050cbbf1a5ce9dc1fd7cd0;hpb=aacd7f07ac5e2b4bb4ef0dfef48ec272b16900fa;p=gofetch.git diff --git a/src/be/nikiroo/gofetch/support/Reddit.java b/src/be/nikiroo/gofetch/support/Reddit.java index f5ae131..c89feff 100644 --- a/src/be/nikiroo/gofetch/support/Reddit.java +++ b/src/be/nikiroo/gofetch/support/Reddit.java @@ -184,16 +184,11 @@ public class Reddit extends BasicSupport { @Override protected List getCommentCommentPosts(Document doc, Element container) { + List elements = new LinkedList(); for (Element el : container.children()) { - elements.addAll(el.getElementsByClass("jHfOJm")); - - } - - if (elements.isEmpty()) { - for (Element el : container.children()) { - elements.addAll(el.getElementsByClass("Comment")); - } + // elements.addAll(el.getElementsByClass("jHfOJm")); + elements.addAll(el.getElementsByClass("emJXdb")); } return elements; @@ -203,8 +198,6 @@ public class Reddit extends BasicSupport { protected String getCommentId(Element post) { int level = 1; Elements els = post.getElementsByClass("imyGpC"); - if (els.isEmpty()) - els.addAll(post.getElementsByClass("emJXdb")); if (!els.isEmpty()) { String l = els.first().text().trim().replace("level ", ""); @@ -271,18 +264,22 @@ public class Reddit extends BasicSupport { List comments = new LinkedList(); Map lastOfLevel = new HashMap(); - for (Comment c : story.getComments()) { - int level = Integer.parseInt(c.getId()); - lastOfLevel.put(level, c); - if (level <= 1) { - comments.add(c); - } else { - Comment parent = lastOfLevel.get(level - 1); - if (parent != null) { - parent.add(c); - } else { - // bad data + if (!story.getComments().isEmpty()) { + // comments are saved under a main ID (which is a copy of comment 1) + // TODO: fix the cause instead of working around it here + for (Comment c : story.getComments().get(0)) { + int level = Integer.parseInt(c.getId()); + lastOfLevel.put(level, c); + if (level <= 1) { comments.add(c); + } else { + Comment parent = lastOfLevel.get(level - 1); + if (parent != null) { + parent.add(c); + } else { + // bad data + comments.add(c); + } } } }