add playlist API list view

This commit is contained in:
simon 2022-04-13 09:51:15 +07:00
parent 8edde732b6
commit cd3e9dd024
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
4 changed files with 43 additions and 0 deletions

View File

@ -123,6 +123,9 @@ POST /api/channel/
## Channel Item View
/api/channel/\<channel_id>/
## Playlist List View
/api/playlist/
## Playlists Item View
/api/playlist/\<playlist_id>/

View File

@ -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()))

View File

@ -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(),

View File

@ -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/<video_id>/
GET: returns metadata dict of an item in the download queue