summaryrefslogtreecommitdiffstats
path: root/src/invidious.cr
diff options
context:
space:
mode:
authorleonklingele <5585491+leonklingele@users.noreply.github.com>2019-07-31 16:48:45 +0200
committerOmar Roth <omarroth@protonmail.com>2019-07-31 09:48:45 -0500
commitf99a7b2a8c8c480f175f15155e8616cdefb59300 (patch)
treed965969bbf911182facc798d78ede2345023712c /src/invidious.cr
parentec36c69984e79d3639a1fda35212a1ad01e05b0c (diff)
downloadinvidious-f99a7b2a8c8c480f175f15155e8616cdefb59300.tar.gz
invidious-f99a7b2a8c8c480f175f15155e8616cdefb59300.tar.bz2
invidious-f99a7b2a8c8c480f175f15155e8616cdefb59300.zip
Fix engagement for zero-view videos (#654)
Division by zero resulted in 'NaN'. Fixes https://github.com/omarroth/invidious/issues/653.
Diffstat (limited to 'src/invidious.cr')
-rw-r--r--src/invidious.cr6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 315363d7..c43af729 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -521,7 +521,11 @@ get "/watch" do |env|
end
rating = video.info["avg_rating"].to_f64
- engagement = ((video.dislikes.to_f + video.likes.to_f)/video.views * 100)
+ if video.views > 0
+ engagement = ((video.dislikes.to_f + video.likes.to_f)/video.views * 100)
+ else
+ engagement = 0
+ end
playability_status = video.player_response["playabilityStatus"]?
if playability_status && playability_status["status"] == "LIVE_STREAM_OFFLINE" && !video.premiere_timestamp