From d22c9bf5ead578939d68886cec71cdc2a912edd6 Mon Sep 17 00:00:00 2001 From: soloturn Date: Sun, 24 Apr 2022 19:28:46 +0200 Subject: [PATCH] reddit, report exception in loop instead of throwing it. fixes #60, #83. --- .../ripme/ripper/rippers/RedditRipper.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java index 4aabe559..f03511a1 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java @@ -112,14 +112,18 @@ public class RedditRipper extends AlbumRipper { } children = data.getJSONArray("children"); for (int j = 0; j < children.length(); j++) { - parseJsonChild(children.getJSONObject(j)); + try { + parseJsonChild(children.getJSONObject(j)); - if (children.getJSONObject(j).getString("kind").equals("t3") && - children.getJSONObject(j).getJSONObject("data").getBoolean("is_self") - ) { - URL selfPostURL = new URL(children.getJSONObject(j).getJSONObject("data").getString("url")); - System.out.println(selfPostURL.toExternalForm()); - saveText(getJsonArrayFromURL(getJsonURL(selfPostURL))); + if (children.getJSONObject(j).getString("kind").equals("t3") && + children.getJSONObject(j).getJSONObject("data").getBoolean("is_self") + ) { + URL selfPostURL = new URL(children.getJSONObject(j).getJSONObject("data").getString("url")); + System.out.println(selfPostURL.toExternalForm()); + saveText(getJsonArrayFromURL(getJsonURL(selfPostURL))); + } + } catch (Exception e) { + LOGGER.debug("at index " + i + ", for this data: " + data.toString() + e); } } if (data.has("after") && !data.isNull("after")) { @@ -316,15 +320,18 @@ public class RedditRipper extends AlbumRipper { for (int i = 0; i < comments.length(); i++) { JSONObject data = comments.getJSONObject(i).getJSONObject("data"); - ContainerTag commentDiv = + try { + ContainerTag commentDiv = div( span(data.getString("author")).withClasses("author", iff(data.getString("author").equals(author), "op")), a(new Date((long) data.getInt("created") * 1000).toString()).withHref("#" + data.getString("name")) ).withClass("thing comment").withId(data.getString("name")) .with(rawHtml(Jsoup.parse(data.getString("body_html")).text())); - - getNestedComments(data, commentDiv, author); - commentsDiv.with(commentDiv); + getNestedComments(data, commentDiv, author); + commentsDiv.with(commentDiv); + } catch (Exception e) { + LOGGER.debug("at index " + i + ", for this data: " + data.toString() + e); + } } return commentsDiv; }