From 9eff18252b4e0912fb0be7b616588b806ec31805 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Thu, 28 Feb 2019 22:55:18 +0530 Subject: [PATCH 1/2] fix npe in fetching service by url --- .../java/org/schabi/newpipe/extractor/StreamingService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index 86bd9d1f8..26e84da97 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -308,11 +308,11 @@ public abstract class StreamingService { LinkHandlerFactory cH = getChannelLHFactory(); LinkHandlerFactory pH = getPlaylistLHFactory(); - if (sH.acceptUrl(url)) { + if (sH != null && sH.acceptUrl(url)) { return LinkType.STREAM; - } else if (cH.acceptUrl(url)) { + } else if (cH != null && cH.acceptUrl(url)) { return LinkType.CHANNEL; - } else if (pH.acceptUrl(url)) { + } else if (pH != null && pH.acceptUrl(url)) { return LinkType.PLAYLIST; } else { return LinkType.NONE; From 72262707bf250620f7d4221cc4e342afd4934235 Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Fri, 1 Mar 2019 00:10:29 +0530 Subject: [PATCH 2/2] fixed youtube comment utf8 bom --- .../YoutubeCommentsInfoItemExtractor.java | 5 ++++- .../org/schabi/newpipe/extractor/utils/Utils.java | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java index 471cafd9c..1d447bd55 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube.extractors; import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.JsonUtils; +import org.schabi.newpipe.extractor.utils.Utils; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; @@ -62,7 +63,9 @@ public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtract @Override public String getCommentText() throws ParsingException { try { - return YoutubeCommentsExtractor.getYoutubeText(JsonUtils.getObject(json, "contentText")); + String commentText = YoutubeCommentsExtractor.getYoutubeText(JsonUtils.getObject(json, "contentText")); + // youtube adds U+FEFF in some comments. eg. https://www.youtube.com/watch?v=Nj4F63E59io + return Utils.removeUTF8BOM(commentText); } catch (Exception e) { throw new ParsingException("Could not get comment text", e); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java index d4b8db432..fde334fa7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java @@ -1,13 +1,13 @@ package org.schabi.newpipe.extractor.utils; -import org.schabi.newpipe.extractor.exceptions.ParsingException; - import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.util.List; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + public class Utils { private Utils() { @@ -120,4 +120,14 @@ public class Utils { throw e; } } + + public static String removeUTF8BOM(String s) { + if (s.startsWith("\uFEFF")) { + s = s.substring(1); + } + if (s.endsWith("\uFEFF")) { + s = s.substring(0, s.length()-1); + } + return s; + } } \ No newline at end of file