From 79b0a989be70ebc3c1fa4cf0448dc713039ddb9c Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 15 Jan 2022 14:14:18 +0700 Subject: [PATCH] new api view to return video player --- tubearchivist/api/README.md | 4 ++++ tubearchivist/api/urls.py | 6 ++++++ tubearchivist/api/views.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/tubearchivist/api/README.md b/tubearchivist/api/README.md index 73dd4fc..0e74a11 100644 --- a/tubearchivist/api/README.md +++ b/tubearchivist/api/README.md @@ -23,6 +23,10 @@ response = requests.get(url, headers=headers) ## Video Item View /api/video/\/ +## Video Player View +returns all relevant information to create video player +/api/video/\/player + ## Channel List View /api/channel/ diff --git a/tubearchivist/api/urls.py b/tubearchivist/api/urls.py index d39dc30..a6c6801 100644 --- a/tubearchivist/api/urls.py +++ b/tubearchivist/api/urls.py @@ -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//player/", + VideoApiPlayerView.as_view(), + name="api-video-player", + ), path( "channel/", ChannelApiListView.as_view(), diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index 745a5eb..165ca60 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -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//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// GET: returns metadata dict of channel