new api view to return video player

This commit is contained in:
simon 2022-01-15 14:14:18 +07:00
parent cccb8e570a
commit 79b0a989be
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 43 additions and 0 deletions

View File

@ -23,6 +23,10 @@ response = requests.get(url, headers=headers)
## Video Item View
/api/video/\<video_id>/
## Video Player View
returns all relevant information to create video player
/api/video/\<video_id>/player
## Channel List View
/api/channel/

View File

@ -6,6 +6,7 @@ from api.views import (
DownloadApiListView,
DownloadApiView,
PlaylistApiView,
VideoApiPlayerView,
VideoApiView,
)
from django.urls import path
@ -16,6 +17,11 @@ urlpatterns = [
VideoApiView.as_view(),
name="api-video",
),
path(
"video/<slug:video_id>/player/",
VideoApiPlayerView.as_view(),
name="api-video-player",
),
path(
"channel/",
ChannelApiListView.as_view(),

View File

@ -3,6 +3,7 @@
import requests
from home.src.config import AppConfig
from home.src.helper import UrlListParser
from home.src.thumbnails import ThumbManager
from home.tasks import extrac_dl, subscribe_to
from rest_framework.authentication import (
SessionAuthentication,
@ -77,6 +78,38 @@ class VideoApiView(ApiBaseView):
return Response(self.response, status=self.status_code)
class VideoApiPlayerView(ApiBaseView):
"""resolves to /api/video/<video_id>/player
GET: returns dict of video to build player
"""
search_base = "/ta_video/_doc/"
def get(self, request, video_id):
# pylint: disable=unused-argument
"""get request"""
self.config_builder()
self.get_document(video_id)
player = self.process_response()
return Response(player, status=self.status_code)
def process_response(self):
"""build all needed vars for player"""
vid_data = self.response["data"]
youtube_id = vid_data["youtube_id"]
vid_thumb_url = ThumbManager().vid_thumb_path(youtube_id)
player = {
"youtube_id": youtube_id,
"media_url": "/media/" + vid_data["media_url"],
"vid_thumb_url": "/cache/" + vid_thumb_url,
"title": vid_data["title"],
"channel_name": vid_data["channel"]["channel_name"],
"channel_id": vid_data["channel"]["channel_id"],
"is_watched": vid_data["player"]["watched"],
}
return player
class ChannelApiView(ApiBaseView):
"""resolves to /api/channel/<channel_id>/
GET: returns metadata dict of channel