From 265795f4a95937a3ba64228a547c483dd80a0b6a Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 17 Feb 2022 16:59:59 +0700 Subject: [PATCH 1/3] add config key to api response --- tubearchivist/api/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index 620c063..8ddd323 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -34,6 +34,7 @@ class ApiBaseView(APIView): "es_url": self.default_conf["application"]["es_url"], "es_auth": self.default_conf["application"]["es_auth"], } + self.response["config"] = self.default_conf def get_document(self, document_id): """get single document from es""" From 4d83af7c14226b0c3f845ce2b6eab66338e66973 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 17 Feb 2022 18:19:52 +0700 Subject: [PATCH 2/3] bump redis client --- tubearchivist/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubearchivist/requirements.txt b/tubearchivist/requirements.txt index fc21392..4cf2786 100644 --- a/tubearchivist/requirements.txt +++ b/tubearchivist/requirements.txt @@ -4,7 +4,7 @@ Django==4.0.2 django-cors-headers==3.11.0 djangorestframework==3.13.1 Pillow==9.0.1 -redis==4.1.3 +redis==4.1.4 requests==2.27.1 ryd-client==0.0.3 uWSGI==2.0.20 From 241d8326f75586b8e76c31117d42635ea98e7057 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 17 Feb 2022 18:20:30 +0700 Subject: [PATCH 3/3] add video progress API endpoints --- tubearchivist/api/README.md | 26 ++++++++++++++++++++++++ tubearchivist/api/urls.py | 6 ++++++ tubearchivist/api/views.py | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/tubearchivist/api/README.md b/tubearchivist/api/README.md index 73dd4fc..bc75eda 100644 --- a/tubearchivist/api/README.md +++ b/tubearchivist/api/README.md @@ -23,6 +23,32 @@ response = requests.get(url, headers=headers) ## Video Item View /api/video/\/ +## Video Progress View +/api/video/\/progress + +Progress is stored for each user. + +### Get last player position of a video +GET /api/video/\/progress +```json +{ + "youtube_id": "", + "user_id": 1, + "position": 100 +} +``` + +### Post player position of video +POST /api/video/\/progress +```json +{ + "position": 100 +} +``` + +### Delete player position of video +DELETE /api/video/\/progress + ## Channel List View /api/channel/ diff --git a/tubearchivist/api/urls.py b/tubearchivist/api/urls.py index d39dc30..8ba3dcf 100644 --- a/tubearchivist/api/urls.py +++ b/tubearchivist/api/urls.py @@ -7,6 +7,7 @@ from api.views import ( DownloadApiView, PlaylistApiView, VideoApiView, + VideoProgressView, ) from django.urls import path @@ -16,6 +17,11 @@ urlpatterns = [ VideoApiView.as_view(), name="api-video", ), + path( + "video//progress/", + VideoProgressView.as_view(), + name="api-video-progress", + ), path( "channel/", ChannelApiListView.as_view(), diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index 8ddd323..79932fa 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -4,6 +4,7 @@ import requests from home.src.download.thumbnails import ThumbManager from home.src.ta.config import AppConfig from home.src.ta.helper import UrlListParser +from home.src.ta.ta_redis import RedisArchivist from home.tasks import extrac_dl, subscribe_to from rest_framework.authentication import ( SessionAuthentication, @@ -99,6 +100,45 @@ class VideoApiView(ApiBaseView): return Response(self.response, status=self.status_code) +class VideoProgressView(APIView): + """resolves to /api/video// + handle progress status for video + """ + + @staticmethod + def get(request, video_id): + """get progress for a single video""" + user_id = request.user.id + key = f"{user_id}:progress:{video_id}" + video_progress = RedisArchivist().get_message(key) + position = video_progress.get("position", 0) + + progress = { + "youtube_id": video_id, + "user_id": user_id, + "position": position, + } + return Response(progress) + + @staticmethod + def post(request, video_id): + """set progress position in redis""" + position = request.data.get("position", 0) + key = f"{request.user.id}:progress:{video_id}" + message = {"position": position} + RedisArchivist().set_message(key, message, expire=False) + + return Response(request.data) + + @staticmethod + def delete(request, video_id): + """delete progress position""" + key = f"{request.user.id}:progress:{video_id}" + RedisArchivist().del_message(key) + + return Response({"progress-reset": video_id}) + + class ChannelApiView(ApiBaseView): """resolves to /api/channel// GET: returns metadata dict of channel