From 8b8779b1762fa5896487f5381d188dbbdcf6d979 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Mon, 20 Aug 2018 04:58:33 +0530 Subject: [PATCH] removing catch exception --- .../extractors/YoutubeCommentsExtractor.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java index ec1568e3b..994f19332 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java @@ -9,6 +9,7 @@ import java.net.URLEncoder; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import javax.net.ssl.HttpsURLConnection; @@ -54,15 +55,15 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { } private String getNextPageUrl(JsonNode ajaxJson) throws IOException, ExtractionException { - String continuation; - try { - continuation = ajaxJson.findValue("itemSectionContinuation").get("continuations").findValue("continuation") - .asText(); - } catch (Exception e) { + Optional element = Optional.ofNullable(ajaxJson.findValue("itemSectionContinuation")) + .map(e -> e.get("continuations")).map(e -> e.findValue("continuation")); + + if (element.isPresent()) { + return getNextPageUrl(element.get().asText()); + } else { // no more comments return ""; } - return getNextPageUrl(continuation); } private String getNextPageUrl(String continuation) throws ParsingException {