Skip to content

Commit e8e9e6c

Browse files
committed
Fix comment reply continuations.
1 parent 666b459 commit e8e9e6c

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfoItemsCollector.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ public void commit(CommentsInfoItemExtractor extractor) {
112112
}
113113

114114
public List<CommentsInfoItem> getCommentsInfoItemList() {
115-
List<CommentsInfoItem> siiList = new ArrayList<>();
116-
for (InfoItem ii : super.getItems()) {
117-
if (ii instanceof CommentsInfoItem) {
118-
siiList.add((CommentsInfoItem) ii);
119-
}
120-
}
121-
return siiList;
115+
return new ArrayList<>(super.getItems());
122116
}
123117
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private String findInitialCommentsToken() throws ExtractionException {
101101

102102
if (itemSectionRenderer.isPresent()) {
103103
token = JsonUtils.getString(((JsonObject) itemSectionRenderer.get())
104-
.getObject("itemSectionRenderer").getArray("contents").getObject(0),
104+
.getObject("itemSectionRenderer").getArray("contents").getObject(0),
105105
"continuationItemRenderer.continuationEndpoint.continuationCommand.token");
106106
} else {
107107
token = null;
@@ -140,10 +140,13 @@ private Page getNextPage(@Nonnull final JsonObject ajaxJson) throws ExtractionEx
140140
return null;
141141
}
142142

143+
final JsonObject continuationItemRenderer = jsonArray.getObject(jsonArray.size() - 1).getObject("continuationItemRenderer");
144+
145+
final String jsonPath = continuationItemRenderer.has("button") ? "button.buttonRenderer.command.continuationCommand.token" : "continuationEndpoint.continuationCommand.token";
146+
143147
final String continuation;
144148
try {
145-
continuation = JsonUtils.getString(jsonArray.getObject(jsonArray.size() - 1),
146-
"continuationItemRenderer.continuationEndpoint.continuationCommand.token");
149+
continuation = JsonUtils.getString(continuationItemRenderer, jsonPath);
147150
} catch (final Exception e) {
148151
return null;
149152
}
@@ -167,7 +170,7 @@ public InfoItemsPage<CommentsInfoItem> getPage(final Page page)
167170

168171
final Localization localization = getExtractorLocalization();
169172
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(localization,
170-
getExtractorContentCountry())
173+
getExtractorContentCountry())
171174
.value("continuation", page.getId())
172175
.done())
173176
.getBytes(UTF_8);
@@ -236,7 +239,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
236239
throws IOException, ExtractionException {
237240
final Localization localization = getExtractorLocalization();
238241
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(localization,
239-
getExtractorContentCountry())
242+
getExtractorContentCountry())
240243
.value("videoId", getId())
241244
.done())
242245
.getBytes(UTF_8);

0 commit comments

Comments
 (0)