From f6950a2ca5005536c40fb467fef2ba16063a9157 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 12 Mar 2022 17:29:34 +0700 Subject: [PATCH] list all in progress videos --- tubearchivist/home/templates/home/home.html | 24 ++++++++--------- tubearchivist/home/views.py | 30 +++++++++++++++++---- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/tubearchivist/home/templates/home/home.html b/tubearchivist/home/templates/home/home.html index 0eb2926..445de5b 100644 --- a/tubearchivist/home/templates/home/home.html +++ b/tubearchivist/home/templates/home/home.html @@ -9,14 +9,14 @@
{% for video in continue_vids %}
- +
- video-thumb - {% if video.player.progress %} -
+ video-thumb + {% if video.source.player.progress %} +
{% else %} -
+
{% endif %}
@@ -25,17 +25,17 @@
-
- {% if video.player.watched %} - seen-icon +
+ {% if video.source.player.watched %} + seen-icon {% else %} - unseen-icon + unseen-icon {% endif %} - {{ video.published }} | {{ video.player.duration_str }} + {{ video.source.published }} | {{ video.source.player.duration_str }}
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 781b690..08e5df8 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -175,15 +175,35 @@ class ArchivistResultsView(ArchivistViewConfig): if not results or not self.context["results"]: return - self.context["continue_vids"] = [] - progress = {i["youtube_id"]: i["position"] for i in results} + self.context["continue_vids"] = self.get_in_progress(results) + + in_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"]) + if video["youtube_id"] in in_progress: + played_sec = in_progress.get(video["youtube_id"]) total = video["player"]["duration"] video["player"]["progress"] = 100 * (played_sec / total) - self.context["continue_vids"].append(video) + + def get_in_progress(self, results): + """get all videos in progress""" + ids = [{"match": {"youtube_id": i.get("youtube_id")}} for i in results] + data = { + "size": self.default_conf["archive"]["page_size"], + "query": {"bool": {"should": ids}}, + } + search = SearchHandler( + "ta_video/_search", self.default_conf, data=data + ) + videos = search.get_data() + for video in videos: + youtube_id = video["source"]["youtube_id"] + matched = [i for i in results if i["youtube_id"] == youtube_id] + played_sec = matched[0]["position"] + total = video["source"]["player"]["duration"] + video["source"]["player"]["progress"] = 100 * (played_sec / total) + + return videos def single_lookup(self, es_path): """retrieve a single item from url"""