mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 22:39:38 +00:00
add playlist/channel detail subscribed update, #862
This commit is contained in:
@@ -89,8 +89,18 @@ class ChannelApiView(ApiBaseView):
|
|||||||
|
|
||||||
def post(self, request, channel_id):
|
def post(self, request, channel_id):
|
||||||
"""modify channel overwrites"""
|
"""modify channel overwrites"""
|
||||||
|
self.get_document(channel_id)
|
||||||
|
if not self.response["data"]:
|
||||||
|
return Response({"error": "channel not found"}, status=404)
|
||||||
|
|
||||||
data = request.data
|
data = request.data
|
||||||
if not isinstance(data, dict) or "channel_overwrites" not in data:
|
subscribed = data.get("channel_subscribed")
|
||||||
|
if subscribed is not None:
|
||||||
|
channel_sub = ChannelSubscription()
|
||||||
|
json_data = channel_sub.change_subscribe(channel_id, subscribed)
|
||||||
|
return Response(json_data, status=200)
|
||||||
|
|
||||||
|
if "channel_overwrites" not in data:
|
||||||
return Response({"error": "invalid payload"}, status=400)
|
return Response({"error": "invalid payload"}, status=400)
|
||||||
|
|
||||||
overwrites = data["channel_overwrites"]
|
overwrites = data["channel_overwrites"]
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ class ChannelSubscription:
|
|||||||
channel.upload_to_es()
|
channel.upload_to_es()
|
||||||
channel.sync_to_videos()
|
channel.sync_to_videos()
|
||||||
|
|
||||||
|
return channel.json_data
|
||||||
|
|
||||||
|
|
||||||
class VideoQueryBuilder:
|
class VideoQueryBuilder:
|
||||||
"""Build queries for yt-dlp."""
|
"""Build queries for yt-dlp."""
|
||||||
@@ -280,6 +282,7 @@ class PlaylistSubscription:
|
|||||||
playlist.build_json()
|
playlist.build_json()
|
||||||
playlist.json_data["playlist_subscribed"] = subscribe_status
|
playlist.json_data["playlist_subscribed"] = subscribe_status
|
||||||
playlist.upload_to_es()
|
playlist.upload_to_es()
|
||||||
|
return playlist.json_data
|
||||||
|
|
||||||
def find_missing(self):
|
def find_missing(self):
|
||||||
"""find videos in subscribed playlists not downloaded yet"""
|
"""find videos in subscribed playlists not downloaded yet"""
|
||||||
@@ -426,7 +429,7 @@ class SubscriptionHandler:
|
|||||||
|
|
||||||
def _subscribe(self, channel_id):
|
def _subscribe(self, channel_id):
|
||||||
"""subscribe to channel"""
|
"""subscribe to channel"""
|
||||||
ChannelSubscription().change_subscribe(
|
_ = ChannelSubscription().change_subscribe(
|
||||||
channel_id, channel_subscribed=True
|
channel_id, channel_subscribed=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class PlaylistApiListView(ApiBaseView):
|
|||||||
def _unsubscribe(playlist_id: str):
|
def _unsubscribe(playlist_id: str):
|
||||||
"""unsubscribe"""
|
"""unsubscribe"""
|
||||||
print(f"[{playlist_id}] unsubscribe from playlist")
|
print(f"[{playlist_id}] unsubscribe from playlist")
|
||||||
PlaylistSubscription().change_subscribe(
|
_ = PlaylistSubscription().change_subscribe(
|
||||||
playlist_id, subscribe_status=False
|
playlist_id, subscribe_status=False
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -85,8 +85,18 @@ class PlaylistApiView(ApiBaseView):
|
|||||||
|
|
||||||
def post(self, request, playlist_id):
|
def post(self, request, playlist_id):
|
||||||
"""post to custom playlist to add a video to list"""
|
"""post to custom playlist to add a video to list"""
|
||||||
playlist = YoutubePlaylist(playlist_id)
|
self.get_document(playlist_id)
|
||||||
if not playlist.is_custom_playlist():
|
if not self.response["data"]:
|
||||||
|
return Response({"error": "playlist not found"}, status=404)
|
||||||
|
|
||||||
|
data = request.data
|
||||||
|
subscribed = data.get("playlist_subscribed")
|
||||||
|
if subscribed is not None:
|
||||||
|
playlist_sub = PlaylistSubscription()
|
||||||
|
json_data = playlist_sub.change_subscribe(playlist_id, subscribed)
|
||||||
|
return Response(json_data, status=200)
|
||||||
|
|
||||||
|
if not self.response["data"]["playlist_type"] == "custom":
|
||||||
message = f"playlist with ID {playlist_id} is not custom"
|
message = f"playlist with ID {playlist_id} is not custom"
|
||||||
return Response({"message": message}, status=400)
|
return Response({"message": message}, status=400)
|
||||||
|
|
||||||
@@ -95,6 +105,7 @@ class PlaylistApiView(ApiBaseView):
|
|||||||
message = f"invalid action: {action}"
|
message = f"invalid action: {action}"
|
||||||
return Response({"message": message}, status=400)
|
return Response({"message": message}, status=400)
|
||||||
|
|
||||||
|
playlist = YoutubePlaylist(playlist_id)
|
||||||
video_id = request.data.get("video_id")
|
video_id = request.data.get("video_id")
|
||||||
if action == "create":
|
if action == "create":
|
||||||
playlist.add_video_to_playlist(video_id)
|
playlist.add_video_to_playlist(video_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user