File tree Expand file tree Collapse file tree
extractor/src/main/java/org/schabi/newpipe/extractor
services/youtube/extractors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import org .schabi .newpipe .extractor .comments .CommentsInfoItemExtractor ;
44import org .schabi .newpipe .extractor .exceptions .ParsingException ;
55import org .schabi .newpipe .extractor .utils .JsonUtils ;
6+ import org .schabi .newpipe .extractor .utils .Utils ;
67
78import com .grack .nanojson .JsonArray ;
89import 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 }
Original file line number Diff line number Diff line change 11package org .schabi .newpipe .extractor .utils ;
22
3- import org .schabi .newpipe .extractor .exceptions .ParsingException ;
4-
53import java .io .UnsupportedEncodingException ;
64import java .net .MalformedURLException ;
75import java .net .URL ;
86import java .net .URLDecoder ;
97import java .util .List ;
108
9+ import org .schabi .newpipe .extractor .exceptions .ParsingException ;
10+
1111public 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}
You can’t perform that action at this time.
0 commit comments