fix: handle new like count view model
This commit is contained in:
parent
eac850ca10
commit
64e675944d
|
@ -399,19 +399,36 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
.getObject("menuRenderer")
|
.getObject("menuRenderer")
|
||||||
.getArray("topLevelButtons");
|
.getArray("topLevelButtons");
|
||||||
|
|
||||||
// Try first with the new video actions buttons data structure
|
// New viewModel data structure
|
||||||
JsonObject likeToggleButtonRenderer = topLevelButtons.stream()
|
likesString = topLevelButtons.stream()
|
||||||
.filter(JsonObject.class::isInstance)
|
.filter(JsonObject.class::isInstance)
|
||||||
.map(JsonObject.class::cast)
|
.map(JsonObject.class::cast)
|
||||||
.map(button -> button.getObject("segmentedLikeDislikeButtonRenderer")
|
.map(button -> button.getObject("segmentedLikeDislikeButtonViewModel")
|
||||||
.getObject("likeButton")
|
.getObject("likeButtonViewModel")
|
||||||
.getObject("toggleButtonRenderer"))
|
.getObject("likeButtonViewModel")
|
||||||
.filter(toggleButtonRenderer -> !isNullOrEmpty(toggleButtonRenderer))
|
.getObject("toggleButtonViewModel")
|
||||||
|
.getObject("toggleButtonViewModel")
|
||||||
|
.getObject("defaultButtonViewModel")
|
||||||
|
.getObject("buttonViewModel")
|
||||||
|
.getString("accessibilityText")
|
||||||
|
)
|
||||||
|
.filter(s -> !isNullOrEmpty(s))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
if (likesString == null) {
|
||||||
|
// Try first with the new video actions buttons data structure
|
||||||
|
JsonObject likeToggleButtonRenderer = topLevelButtons.stream()
|
||||||
|
.filter(JsonObject.class::isInstance)
|
||||||
|
.map(JsonObject.class::cast)
|
||||||
|
.map(button -> button.getObject("segmentedLikeDislikeButtonRenderer")
|
||||||
|
.getObject("likeButton")
|
||||||
|
.getObject("toggleButtonRenderer"))
|
||||||
|
.filter(toggleButtonRenderer -> !isNullOrEmpty(toggleButtonRenderer))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
// Use the old video actions buttons data structure if the new one isn't returned
|
// Use the old video actions buttons data structure if the new one isn't returned
|
||||||
if (likeToggleButtonRenderer == null) {
|
if (likeToggleButtonRenderer == null) {
|
||||||
/*
|
/*
|
||||||
In the old video actions buttons data structure, there are 3 ways to detect whether
|
In the old video actions buttons data structure, there are 3 ways to detect whether
|
||||||
a button is the like button, using its toggleButtonRenderer:
|
a button is the like button, using its toggleButtonRenderer:
|
||||||
|
@ -421,43 +438,46 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
toggleButtonRenderer.toggleButtonSupportedData.toggleButtonIdData.id
|
toggleButtonRenderer.toggleButtonSupportedData.toggleButtonIdData.id
|
||||||
is equal to TOGGLE_BUTTON_ID_TYPE_LIKE.
|
is equal to TOGGLE_BUTTON_ID_TYPE_LIKE.
|
||||||
*/
|
*/
|
||||||
likeToggleButtonRenderer = topLevelButtons.stream()
|
likeToggleButtonRenderer = topLevelButtons.stream()
|
||||||
.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
|
||||||
.equalsIgnoreCase("watch-like")
|
.getString("targetId")
|
||||||
|| toggleButtonRenderer.getObject("defaultIcon")
|
.equalsIgnoreCase("watch-like")
|
||||||
.getString("iconType")
|
|| toggleButtonRenderer.getObject("defaultIcon")
|
||||||
.equalsIgnoreCase("LIKE")
|
.getString("iconType")
|
||||||
|| toggleButtonRenderer.getObject("toggleButtonSupportedData")
|
.equalsIgnoreCase("LIKE")
|
||||||
.getObject("toggleButtonIdData")
|
|| toggleButtonRenderer.getObject("toggleButtonSupportedData")
|
||||||
.getString("id")
|
.getObject("toggleButtonIdData")
|
||||||
.equalsIgnoreCase("TOGGLE_BUTTON_ID_TYPE_LIKE"))
|
.getString("id")
|
||||||
.findFirst()
|
.equalsIgnoreCase("TOGGLE_BUTTON_ID_TYPE_LIKE"))
|
||||||
.orElseThrow(() -> new ParsingException(
|
.findFirst()
|
||||||
"The like button is missing even though ratings are enabled"));
|
.orElseThrow(() -> new ParsingException(
|
||||||
}
|
"The like button is missing even though ratings are enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
// Use one of the accessibility strings available (this one has the same path as the
|
// Use one of the accessibility strings available (this one has the same path as the
|
||||||
// one used for comments' like count extraction)
|
// one used for comments' like count extraction)
|
||||||
likesString = likeToggleButtonRenderer.getObject("accessibilityData")
|
likesString = likeToggleButtonRenderer.getObject("accessibilityData")
|
||||||
.getObject("accessibilityData")
|
|
||||||
.getString("label");
|
|
||||||
|
|
||||||
// Use the other accessibility string available which contains the exact like count
|
|
||||||
if (likesString == null) {
|
|
||||||
likesString = likeToggleButtonRenderer.getObject("accessibility")
|
|
||||||
.getString("label");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Last method: use the defaultText's accessibility data, which contains the exact like
|
|
||||||
// count too, except when it is equal to 0, where a localized string is returned instead
|
|
||||||
if (likesString == null) {
|
|
||||||
likesString = likeToggleButtonRenderer.getObject("defaultText")
|
|
||||||
.getObject("accessibility")
|
|
||||||
.getObject("accessibilityData")
|
.getObject("accessibilityData")
|
||||||
.getString("label");
|
.getString("label");
|
||||||
|
|
||||||
|
// Use the other accessibility string available which contains the exact like count
|
||||||
|
if (likesString == null) {
|
||||||
|
likesString = likeToggleButtonRenderer.getObject("accessibility")
|
||||||
|
.getString("label");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last method: use the defaultText's accessibility data, which contains the exact
|
||||||
|
// like count too, except when it is equal to 0, where a localized string is
|
||||||
|
// returned instead
|
||||||
|
if (likesString == null) {
|
||||||
|
likesString = likeToggleButtonRenderer.getObject("defaultText")
|
||||||
|
.getObject("accessibility")
|
||||||
|
.getObject("accessibilityData")
|
||||||
|
.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
|
||||||
|
|
Loading…
Reference in New Issue