From db4b29f7379c5a57104337c47e4e43f2549e0e80 Mon Sep 17 00:00:00 2001 From: girst Date: Sat, 29 May 2021 15:01:52 +0200 Subject: [PATCH] replace star rating with thumbs up/down percentage also replace 'blacklisted in' with the shorter 'blocked in' for aesthetic reasons. --- app/youtube/lib.py | 6 ++++++ app/youtube/templates/watch.html.j2 | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/youtube/lib.py b/app/youtube/lib.py index 9bc23ca..bb94f21 100644 --- a/app/youtube/lib.py +++ b/app/youtube/lib.py @@ -78,10 +78,16 @@ def prepare_metadata(metadata): whitelisted = sorted(meta2.get('availableCountries',[])) 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 + return { **video_metadata(metadata), 'description': meta1['shortDescription'], 'rating': meta1['averageRating'], + 'thumbs_up': thumbs_up, + 'thumbs_dn': thumbs_dn, 'category': meta2['category'], 'aspectr': aspect_ratio, 'unlisted': meta2['isUnlisted'], diff --git a/app/youtube/templates/watch.html.j2 b/app/youtube/templates/watch.html.j2 index 5abd16e..994cfbc 100644 --- a/app/youtube/templates/watch.html.j2 +++ b/app/youtube/templates/watch.html.j2 @@ -90,7 +90,7 @@ 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 -
{{ rating | round(1) }}/5 +
{{ thumbs_up | round(1) }}% 👍︎⁄👎︎ {{ thumbs_dn | round(1) }}%
Visibility
{{ 'unlisted' if unlisted else 'public' }} {% if blacklisted|length == 0 %} @@ -103,7 +103,7 @@ var sha256=function a(b){function c(a,b){return a>>>b|a<<32-b}for(var d,e,f=Math
Available in
{{ whitelisted | join(', ') }} {% else %} -
Blacklisted in +
Blocked in
{{ blacklisted | join(', ') }} {% endif %} -- 2.39.3