simulate sponsorblock post request

This commit is contained in:
simon 2022-04-05 21:51:45 +07:00
parent bace7d41af
commit 286b1cf9b6
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 36 additions and 0 deletions

View File

@ -11,6 +11,7 @@ from api.views import (
VideoApiListView,
VideoApiView,
VideoProgressView,
VideoSponsorView,
)
from django.urls import path
@ -32,6 +33,11 @@ urlpatterns = [
VideoProgressView.as_view(),
name="api-video-progress",
),
path(
"video/<slug:video_id>/sponsor/",
VideoSponsorView.as_view(),
name="api-video-sponsor",
),
path(
"channel/",
ChannelApiListView.as_view(),

View File

@ -3,6 +3,7 @@
from api.src.search_processor import SearchProcess
from home.src.download.thumbnails import ThumbManager
from home.src.es.connect import ElasticWrap
from home.src.index.video import SponsorBlock
from home.src.ta.config import AppConfig
from home.src.ta.helper import UrlListParser
from home.src.ta.ta_redis import RedisArchivist
@ -144,6 +145,35 @@ class VideoProgressView(ApiBaseView):
return Response(self.response)
class VideoSponsorView(ApiBaseView):
"""resolves to /api/video/<video_id>/
handle sponsor block integration
"""
search_base = "ta_video/_doc/"
def get(self, request, video_id):
"""get sponsor info"""
# pylint: disable=unused-argument
self.get_document(video_id)
sponsorblock = self.response["data"].get("sponsorblock")
return Response(sponsorblock)
@staticmethod
def post(request, video_id):
"""post verification and timestamps"""
start_time = request.data.get("startTime")
end_time = request.data.get("endTime")
response, status_code = SponsorBlock(request.user.id).post_timestamps(
video_id, start_time, end_time
)
return Response(response, status=status_code)
class ChannelApiView(ApiBaseView):
"""resolves to /api/channel/<channel_id>/
GET: returns metadata dict of channel