mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2024-12-23 18:30:12 +00:00
[API] add and use DELETE video endpoint
This commit is contained in:
parent
63f35b19fe
commit
db21ee8bcb
@ -79,7 +79,8 @@ Pass page number as a query parameter: `page=2`. Defaults to *0*, `page=1` is re
|
|||||||
/api/video/
|
/api/video/
|
||||||
|
|
||||||
## Video Item View
|
## Video Item View
|
||||||
/api/video/\<video_id>/
|
GET: /api/video/\<video_id>/
|
||||||
|
DELETE: /api/video/\<video_id>/
|
||||||
|
|
||||||
## Video Comment View
|
## Video Comment View
|
||||||
/api/video/\<video_id>/comment/
|
/api/video/\<video_id>/comment/
|
||||||
|
@ -9,7 +9,7 @@ from home.src.es.snapshot import ElasticSnapshot
|
|||||||
from home.src.frontend.searching import SearchForm
|
from home.src.frontend.searching import SearchForm
|
||||||
from home.src.index.generic import Pagination
|
from home.src.index.generic import Pagination
|
||||||
from home.src.index.reindex import ReindexProgress
|
from home.src.index.reindex import ReindexProgress
|
||||||
from home.src.index.video import SponsorBlock
|
from home.src.index.video import SponsorBlock, YoutubeVideo
|
||||||
from home.src.ta.config import AppConfig
|
from home.src.ta.config import AppConfig
|
||||||
from home.src.ta.helper import UrlListParser
|
from home.src.ta.helper import UrlListParser
|
||||||
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
|
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
|
||||||
@ -95,6 +95,20 @@ class VideoApiView(ApiBaseView):
|
|||||||
self.get_document(video_id)
|
self.get_document(video_id)
|
||||||
return Response(self.response, status=self.status_code)
|
return Response(self.response, status=self.status_code)
|
||||||
|
|
||||||
|
def delete(self, request, video_id):
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
"""delete single video"""
|
||||||
|
message = {"video": video_id}
|
||||||
|
try:
|
||||||
|
YoutubeVideo(video_id).delete_media_file()
|
||||||
|
status_code = 200
|
||||||
|
message.update({"state": "delete"})
|
||||||
|
except FileNotFoundError:
|
||||||
|
status_code = 404
|
||||||
|
message.update({"state": "not found"})
|
||||||
|
|
||||||
|
return Response(message, status=status_code)
|
||||||
|
|
||||||
|
|
||||||
class VideoApiListView(ApiBaseView):
|
class VideoApiListView(ApiBaseView):
|
||||||
"""resolves to /api/video/
|
"""resolves to /api/video/
|
||||||
|
@ -12,7 +12,6 @@ from home.src.download.subscriptions import (
|
|||||||
from home.src.frontend.watched import WatchState
|
from home.src.frontend.watched import WatchState
|
||||||
from home.src.index.channel import YoutubeChannel
|
from home.src.index.channel import YoutubeChannel
|
||||||
from home.src.index.playlist import YoutubePlaylist
|
from home.src.index.playlist import YoutubePlaylist
|
||||||
from home.src.index.video import YoutubeVideo
|
|
||||||
from home.src.ta.helper import UrlListParser
|
from home.src.ta.helper import UrlListParser
|
||||||
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
|
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
|
||||||
from home.tasks import (
|
from home.tasks import (
|
||||||
@ -73,7 +72,6 @@ class PostData:
|
|||||||
"db-backup": self._db_backup,
|
"db-backup": self._db_backup,
|
||||||
"db-restore": self._db_restore,
|
"db-restore": self._db_restore,
|
||||||
"fs-rescan": self._fs_rescan,
|
"fs-rescan": self._fs_rescan,
|
||||||
"delete-video": self._delete_video,
|
|
||||||
"delete-channel": self._delete_channel,
|
"delete-channel": self._delete_channel,
|
||||||
"delete-playlist": self._delete_playlist,
|
"delete-playlist": self._delete_playlist,
|
||||||
"find-playlists": self._find_playlists,
|
"find-playlists": self._find_playlists,
|
||||||
@ -284,12 +282,6 @@ class PostData:
|
|||||||
rescan_filesystem.delay()
|
rescan_filesystem.delay()
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
def _delete_video(self):
|
|
||||||
"""delete media file, metadata and thumb"""
|
|
||||||
youtube_id = self.exec_val
|
|
||||||
YoutubeVideo(youtube_id).delete_media_file()
|
|
||||||
return {"success": True}
|
|
||||||
|
|
||||||
def _delete_channel(self):
|
def _delete_channel(self):
|
||||||
"""delete channel and all matching videos"""
|
"""delete channel and all matching videos"""
|
||||||
channel_id = self.exec_val
|
channel_id = self.exec_val
|
||||||
|
@ -292,6 +292,9 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
|
|||||||
"""delete video file, meta data"""
|
"""delete video file, meta data"""
|
||||||
print(f"{self.youtube_id}: delete video")
|
print(f"{self.youtube_id}: delete video")
|
||||||
self.get_from_es()
|
self.get_from_es()
|
||||||
|
if not self.json_data:
|
||||||
|
raise FileNotFoundError
|
||||||
|
|
||||||
video_base = self.app_conf["videos"]
|
video_base = self.app_conf["videos"]
|
||||||
media_url = self.json_data.get("media_url")
|
media_url = self.json_data.get("media_url")
|
||||||
file_path = os.path.join(video_base, media_url)
|
file_path = os.path.join(video_base, media_url)
|
||||||
|
@ -334,8 +334,8 @@ function deleteConfirm() {
|
|||||||
function deleteVideo(button) {
|
function deleteVideo(button) {
|
||||||
let to_delete = button.getAttribute('data-id');
|
let to_delete = button.getAttribute('data-id');
|
||||||
let to_redirect = button.getAttribute('data-redirect');
|
let to_redirect = button.getAttribute('data-redirect');
|
||||||
let payload = JSON.stringify({ 'delete-video': to_delete });
|
let apiEndpoint = '/api/video/' + to_delete + '/';
|
||||||
sendPost(payload);
|
apiRequest(apiEndpoint, 'DELETE');
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
let redirect = '/channel/' + to_redirect;
|
let redirect = '/channel/' + to_redirect;
|
||||||
window.location.replace(redirect);
|
window.location.replace(redirect);
|
||||||
|
Loading…
Reference in New Issue
Block a user