diff --git a/tubearchivist/home/templates/home/video.html b/tubearchivist/home/templates/home/video.html index 0a70ae2..8d3788a 100644 --- a/tubearchivist/home/templates/home/video.html +++ b/tubearchivist/home/templates/home/video.html @@ -56,7 +56,11 @@

Views: {{ video.stats.view_count|intcomma }}

thumbs-up: {{ video.stats.like_count|intcomma }}

thumbs-down: {{ video.stats.dislike_count|intcomma }}

-

Rating: {{ video.stats.average_rating }}

+

Rating: + {% for star in video.stats.average_rating %} + {{ star }} + {% endfor %} +

diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 3cdb6f3..eef969f 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -408,6 +408,12 @@ class VideoView(View): look_up = SearchHandler(url, data) video_hit = look_up.get_data() video_data = video_hit[0]["source"] + try: + rating = video_data["stats"]["average_rating"] + video_data["stats"]["average_rating"] = self.star_creator(rating) + except KeyError: + video_data["stats"]["average_rating"] = False + video_title = video_data["title"] context = {"video": video_data, "title": video_title, "colors": colors} return render(request, "home/video.html", context) @@ -420,6 +426,20 @@ class VideoView(View): colors = config["application"]["colors"] return es_url, colors + @staticmethod + def star_creator(rating): + """convert rating float to stars""" + stars = [] + for _ in range(1, 6): + if rating >= 0.75: + stars.append("full") + elif 0.25 < rating < 0.75: + stars.append("half") + else: + stars.append("empty") + rating = rating - 1 + return stars + class SettingsView(View): """resolves to /settings/ diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index 6cbe388..875c573 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -528,7 +528,8 @@ button:hover { margin-left: 5px; } -.thumb-icon img { +.thumb-icon img, +.rating-stars img { width: 20px; margin: 0; filter: var(--img-filter); diff --git a/tubearchivist/static/img/icon-star-empty.svg b/tubearchivist/static/img/icon-star-empty.svg new file mode 100644 index 0000000..d6fa220 --- /dev/null +++ b/tubearchivist/static/img/icon-star-empty.svg @@ -0,0 +1,65 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/tubearchivist/static/img/icon-star-full.svg b/tubearchivist/static/img/icon-star-full.svg new file mode 100644 index 0000000..7018bf6 --- /dev/null +++ b/tubearchivist/static/img/icon-star-full.svg @@ -0,0 +1,74 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/tubearchivist/static/img/icon-star-half.svg b/tubearchivist/static/img/icon-star-half.svg new file mode 100644 index 0000000..a3e6b34 --- /dev/null +++ b/tubearchivist/static/img/icon-star-half.svg @@ -0,0 +1,66 @@ + + + + + + + + + + image/svg+xml + + + + + + + + +