Skip to content

Commit

Permalink
Fix for requested changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMasterK committed Feb 11, 2022
1 parent df708a7 commit 0779c33
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private Optional<Boolean> optCommentsDisabled = Optional.empty();
/**
* The second ajax <b>/next</b> response.
*/
private JsonObject ajaxJson;

public YoutubeCommentsExtractor(
Expand Down Expand Up @@ -260,14 +263,17 @@ public boolean isCommentsDisabled() throws ExtractionException {

@Override
public int getCommentsCount() throws ExtractionException {
final JsonObject commentsHeaderRenderer = ajaxJson
final JsonObject countText = ajaxJson
.getArray("onResponseReceivedEndpoints").getObject(0)
.getObject("reloadContinuationItemsCommand")
.getArray("continuationItems").getObject(0)
.getObject("commentsHeaderRenderer");

final String text = getTextFromObject(commentsHeaderRenderer.getObject("countText"));
.getObject("commentsHeaderRenderer")
.getObject("countText");

return Integer.parseInt(Utils.removeNonDigitCharacters(text));
try {
return Integer.parseInt(Utils.removeNonDigitCharacters(getTextFromObject(countText)));
} catch (final Exception e) {
throw new ExtractionException("Unable to get comments count", e);
}
}
}

0 comments on commit 0779c33

Please sign in to comment.