fix: handle new like count view model
This commit is contained in:
parent
eac850ca10
commit
64e675944d
|
@ -399,6 +399,23 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
.getObject("menuRenderer")
|
.getObject("menuRenderer")
|
||||||
.getArray("topLevelButtons");
|
.getArray("topLevelButtons");
|
||||||
|
|
||||||
|
// New viewModel data structure
|
||||||
|
likesString = topLevelButtons.stream()
|
||||||
|
.filter(JsonObject.class::isInstance)
|
||||||
|
.map(JsonObject.class::cast)
|
||||||
|
.map(button -> button.getObject("segmentedLikeDislikeButtonViewModel")
|
||||||
|
.getObject("likeButtonViewModel")
|
||||||
|
.getObject("likeButtonViewModel")
|
||||||
|
.getObject("toggleButtonViewModel")
|
||||||
|
.getObject("toggleButtonViewModel")
|
||||||
|
.getObject("defaultButtonViewModel")
|
||||||
|
.getObject("buttonViewModel")
|
||||||
|
.getString("accessibilityText")
|
||||||
|
)
|
||||||
|
.filter(s -> !isNullOrEmpty(s))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if (likesString == null) {
|
||||||
// Try first with the new video actions buttons data structure
|
// Try first with the new video actions buttons data structure
|
||||||
JsonObject likeToggleButtonRenderer = topLevelButtons.stream()
|
JsonObject likeToggleButtonRenderer = topLevelButtons.stream()
|
||||||
.filter(JsonObject.class::isInstance)
|
.filter(JsonObject.class::isInstance)
|
||||||
|
@ -425,7 +442,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
.filter(JsonObject.class::isInstance)
|
.filter(JsonObject.class::isInstance)
|
||||||
.map(JsonObject.class::cast)
|
.map(JsonObject.class::cast)
|
||||||
.map(topLevelButton -> topLevelButton.getObject("toggleButtonRenderer"))
|
.map(topLevelButton -> topLevelButton.getObject("toggleButtonRenderer"))
|
||||||
.filter(toggleButtonRenderer -> toggleButtonRenderer.getString("targetId")
|
.filter(toggleButtonRenderer -> toggleButtonRenderer
|
||||||
|
.getString("targetId")
|
||||||
.equalsIgnoreCase("watch-like")
|
.equalsIgnoreCase("watch-like")
|
||||||
|| toggleButtonRenderer.getObject("defaultIcon")
|
|| toggleButtonRenderer.getObject("defaultIcon")
|
||||||
.getString("iconType")
|
.getString("iconType")
|
||||||
|
@ -451,14 +469,16 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
.getString("label");
|
.getString("label");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last method: use the defaultText's accessibility data, which contains the exact like
|
// Last method: use the defaultText's accessibility data, which contains the exact
|
||||||
// count too, except when it is equal to 0, where a localized string is returned instead
|
// like count too, except when it is equal to 0, where a localized string is
|
||||||
|
// returned instead
|
||||||
if (likesString == null) {
|
if (likesString == null) {
|
||||||
likesString = likeToggleButtonRenderer.getObject("defaultText")
|
likesString = likeToggleButtonRenderer.getObject("defaultText")
|
||||||
.getObject("accessibility")
|
.getObject("accessibility")
|
||||||
.getObject("accessibilityData")
|
.getObject("accessibilityData")
|
||||||
.getString("label");
|
.getString("label");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If ratings are allowed and the likes string is null, it means that we couldn't
|
// If ratings are allowed and the likes string is null, it means that we couldn't
|
||||||
// extract the (real) like count from accessibility data
|
// extract the (real) like count from accessibility data
|
||||||
|
|
Loading…
Reference in New Issue