Remove old ways of getting YT dis/likes
* Added additional check for averageRating (in dislikes)
This commit is contained in:
parent
fe432425df
commit
15b98ffdb4
|
@ -337,24 +337,18 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
@Override
|
@Override
|
||||||
public long getLikeCount() throws ParsingException {
|
public long getLikeCount() throws ParsingException {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
String likesString = null;
|
String likesString = "";
|
||||||
try {
|
try {
|
||||||
likesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar")
|
likesString = getVideoPrimaryInfoRenderer()
|
||||||
.getObject("sentimentBarRenderer").getString("tooltip");
|
.getObject("videoActions")
|
||||||
if (likesString != null && likesString.contains("/")) {
|
.getObject("menuRenderer")
|
||||||
likesString = likesString.split("/")[0];
|
.getArray("topLevelButtons")
|
||||||
} else {
|
.getObject(0)
|
||||||
likesString = getVideoPrimaryInfoRenderer()
|
.getObject("toggleButtonRenderer")
|
||||||
.getObject("videoActions")
|
.getObject("defaultText")
|
||||||
.getObject("menuRenderer")
|
.getObject("accessibility")
|
||||||
.getArray("topLevelButtons")
|
.getObject("accessibilityData")
|
||||||
.getObject(0)
|
.getString("label");
|
||||||
.getObject("toggleButtonRenderer")
|
|
||||||
.getObject("defaultText")
|
|
||||||
.getObject("accessibility")
|
|
||||||
.getObject("accessibilityData")
|
|
||||||
.getString("label");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (likesString == null) {
|
if (likesString == null) {
|
||||||
// If this kicks in our button has no content and therefore ratings must be disabled
|
// If this kicks in our button has no content and therefore ratings must be disabled
|
||||||
|
@ -380,27 +374,24 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
public long getDislikeCount() throws ParsingException {
|
public long getDislikeCount() throws ParsingException {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
|
|
||||||
try {
|
// YouTube is "gradually rolling out" removing dislike count
|
||||||
String dislikesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar")
|
|
||||||
.getObject("sentimentBarRenderer").getString("tooltip");
|
|
||||||
if (dislikesString != null && dislikesString.contains("/")) {
|
|
||||||
dislikesString = dislikesString.split("/")[1];
|
|
||||||
return Integer.parseInt(Utils.removeNonDigitCharacters(dislikesString));
|
|
||||||
} else {
|
|
||||||
// Calculate dislike with average rating and like count
|
|
||||||
long likes = getLikeCount();
|
|
||||||
double averageRating = playerResponse.getObject("videoDetails").getDouble("averageRating");
|
|
||||||
|
|
||||||
if (likes != -1 && averageRating > 1) {
|
|
||||||
// If averageRating can't be gathered, it will be 0,
|
|
||||||
// but we also can't divide by 0 so we need > 1
|
|
||||||
return Math.round(likes * ((5 - averageRating) / (averageRating - 1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (final Exception e) {
|
|
||||||
}
|
|
||||||
// Silently fail as YouTube is "gradually rolling out" removing dislike count
|
|
||||||
// https://blog.youtube/news-and-events/update-to-youtube/
|
// https://blog.youtube/news-and-events/update-to-youtube/
|
||||||
|
// Getting dislikes might not work forever
|
||||||
|
|
||||||
|
// Calculate dislike with average rating and like count
|
||||||
|
try {
|
||||||
|
long likes = getLikeCount();
|
||||||
|
double averageRating = playerResponse.getObject("videoDetails").getDouble("averageRating");
|
||||||
|
|
||||||
|
if (likes != -1 && averageRating > 1 && averageRating <= 5) {
|
||||||
|
// If averageRating can't be gathered, it will be 0,
|
||||||
|
// but we also can't divide by 0 so we need > 1
|
||||||
|
return Math.round(likes * ((5 - averageRating) / (averageRating - 1)));
|
||||||
|
}
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
throw new ParsingException("Could not get dislike count", ex);
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue