From cd3e9dd024e632dec16bfdb3743714381600f882 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 13 Apr 2022 09:51:15 +0700 Subject: [PATCH] add playlist API list view --- tubearchivist/api/README.md | 3 +++ tubearchivist/api/src/search_processor.py | 18 ++++++++++++++++++ tubearchivist/api/urls.py | 6 ++++++ tubearchivist/api/views.py | 16 ++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/tubearchivist/api/README.md b/tubearchivist/api/README.md index 3c019cd..65cab1f 100644 --- a/tubearchivist/api/README.md +++ b/tubearchivist/api/README.md @@ -123,6 +123,9 @@ POST /api/channel/ ## Channel Item View /api/channel/\/ +## Playlist List View +/api/playlist/ + ## Playlists Item View /api/playlist/\/ diff --git a/tubearchivist/api/src/search_processor.py b/tubearchivist/api/src/search_processor.py index dc0a5db..0fc672b 100644 --- a/tubearchivist/api/src/search_processor.py +++ b/tubearchivist/api/src/search_processor.py @@ -40,6 +40,8 @@ class SearchProcess: processed = self._process_video(result["_source"]) if index == "ta_channel": processed = self._process_channel(result["_source"]) + if index == "ta_playlist": + processed = self._process_playlist(result["_source"]) return processed @@ -80,3 +82,19 @@ class SearchProcess: ) return dict(sorted(video_dict.items())) + + @staticmethod + def _process_playlist(playlist_dict): + """run on single playlist dict""" + playlist_id = playlist_dict["playlist_id"] + playlist_last_refresh = date_praser( + playlist_dict["playlist_last_refresh"] + ) + playlist_dict.update( + { + "playlist_thumbnail": f"/cache/playlists/{playlist_id}.jpg", + "playlist_last_refresh": playlist_last_refresh, + } + ) + + return dict(sorted(playlist_dict.items())) diff --git a/tubearchivist/api/urls.py b/tubearchivist/api/urls.py index 0cdf11a..cb70e4c 100644 --- a/tubearchivist/api/urls.py +++ b/tubearchivist/api/urls.py @@ -7,6 +7,7 @@ from api.views import ( DownloadApiView, LoginApiView, PingView, + PlaylistApiListView, PlaylistApiView, VideoApiListView, VideoApiView, @@ -53,6 +54,11 @@ urlpatterns = [ PlaylistApiView.as_view(), name="api-playlist", ), + path( + "playlist/", + PlaylistApiListView.as_view(), + name="api-playlist-list", + ), path( "download/", DownloadApiListView.as_view(), diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index 4ad216e..afe1c0b 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -258,6 +258,22 @@ class PlaylistApiView(ApiBaseView): return Response(self.response, status=self.status_code) +class PlaylistApiListView(ApiBaseView): + """resolves to /api/playlist/ + GET: returns list of indexed playlists + """ + + search_base = "ta_playlist/_search/" + + def get(self, request): + # pylint: disable=unused-argument + """handle get request""" + data = {"query": {"match_all": {}}} + self.get_document_list(data) + self.get_paginate() + return Response(self.response) + + class DownloadApiView(ApiBaseView): """resolves to /api/download// GET: returns metadata dict of an item in the download queue