From 8f57388cd315a95fe0addfcd7894b9b1b368762d Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 12 Jan 2019 11:56:07 -0600 Subject: [PATCH] Fix average rating where likes and dislikes are null --- src/invidious/videos.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index b7955eb4..b4705daa 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -649,7 +649,9 @@ def fetch_video(id, proxies, region) dislikes = dislikes.try &.content.delete(",").try &.to_i? dislikes ||= 0 - info["avg_rating"] = "#{(likes.to_f/(likes.to_f + dislikes.to_f) * 4 + 1)}" + avg_rating = (likes.to_f/(likes.to_f + dislikes.to_f) * 4 + 1) + avg_rating = avg_rating.nan? ? 0.0 : avg_rating + info["avg_rating"] = "#{avg_rating}" description = html.xpath_node(%q(//p[@id="eow-description"])) description = description ? description.to_xml : ""