Skip to content

Commit 16d693e

Browse files
authored
Merge branch 'master' into serviceByUrlNPEfix
2 parents 9eff182 + 8425936 commit 16d693e

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsInfoItemExtractor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
44
import org.schabi.newpipe.extractor.exceptions.ParsingException;
55
import org.schabi.newpipe.extractor.utils.JsonUtils;
6+
import org.schabi.newpipe.extractor.utils.Utils;
67

78
import com.grack.nanojson.JsonArray;
89
import com.grack.nanojson.JsonObject;
@@ -62,7 +63,9 @@ public Integer getLikeCount() throws ParsingException {
6263
@Override
6364
public String getCommentText() throws ParsingException {
6465
try {
65-
return YoutubeCommentsExtractor.getYoutubeText(JsonUtils.getObject(json, "contentText"));
66+
String commentText = YoutubeCommentsExtractor.getYoutubeText(JsonUtils.getObject(json, "contentText"));
67+
// youtube adds U+FEFF in some comments. eg. https://www.youtube.com/watch?v=Nj4F63E59io<feff>
68+
return Utils.removeUTF8BOM(commentText);
6669
} catch (Exception e) {
6770
throw new ParsingException("Could not get comment text", e);
6871
}

extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.schabi.newpipe.extractor.utils;
22

3-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
4-
53
import java.io.UnsupportedEncodingException;
64
import java.net.MalformedURLException;
75
import java.net.URL;
86
import java.net.URLDecoder;
97
import java.util.List;
108

9+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
10+
1111
public class Utils {
1212

1313
private Utils() {
@@ -120,4 +120,14 @@ public static URL stringToURL(String url) throws MalformedURLException {
120120
throw e;
121121
}
122122
}
123+
124+
public static String removeUTF8BOM(String s) {
125+
if (s.startsWith("\uFEFF")) {
126+
s = s.substring(1);
127+
}
128+
if (s.endsWith("\uFEFF")) {
129+
s = s.substring(0, s.length()-1);
130+
}
131+
return s;
132+
}
123133
}

0 commit comments

Comments
 (0)