add playlist/channel detail subscribed update, #862

This commit is contained in:
Simon 2025-01-06 22:37:16 +07:00
parent a7fb5d9939
commit b83e16f3ab
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 29 additions and 5 deletions

View File

@ -89,8 +89,18 @@ class ChannelApiView(ApiBaseView):
def post(self, request, channel_id):
"""modify channel overwrites"""
self.get_document(channel_id)
if not self.response["data"]:
return Response({"error": "channel not found"}, status=404)
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)
overwrites = data["channel_overwrites"]

View File

@ -123,6 +123,8 @@ class ChannelSubscription:
channel.upload_to_es()
channel.sync_to_videos()
return channel.json_data
class VideoQueryBuilder:
"""Build queries for yt-dlp."""
@ -280,6 +282,7 @@ class PlaylistSubscription:
playlist.build_json()
playlist.json_data["playlist_subscribed"] = subscribe_status
playlist.upload_to_es()
return playlist.json_data
def find_missing(self):
"""find videos in subscribed playlists not downloaded yet"""
@ -426,7 +429,7 @@ class SubscriptionHandler:
def _subscribe(self, channel_id):
"""subscribe to channel"""
ChannelSubscription().change_subscribe(
_ = ChannelSubscription().change_subscribe(
channel_id, channel_subscribed=True
)

View File

@ -63,7 +63,7 @@ class PlaylistApiListView(ApiBaseView):
def _unsubscribe(playlist_id: str):
"""unsubscribe"""
print(f"[{playlist_id}] unsubscribe from playlist")
PlaylistSubscription().change_subscribe(
_ = PlaylistSubscription().change_subscribe(
playlist_id, subscribe_status=False
)
@ -85,8 +85,18 @@ class PlaylistApiView(ApiBaseView):
def post(self, request, playlist_id):
"""post to custom playlist to add a video to list"""
playlist = YoutubePlaylist(playlist_id)
if not playlist.is_custom_playlist():
self.get_document(playlist_id)
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"
return Response({"message": message}, status=400)
@ -95,6 +105,7 @@ class PlaylistApiView(ApiBaseView):
message = f"invalid action: {action}"
return Response({"message": message}, status=400)
playlist = YoutubePlaylist(playlist_id)
video_id = request.data.get("video_id")
if action == "create":
playlist.add_video_to_playlist(video_id)