diff --git a/tubearchivist/home/src/frontend/forms.py b/tubearchivist/home/src/frontend/forms.py index 3e1b353..839a88a 100644 --- a/tubearchivist/home/src/frontend/forms.py +++ b/tubearchivist/home/src/frontend/forms.py @@ -178,3 +178,10 @@ class SubscribeToPlaylistForm(forms.Form): } ), ) + + +class ChannelOverwriteForm(forms.Form): + """custom overwrites for channel settings""" + + download_format = forms.CharField(label=False, required=False) + autodelete_days = forms.IntegerField(label=False, required=False) diff --git a/tubearchivist/home/src/index/channel.py b/tubearchivist/home/src/index/channel.py index 3837bcd..ccbdacc 100644 --- a/tubearchivist/home/src/index/channel.py +++ b/tubearchivist/home/src/index/channel.py @@ -274,7 +274,7 @@ class YoutubeChannel(YouTubeItem): def set_overwrites(self, overwrites): """set per channel overwrites""" - valid_keys = ["format", "autodelete_days"] + valid_keys = ["download_format", "autodelete_days"] for key in overwrites: if key not in valid_keys: raise ValueError(f"invalid overwrite key: {key}") @@ -283,3 +283,12 @@ class YoutubeChannel(YouTubeItem): self.json_data["channel_overwrites"].update(overwrites) else: self.json_data["channel_overwrites"] = overwrites + + +def channel_overwrites(channel_id, overwrites): + """collection to overwrite settings per channel""" + channel = YoutubeChannel(channel_id) + channel.build_json() + channel.set_overwrites(overwrites) + channel.upload_to_es() + channel.sync_to_videos() diff --git a/tubearchivist/home/templates/home/channel_id.html b/tubearchivist/home/templates/home/channel_id.html index 3a84037..00fdfa4 100644 --- a/tubearchivist/home/templates/home/channel_id.html +++ b/tubearchivist/home/templates/home/channel_id.html @@ -57,6 +57,18 @@ +
+
+
+ {% csrf_token %} +

Download format

+ {{ channel_overwrite_form.download_format }}
+

Auto delete videos after x days

+ {{ channel_overwrite_form.autodelete_days }}
+ +
+
+
{% if channel_info.channel_description %}

Description:

diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index c53fe1f..15faa31 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -19,6 +19,7 @@ from home.src.frontend.api_calls import PostData from home.src.frontend.forms import ( AddToQueueForm, ApplicationSettingsForm, + ChannelOverwriteForm, CustomAuthForm, MultiSearchForm, SchedulerSettingsForm, @@ -27,6 +28,7 @@ from home.src.frontend.forms import ( UserSettingsForm, ) from home.src.frontend.searching import SearchHandler +from home.src.index.channel import channel_overwrites from home.src.index.generic import Pagination from home.src.index.playlist import YoutubePlaylist from home.src.ta.config import AppConfig, ScheduleBuilder @@ -412,6 +414,7 @@ class ChannelIdView(ArchivistResultsView): { "title": "Channel: " + channel_name, "channel_info": channel_info, + "channel_overwrite_form": ChannelOverwriteForm, } ) @@ -432,6 +435,19 @@ class ChannelIdView(ArchivistResultsView): to_append = {"term": {"player.watched": {"value": False}}} self.data["query"]["bool"]["must"].append(to_append) + @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) + + sleep(1) + return redirect("channel_id", channel_id, permanent=True) + class ChannelView(ArchivistResultsView): """resolves to /channel/