implement vote on sponsorblock segments api

This commit is contained in:
simon 2022-04-05 22:25:40 +07:00
parent 286b1cf9b6
commit 03dd25cff4
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 40 additions and 6 deletions

View File

@ -146,7 +146,7 @@ class VideoProgressView(ApiBaseView):
class VideoSponsorView(ApiBaseView):
"""resolves to /api/video/<video_id>/
"""resolves to /api/video/<video_id>/sponsor/
handle sponsor block integration
"""
@ -161,17 +161,37 @@ class VideoSponsorView(ApiBaseView):
return Response(sponsorblock)
@staticmethod
def post(request, video_id):
def post(self, request, video_id):
"""post verification and timestamps"""
start_time = request.data.get("startTime")
end_time = request.data.get("endTime")
if "segment" in request.data:
response, status_code = self._create_segment(request, video_id)
elif "vote" in request.data:
response, status_code = self._vote_on_segment(request)
return Response(response, status=status_code)
@staticmethod
def _create_segment(request, video_id):
"""create segment in API"""
start_time = request.data["segment"]["startTime"]
end_time = request.data["segment"]["endTime"]
response, status_code = SponsorBlock(request.user.id).post_timestamps(
video_id, start_time, end_time
)
return Response(response, status=status_code)
return response, status_code
@staticmethod
def _vote_on_segment(request):
"""validate on existing segment"""
user_id = request.user.id
uuid = request.data["vote"]["uuid"]
vote = request.data["vote"]["yourVote"]
response, status_code = SponsorBlock(user_id).vote_on_segment(
uuid, vote
)
return response, status_code
class ChannelApiView(ApiBaseView):

View File

@ -335,6 +335,20 @@ class SponsorBlock:
return {"success": True}, 200
def vote_on_segment(self, uuid, vote):
"""send vote on existing segment"""
user_id = self.get_sb_id().get("status")
data = {
"UUID": uuid,
"userID": user_id,
"type": vote,
}
url = f"{self.API}/api/voteOnSponsorTime"
print(f"post: {data}")
print(f"to: {url}")
return {"success": True}, 200
class YoutubeVideo(YouTubeItem, YoutubeSubtitle):
"""represents a single youtube video"""