From 7a60fa0d1401e7c5baac1f7697a5091135719e6b Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 3 Jun 2021 20:37:13 +0200 Subject: [PATCH] fix rating when absent displayed as -25%up / 125%down -- oops :D --- app/youtube/lib.py | 8 ++++++-- app/youtube/templates/watch.html.j2 | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/youtube/lib.py b/app/youtube/lib.py index bb94f21..8d688df 100644 --- a/app/youtube/lib.py +++ b/app/youtube/lib.py @@ -79,8 +79,12 @@ def prepare_metadata(metadata): blacklisted = sorted(set(all_countries) - set(whitelisted)) # the rating goes from 1 to 5, and is the ratio of up- to down votes, plus 1 - thumbs_up = 100 * (meta1['averageRating']-1) / 4 # reconstructed ratio - thumbs_dn = 100 - thumbs_up + if meta1['averageRating'] != 0: + thumbs_up = 100 * (meta1['averageRating']-1) / 4 # reconstructed ratio + thumbs_dn = 100 - thumbs_up + else: # no thumbs given + thumbs_up = 0 + thumbs_dn = 0 return { **video_metadata(metadata), diff --git a/app/youtube/templates/watch.html.j2 b/app/youtube/templates/watch.html.j2 index 26fb1c3..4347d28 100644 --- a/app/youtube/templates/watch.html.j2 +++ b/app/youtube/templates/watch.html.j2 @@ -90,7 +90,11 @@ var sha256=function a(b){function c(a,b){return a>>>b|a<<32-b}for(var d,e,f=Math
Published
{{ published.split('T')[0] }}
Rating + {% if rating == 0 %} +
n/a + {% else %}
{{ thumbs_up | round(1) }}% 👍︎⁄👎︎ {{ thumbs_dn | round(1) }}% + {% endif %}
Visibility
{{ 'unlisted' if unlisted else 'public' }} {% if blacklisted|length == 0 %} -- 2.39.3