From 99a0134b1cf031f96a9bf6fedda627bcc69fa957 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Fri, 19 Oct 2018 19:33:36 +0530 Subject: [PATCH] removed unchecked cast --- .../extractors/YoutubeCommentsExtractor.java | 14 +++---- .../YoutubeCommentsInfoItemExtractor.java | 24 ++++++------ .../newpipe/extractor/utils/JsonUtils.java | 39 +++++++++++++++++++ 3 files changed, 57 insertions(+), 20 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 cede2a4d5..dee0b21c3 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 @@ -62,7 +62,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { JsonArray arr; try { - arr = (JsonArray) JsonUtils.getValue(ajaxJson, "response.continuationContents.commentSectionContinuation.continuations"); + arr = JsonUtils.getArray(ajaxJson, "response.continuationContents.commentSectionContinuation.continuations"); } catch (Exception e) { return ""; } @@ -71,7 +71,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { } String continuation; try { - continuation = (String) JsonUtils.getValue(arr.getObject(0), "nextContinuationData.continuation"); + continuation = JsonUtils.getString(arr.getObject(0), "nextContinuationData.continuation"); } catch (Exception e) { return ""; } @@ -111,7 +111,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { JsonArray contents; try { - contents = (JsonArray) JsonUtils.getValue(ajaxJson, "response.continuationContents.commentSectionContinuation.items"); + contents = JsonUtils.getArray(ajaxJson, "response.continuationContents.commentSectionContinuation.items"); }catch(Exception e) { //no comments return; @@ -135,7 +135,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { private void fetchTitle(JsonArray contents) { if(null == title) { try { - title = getYoutubeText((JsonObject) JsonUtils.getValue(contents.getObject(0), "commentThreadRenderer.commentTargetTitle")); + title = getYoutubeText(JsonUtils.getObject(contents.getObject(0), "commentThreadRenderer.commentTargetTitle")); } catch (Exception e) { title = "Youtube Comments"; } @@ -196,13 +196,13 @@ public class YoutubeCommentsExtractor extends CommentsExtractor { public static String getYoutubeText(@Nonnull JsonObject object) throws ParsingException { try { - return (String) JsonUtils.getValue(object, "simpleText"); + return JsonUtils.getString(object, "simpleText"); } catch (Exception e1) { try { - JsonArray arr = (JsonArray) JsonUtils.getValue(object, "runs"); + JsonArray arr = JsonUtils.getArray(object, "runs"); String result = ""; for(int i=0; i getValues(@Nonnull JsonArray array, @Nonnull String path) throws ParsingException {