From ef3abd01b1cca2ba5a7aebb3ba5274c7d791d5cf Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 4 Jul 2022 20:25:52 +0700 Subject: [PATCH] implement channel_id_playlist, handle channel_id_about post --- .../home/templates/home/channel_id.html | 58 +------------------ .../home/templates/home/channel_id_about.html | 5 +- .../templates/home/channel_id_playlist.html | 46 +++++++++++++++ tubearchivist/home/urls.py | 6 ++ tubearchivist/home/views.py | 57 +++++++++++++++++- 5 files changed, 111 insertions(+), 61 deletions(-) create mode 100644 tubearchivist/home/templates/home/channel_id_playlist.html diff --git a/tubearchivist/home/templates/home/channel_id.html b/tubearchivist/home/templates/home/channel_id.html index 57d1e05..a4e7f74 100644 --- a/tubearchivist/home/templates/home/channel_id.html +++ b/tubearchivist/home/templates/home/channel_id.html @@ -8,7 +8,7 @@

Videos

-

Playlists

+

Playlists

About

@@ -58,65 +58,9 @@

Total Videos archived: {{ max_hits }}

Watched:

{% endif %} - - -
-
-
- {% csrf_token %} -
-

Download format: - {% if channel_info.channel_overwrites.download_format %} - {{ channel_info.channel_overwrites.download_format }} - {% else %} - False - {% endif %}

- {{ channel_overwrite_form.download_format }}
-
-
-

Auto delete watched videos after x days: - {% if channel_info.channel_overwrites.autodelete_days %} - {{ channel_info.channel_overwrites.autodelete_days }} - {% else %} - False - {% endif %}

- {{ channel_overwrite_form.autodelete_days }}
-
-
-

Index playlists: - {% if channel_info.channel_overwrites.index_playlists %} - {{ channel_info.channel_overwrites.index_playlists }} - {% else %} - False - {% endif %}

- {{ channel_overwrite_form.index_playlists }}
-
-
-

Enable SponsorBlock: - {% if channel_info.channel_overwrites.integrate_sponsorblock %} - {{ channel_info.channel_overwrites.integrate_sponsorblock }} - {% elif channel_info.channel_overwrites.integrate_sponsorblock == False %} - Disabled - {% else %} - False - {% endif %}

- {{ channel_overwrite_form.integrate_sponsorblock }}
-
- -
-
-
- {% if channel_info.channel_description %} -
-

Description:

-
- {{ channel_info.channel_description|linebreaks }} -
-
- {% endif %}
diff --git a/tubearchivist/home/templates/home/channel_id_about.html b/tubearchivist/home/templates/home/channel_id_about.html index 3650e8b..cbf4ce7 100644 --- a/tubearchivist/home/templates/home/channel_id_about.html +++ b/tubearchivist/home/templates/home/channel_id_about.html @@ -8,7 +8,7 @@
@@ -61,7 +61,7 @@ {% endif %}
-
+ {% csrf_token %}

Download format: @@ -105,6 +105,5 @@

-

{{ channel_info }}

{% endblock content %} \ No newline at end of file diff --git a/tubearchivist/home/templates/home/channel_id_playlist.html b/tubearchivist/home/templates/home/channel_id_playlist.html new file mode 100644 index 0000000..a1733f7 --- /dev/null +++ b/tubearchivist/home/templates/home/channel_id_playlist.html @@ -0,0 +1,46 @@ +{% extends "home/base.html" %} +{% block content %} +{% load static %} +{% load humanize %} +
+
+ channel_banner +
+ +
+
+ grid view + list view +
+
+
+ {% if results %} + {% for playlist in results %} +
+
+ + {{ playlist.source.playlist_id }}-thumbnail + +
+
+

{{ playlist.source.playlist_channel }}

+

{{ playlist.source.playlist_name }}

+

Last refreshed: {{ playlist.source.playlist_last_refresh }}

+ {% if playlist.source.playlist_subscribed %} + + {% else %} + + {% endif %} +
+
+ {% endfor %} + {% else %} +

No playlists found...

+ {% endif %} +
+
+{% endblock content %} \ No newline at end of file diff --git a/tubearchivist/home/urls.py b/tubearchivist/home/urls.py index b40c403..521ed3b 100644 --- a/tubearchivist/home/urls.py +++ b/tubearchivist/home/urls.py @@ -7,6 +7,7 @@ from django.urls import path from home.views import ( AboutView, ChannelIdAboutView, + ChannelIdPlaylistView, ChannelIdView, ChannelView, DownloadView, @@ -48,6 +49,11 @@ urlpatterns = [ login_required(ChannelIdAboutView.as_view()), name="channel_id_about", ), + path( + "channel//playlist/", + login_required(ChannelIdPlaylistView.as_view()), + name="channel_id_playlist", + ), path( "video//", login_required(VideoView.as_view()), diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 18604c8..2519e32 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -442,7 +442,6 @@ class ChannelIdView(ArchivistResultsView): { "title": "Channel: " + channel_name, "channel_info": channel_info, - "channel_overwrite_form": ChannelOverwriteForm, } ) @@ -506,6 +505,62 @@ class ChannelIdAboutView(ArchivistResultsView): return render(request, "home/channel_id_about.html", self.context) + @staticmethod + def post(request, channel_id): + """handle post request""" + print(f"handle post from {channel_id}") + channel_overwrite_form = ChannelOverwriteForm(request.POST) + if channel_overwrite_form.is_valid(): + overwrites = channel_overwrite_form.cleaned_data + print(f"{channel_id}: set overwrites {overwrites}") + channel_overwrites(channel_id, overwrites=overwrites) + if overwrites.get("index_playlists") == "1": + index_channel_playlists.delay(channel_id) + + sleep(1) + return redirect("channel_id_about", channel_id, permanent=True) + + +class ChannelIdPlaylistView(ArchivistResultsView): + """resolves to /channel//playlist/ + show all playlists of channel + """ + + view_origin = "playlist" + es_search = "ta_playlist/_search" + + def get(self, request, channel_id): + """handle get request""" + self.initiate_vars(request) + self._update_view_data(channel_id) + self.find_results() + + channel_info = self._get_channel_meta(channel_id) + channel_name = channel_info["channel_name"] + self.context.update( + { + "title": "Channel: Playlists " + channel_name, + "channel_info": channel_info, + } + ) + + return render(request, "home/channel_id_playlist.html", self.context) + + def _update_view_data(self, channel_id): + """update view specific data dict""" + self.data["sort"] = [{"playlist_name.keyword": {"order": "asc"}}] + self.data["query"] = { + "term": {"playlist_channel_id": {"value": channel_id}} + } + + def _get_channel_meta(self, channel_id): + """get metadata for channel""" + path = f"ta_channel/_doc/{channel_id}" + response, _ = ElasticWrap(path).get() + channel_info = SearchProcess(response).process() + + return channel_info + class ChannelView(ArchivistResultsView): """resolves to /channel/