diff --git a/tubearchivist/api/README.md b/tubearchivist/api/README.md index ad56ba37..e26978b5 100644 --- a/tubearchivist/api/README.md +++ b/tubearchivist/api/README.md @@ -165,7 +165,9 @@ POST /api/channel/ ``` ## Channel Item View -/api/channel/\/ +GET: /api/channel/\/ +DELETE: /api/channel/\/ +- Will delete channel with all it's videos ## Channel Videos View /api/channel/\/video/ diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index f9bb4bc3..51cf2969 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -7,6 +7,7 @@ from home.src.download.yt_dlp_base import CookieHandler from home.src.es.connect import ElasticWrap from home.src.es.snapshot import ElasticSnapshot from home.src.frontend.searching import SearchForm +from home.src.index.channel import YoutubeChannel from home.src.index.generic import Pagination from home.src.index.reindex import ReindexProgress from home.src.index.video import SponsorBlock, YoutubeVideo @@ -265,6 +266,20 @@ class ChannelApiView(ApiBaseView): self.get_document(channel_id) return Response(self.response, status=self.status_code) + def delete(self, request, channel_id): + # pylint: disable=unused-argument + """delete channel""" + message = {"channel": channel_id} + try: + YoutubeChannel(channel_id).delete_channel() + status_code = 200 + message.update({"state": "delete"}) + except FileNotFoundError: + status_code = 404 + message.update({"state": "not found"}) + + return Response(message, status=status_code) + class ChannelApiListView(ApiBaseView): """resolves to /api/channel/ diff --git a/tubearchivist/home/src/frontend/api_calls.py b/tubearchivist/home/src/frontend/api_calls.py index 5943c6cd..71c5182a 100644 --- a/tubearchivist/home/src/frontend/api_calls.py +++ b/tubearchivist/home/src/frontend/api_calls.py @@ -10,7 +10,6 @@ from home.src.download.subscriptions import ( PlaylistSubscription, ) from home.src.frontend.watched import WatchState -from home.src.index.channel import YoutubeChannel from home.src.index.playlist import YoutubePlaylist from home.src.ta.helper import UrlListParser from home.src.ta.ta_redis import RedisArchivist, RedisQueue @@ -71,7 +70,6 @@ class PostData: "db-backup": self._db_backup, "db-restore": self._db_restore, "fs-rescan": self._fs_rescan, - "delete-channel": self._delete_channel, "delete-playlist": self._delete_playlist, "find-playlists": self._find_playlists, } @@ -274,12 +272,6 @@ class PostData: rescan_filesystem.delay() return {"success": True} - def _delete_channel(self): - """delete channel and all matching videos""" - channel_id = self.exec_val - YoutubeChannel(channel_id).delete_channel() - return {"success": True} - def _delete_playlist(self): """delete playlist, only metadata or incl all videos""" playlist_dict = self.exec_val diff --git a/tubearchivist/home/src/index/channel.py b/tubearchivist/home/src/index/channel.py index fb80e253..90e0c116 100644 --- a/tubearchivist/home/src/index/channel.py +++ b/tubearchivist/home/src/index/channel.py @@ -298,6 +298,9 @@ class YoutubeChannel(YouTubeItem): """delete channel and all videos""" print(f"{self.youtube_id}: delete channel") self.get_from_es() + if not self.json_data: + raise FileNotFoundError + folder_path = self.get_folder_path() print(f"{self.youtube_id}: delete all media files") try: diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index 31e1d3d2..6b919bf8 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -344,8 +344,8 @@ function deleteVideo(button) { function deleteChannel(button) { let to_delete = button.getAttribute('data-id'); - let payload = JSON.stringify({ 'delete-channel': to_delete }); - sendPost(payload); + let apiEndpoint = '/api/channel/' + to_delete + '/'; + apiRequest(apiEndpoint, 'DELETE'); setTimeout(function () { window.location.replace('/channel/'); }, 1000);