diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py index aa13f80..83492f3 100644 --- a/tubearchivist/home/forms.py +++ b/tubearchivist/home/forms.py @@ -98,3 +98,17 @@ class AddToQueueForm(forms.Form): } ), ) + + +class SubscribeToChannelForm(forms.Form): + """text area form to subscribe to multiple channels""" + + subscribe = forms.CharField( + label=False, + widget=forms.Textarea( + attrs={ + "rows": 3, + "placeholder": "Input channel ID, URL or Video of a channel", + } + ), + ) diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index c7bb45d..20b50b0 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -166,3 +166,22 @@ def kill_dl(task_id): def rescan_filesystem(): """check the media folder for mismatches""" scan_filesystem() + + +@shared_task +def subscribe_to(youtube_ids): + """take a list of urls to subscribe to""" + for youtube_id in youtube_ids: + if youtube_id["type"] == "video": + to_sub = youtube_id["url"] + vid_details = PendingList().get_youtube_details(to_sub) + channel_id_sub = vid_details["channel_id"] + elif youtube_id["type"] == "channel": + channel_id_sub = youtube_id["url"] + else: + raise ValueError("failed to subscribe to: " + youtube_id) + + ChannelSubscription().change_subscribe( + channel_id_sub, channel_subscribed=True + ) + print("subscribed to: " + channel_id_sub) diff --git a/tubearchivist/home/templates/home/channel.html b/tubearchivist/home/templates/home/channel.html index 10141c9..9ad90c3 100644 --- a/tubearchivist/home/templates/home/channel.html +++ b/tubearchivist/home/templates/home/channel.html @@ -12,7 +12,7 @@
{% csrf_token %} - + {{ subscribe_form }}
@@ -24,7 +24,6 @@