Skip to content

Commit aa4f03a

Browse files
authored
Merge pull request #144 from yausername/fixCommentUrl
fix comment url
2 parents e7e411d + a2735c4 commit aa4f03a

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ public final LinkType getLinkTypeByUrl(String url) throws ParsingException {
308308
LinkHandlerFactory cH = getChannelLHFactory();
309309
LinkHandlerFactory pH = getPlaylistLHFactory();
310310

311-
if (sH.acceptUrl(url)) {
311+
if (sH != null && sH.acceptUrl(url)) {
312312
return LinkType.STREAM;
313-
} else if (cH.acceptUrl(url)) {
313+
} else if (cH != null && cH.acceptUrl(url)) {
314314
return LinkType.CHANNEL;
315-
} else if (pH.acceptUrl(url)) {
315+
} else if (pH != null && pH.acceptUrl(url)) {
316316
return LinkType.PLAYLIST;
317317
} else {
318318
return LinkType.NONE;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ public InfoItemsPage<CommentsInfoItem> getPage(String pageUrl) throws IOExceptio
107107
throw new ParsingException("Could not parse json data for comments", e);
108108
}
109109
CommentsInfoItemsCollector collector = new CommentsInfoItemsCollector(getServiceId());
110-
collectCommentsFrom(collector, ajaxJson, pageUrl);
110+
collectCommentsFrom(collector, ajaxJson);
111111
return new InfoItemsPage<>(collector, getNextPageUrl(ajaxJson));
112112
}
113113

114-
private void collectCommentsFrom(CommentsInfoItemsCollector collector, JsonObject ajaxJson, String pageUrl) throws ParsingException {
114+
private void collectCommentsFrom(CommentsInfoItemsCollector collector, JsonObject ajaxJson) throws ParsingException {
115115

116116
JsonArray contents;
117117
try {
@@ -130,7 +130,7 @@ private void collectCommentsFrom(CommentsInfoItemsCollector collector, JsonObjec
130130

131131
for(Object c: comments) {
132132
if(c instanceof JsonObject) {
133-
CommentsInfoItemExtractor extractor = new YoutubeCommentsInfoItemExtractor((JsonObject) c, pageUrl);
133+
CommentsInfoItemExtractor extractor = new YoutubeCommentsInfoItemExtractor((JsonObject) c, getUrl());
134134
collector.commit(extractor);
135135
}
136136
}

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)