From d88d6d6a617a5e68e5bb72c9edac761fa3c136de Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 24 Feb 2022 18:58:26 +0700 Subject: [PATCH] add video progress bar --- tubearchivist/home/templates/home/home.html | 3 +++ tubearchivist/home/views.py | 12 ++++++++++++ tubearchivist/static/css/style.css | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/tubearchivist/home/templates/home/home.html b/tubearchivist/home/templates/home/home.html index 62d2e9a..6cf643a 100644 --- a/tubearchivist/home/templates/home/home.html +++ b/tubearchivist/home/templates/home/home.html @@ -49,6 +49,9 @@
video-thumb + {% if video.source.player.progress %} +
+ {% endif %}
play-icon diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 660ec73..131b78f 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -169,6 +169,17 @@ class ArchivistResultsView(ArchivistViewConfig): } self.data = data + def match_progress(self): + """add video progress to result context""" + results = RedisArchivist().list_items(f"{self.user_id}:progress:") + progress = {i["youtube_id"]: i["position"] for i in results} + for hit in self.context["results"]: + video = hit["source"] + if video["youtube_id"] in progress: + played_sec = progress.get(video["youtube_id"]) + total = video["player"]["duration"] + video["player"]["progress"] = 100 * (played_sec / total) + def single_lookup(self, es_path): """retrieve a single item from url""" search = SearchHandler(es_path, config=self.default_conf) @@ -212,6 +223,7 @@ class HomeView(ArchivistResultsView): self.initiate_vars(request) self._update_view_data() self.find_results() + self.match_progress() return render(request, "home/home.html", self.context) diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index 53a8882..10b219b 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -391,8 +391,17 @@ button:hover { grid-template-columns: 25% auto; } +.video-progress-bar { + position: absolute; + background-color: var(--accent-font-light); + height: 7px; + left: 0; + bottom: 3px; +} + .video-thumb img { width: 100%; + position: relative; } .video-play img {