Fix for requested changes.
This commit is contained in:
parent
656b7c1cd9
commit
22f71b010c
1 changed files with 11 additions and 5 deletions
|
@ -46,6 +46,9 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||||
private Optional<Boolean> optCommentsDisabled = Optional.empty();
|
private Optional<Boolean> optCommentsDisabled = Optional.empty();
|
||||||
|
/**
|
||||||
|
* The second ajax <b>/next</b> response.
|
||||||
|
*/
|
||||||
private JsonObject ajaxJson;
|
private JsonObject ajaxJson;
|
||||||
|
|
||||||
public YoutubeCommentsExtractor(
|
public YoutubeCommentsExtractor(
|
||||||
|
@ -279,14 +282,17 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCommentsCount() throws ExtractionException {
|
public int getCommentsCount() throws ExtractionException {
|
||||||
final JsonObject commentsHeaderRenderer = ajaxJson
|
final JsonObject countText = ajaxJson
|
||||||
.getArray("onResponseReceivedEndpoints").getObject(0)
|
.getArray("onResponseReceivedEndpoints").getObject(0)
|
||||||
.getObject("reloadContinuationItemsCommand")
|
.getObject("reloadContinuationItemsCommand")
|
||||||
.getArray("continuationItems").getObject(0)
|
.getArray("continuationItems").getObject(0)
|
||||||
.getObject("commentsHeaderRenderer");
|
.getObject("commentsHeaderRenderer")
|
||||||
|
.getObject("countText");
|
||||||
|
|
||||||
final String text = getTextFromObject(commentsHeaderRenderer.getObject("countText"));
|
try {
|
||||||
|
return Integer.parseInt(Utils.removeNonDigitCharacters(getTextFromObject(countText)));
|
||||||
return Integer.parseInt(Utils.removeNonDigitCharacters(text));
|
} catch (final Exception e) {
|
||||||
|
throw new ExtractionException("Unable to get comments count", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue