From 2905a67ab993b537ee0fb5fc5b10a9414a80f0c4 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 28 Sep 2021 16:53:45 +0700 Subject: [PATCH] show ignored videos, forget or download ids --- tubearchivist/home/apps.py | 2 + tubearchivist/home/config.json | 1 + .../home/templates/home/downloads.html | 37 +++++++++++++---- tubearchivist/home/views.py | 40 ++++++++++++++++--- tubearchivist/static/script.js | 29 ++++++++++++++ 5 files changed, 95 insertions(+), 14 deletions(-) diff --git a/tubearchivist/home/apps.py b/tubearchivist/home/apps.py index 2e527fe..105d1a9 100644 --- a/tubearchivist/home/apps.py +++ b/tubearchivist/home/apps.py @@ -23,6 +23,8 @@ def sync_redis_state(): redis_archivist.set_message( "show_subed_only", show_subed_only, expire=False ) + filter_view = config["archive"]["filter_view"] + redis_archivist.set_message("filter_view", filter_view, expire=False) def make_folders(): diff --git a/tubearchivist/home/config.json b/tubearchivist/home/config.json index 42c71e8..4a02b2e 100644 --- a/tubearchivist/home/config.json +++ b/tubearchivist/home/config.json @@ -1,6 +1,7 @@ { "archive": { "sort": "published", + "filter_view": "pending", "hide_watched": false, "show_subed_only": false, "page_size": 12 diff --git a/tubearchivist/home/templates/home/downloads.html b/tubearchivist/home/templates/home/downloads.html index 3c5bbb9..e05fe3a 100644 --- a/tubearchivist/home/templates/home/downloads.html +++ b/tubearchivist/home/templates/home/downloads.html @@ -27,30 +27,51 @@ -

Download queue

+
+ Change show / hide ignored only {{ filter_view }} + +
+{% if filter_view == "ignore" %} +

Ignored from download

+{% else %} +

Download queue

+{% endif %}
- {% if pending %} -

Total pending downloads: {{ max_hits }}

- {% for video in pending %} + {% if all_video_hits %} +

Total videos found: {{ max_hits }}

+ {% for video in all_video_hits %}
video_thumb
-

{{ video.title }}

+ {% if filter_view == "ignore" %} +

Ignore: {{ video.title }}

+ {% else %} +

Download: {{ video.title }}

+ {% endif %} {% if video.channel_indexed %} {{ video.channel_name }} {% else %} {{ video.channel_name }} {% endif %}

Published: {{ video.published }} | Duration: {{ video.duration }} | {{ video.youtube_id }}

- - + {% if filter_view == "ignore" %} + + + {% else %} + + + {% endif %}
{% endfor %} {% else %} -

No pending downloads

+

No videos found

{% endif %}
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 2275f18..738df59 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -144,43 +144,45 @@ class DownloadView(View): """handle get requests""" config = AppConfig().config colors = config["application"]["colors"] + filter_view = RedisArchivist().get_message("filter_view") page_get = int(request.GET.get("page", 0)) pagination_handler = Pagination(page_get) url = config["application"]["es_url"] + "/ta_download/_search" - data = self.build_data(pagination_handler) + data = self.build_data(pagination_handler, filter_view) search = SearchHandler(url, data, cache=False) videos_hits = search.get_data() max_hits = search.max_hits if videos_hits: - all_pending = [i["source"] for i in videos_hits] + all_video_hits = [i["source"] for i in videos_hits] pagination_handler.validate(max_hits) pagination = pagination_handler.pagination else: - all_pending = False + all_video_hits = False pagination = False context = { - "pending": all_pending, + "all_video_hits": all_video_hits, "max_hits": max_hits, "pagination": pagination, "title": "Downloads", "colors": colors, + "filter_view": filter_view, } return render(request, "home/downloads.html", context) @staticmethod - def build_data(pagination_handler): + def build_data(pagination_handler, filter_view): """build data dict for search""" page_size = pagination_handler.pagination["page_size"] page_from = pagination_handler.pagination["page_from"] data = { "size": page_size, "from": page_from, - "query": {"term": {"status": {"value": "pending"}}}, + "query": {"term": {"status": {"value": filter_view}}}, "sort": [{"timestamp": {"order": "asc"}}], } return data @@ -481,6 +483,9 @@ class PostData: "hide_watched": self.hide_watched, "show_subed_only": self.show_subed_only, "dlnow": self.dlnow, + "show_ignored_only": self.show_ignored_only, + "forgetIgnore": self.forget_ignore, + "addSingle": self.add_single, "manual-import": self.manual_import, "db-backup": self.db_backup, "db-restore": self.db_restore, @@ -577,6 +582,29 @@ class PostData: RedisArchivist().set_message("dl_queue_id", task_id, expire=False) return {"success": True} + def show_ignored_only(self): + """switch view on /downloads/ to show ignored only""" + show_value = self.exec_val + print("Download view: " + show_value) + RedisArchivist().set_message("filter_view", show_value, expire=False) + return {"success": True} + + def forget_ignore(self): + """delete from ta_download index""" + youtube_id = self.exec_val + print("forgetting from download index: " + youtube_id) + PendingList().delete_from_pending(youtube_id) + return {"success": True} + + def add_single(self): + """add single youtube_id to download queue""" + youtube_id = self.exec_val + print("add vid to dl queue: " + youtube_id) + PendingList().delete_from_pending(youtube_id) + youtube_ids = process_url_list([youtube_id]) + extrac_dl.delay(youtube_ids) + return {"success": True} + @staticmethod def manual_import(): """run manual import from settings page""" diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index cdc452e..4075a12 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -79,6 +79,35 @@ function downloadNow(button) { }, 500); } +function showIgnoredOnly(showValue) { + var payload = JSON.stringify({'show_ignored_only': showValue}); + console.log(payload); + sendPost(payload); + setTimeout(function(){ + window.location.replace("/downloads/"); + return false; + }, 500); +} + +function forgetIgnore(button) { + var youtube_id = button.getAttribute('data-id'); + var payload = JSON.stringify({'forgetIgnore': youtube_id}); + console.log(payload); + sendPost(payload); + document.getElementById("dl-" + youtube_id).remove(); +} + +function addSingle(button) { + var youtube_id = button.getAttribute('data-id'); + var payload = JSON.stringify({'addSingle': youtube_id}); + console.log(payload); + sendPost(payload); + document.getElementById("dl-" + youtube_id).remove(); + setTimeout(function(){ + handleInterval(); + }, 500); +} + function stopQueue() { var payload = JSON.stringify({'queue': 'stop'}); sendPost(payload);