mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-26 07:27:22 +00:00
likes/dislikes: better fallback management
'.to_i64?' instead of '.to_i64' returns nil rather than raising an exception when it's done on an empty string. In some rare cases, rating can be equal to 5. In this case, the value of player_response[videoDetails][averageRating] is an Int and not a Float.
This commit is contained in:
parent
80a513baa5
commit
ceb1feb350
@ -903,7 +903,7 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
|
|||||||
if likes_button
|
if likes_button
|
||||||
likes_txt = (likes_button["defaultText"]? || likes_button["toggledText"]?)
|
likes_txt = (likes_button["defaultText"]? || likes_button["toggledText"]?)
|
||||||
.try &.dig?("accessibility", "accessibilityData", "label")
|
.try &.dig?("accessibility", "accessibilityData", "label")
|
||||||
likes = likes_txt.as_s.gsub(/\D/, "").to_i64 if likes_txt
|
likes = likes_txt.as_s.gsub(/\D/, "").to_i64? if likes_txt
|
||||||
|
|
||||||
LOGGER.trace("extract_video_info: Found \"likes\" button. Button text is \"#{likes_txt}\"")
|
LOGGER.trace("extract_video_info: Found \"likes\" button. Button text is \"#{likes_txt}\"")
|
||||||
LOGGER.debug("extract_video_info: Likes count is #{likes}") if likes
|
LOGGER.debug("extract_video_info: Likes count is #{likes}") if likes
|
||||||
@ -916,7 +916,7 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
|
|||||||
if dislikes_button
|
if dislikes_button
|
||||||
dislikes_txt = (dislikes_button["defaultText"] || dislikes_button["toggledText"]?)
|
dislikes_txt = (dislikes_button["defaultText"] || dislikes_button["toggledText"]?)
|
||||||
.try &.dig?("accessibility", "accessibilityData", "label")
|
.try &.dig?("accessibility", "accessibilityData", "label")
|
||||||
dislikes = dislikes_txt.as_s.gsub(/\D/, "").to_i64 if dislikes_txt
|
dislikes = dislikes_txt.as_s.gsub(/\D/, "").to_i64? if dislikes_txt
|
||||||
|
|
||||||
LOGGER.trace("extract_video_info: Found \"dislikes\" button. Button text is \"#{dislikes_txt}\"")
|
LOGGER.trace("extract_video_info: Found \"dislikes\" button. Button text is \"#{dislikes_txt}\"")
|
||||||
LOGGER.debug("extract_video_info: Dislikes count is #{dislikes}") if dislikes
|
LOGGER.debug("extract_video_info: Dislikes count is #{dislikes}") if dislikes
|
||||||
@ -924,7 +924,7 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
|
|||||||
end
|
end
|
||||||
|
|
||||||
if likes && likes != 0_i64 && (!dislikes || dislikes == 0_i64)
|
if likes && likes != 0_i64 && (!dislikes || dislikes == 0_i64)
|
||||||
if rating = player_response.dig?("videoDetails", "averageRating").try &.as_f
|
if rating = player_response.dig?("videoDetails", "averageRating").try { |x| x.as_i64? || x.as_f? }
|
||||||
dislikes = (likes * ((5 - rating)/(rating - 1))).round.to_i64
|
dislikes = (likes * ((5 - rating)/(rating - 1))).round.to_i64
|
||||||
LOGGER.debug("extract_video_info: Dislikes count (using fallback method) is #{dislikes}")
|
LOGGER.debug("extract_video_info: Dislikes count (using fallback method) is #{dislikes}")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user