add playlist-video and channel-video api views

This commit is contained in:
simon 2022-04-17 09:58:18 +07:00
parent 7d45d23767
commit b8ca324aaf
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 64 additions and 9 deletions

View File

@ -123,12 +123,18 @@ POST /api/channel/
## Channel Item View ## Channel Item View
/api/channel/\<channel_id>/ /api/channel/\<channel_id>/
## Channel Videos View
/api/channel/\<channel_id>/video/
## Playlist List View ## Playlist List View
/api/playlist/ /api/playlist/
## Playlists Item View ## Playlists Item View
/api/playlist/\<playlist_id>/ /api/playlist/\<playlist_id>/
## Playlist Videos View
/api/playlist/\<playlist_id>/video/
## Download Queue List View ## Download Queue List View
/api/download/ /api/download/

View File

@ -2,12 +2,14 @@
from api.views import ( from api.views import (
ChannelApiListView, ChannelApiListView,
ChannelApiVideoView,
ChannelApiView, ChannelApiView,
DownloadApiListView, DownloadApiListView,
DownloadApiView, DownloadApiView,
LoginApiView, LoginApiView,
PingView, PingView,
PlaylistApiListView, PlaylistApiListView,
PlaylistApiVideoView,
PlaylistApiView, PlaylistApiView,
VideoApiListView, VideoApiListView,
VideoApiView, VideoApiView,
@ -50,15 +52,25 @@ urlpatterns = [
name="api-channel", name="api-channel",
), ),
path( path(
"playlist/<slug:playlist_id>/", "channel/<slug:channel_id>/video/",
PlaylistApiView.as_view(), ChannelApiVideoView.as_view(),
name="api-playlist", name="api-channel-video",
), ),
path( path(
"playlist/", "playlist/",
PlaylistApiListView.as_view(), PlaylistApiListView.as_view(),
name="api-playlist-list", name="api-playlist-list",
), ),
path(
"playlist/<slug:playlist_id>/",
PlaylistApiView.as_view(),
name="api-playlist",
),
path(
"playlist/<slug:playlist_id>/video/",
PlaylistApiVideoView.as_view(),
name="api-playlist-video",
),
path( path(
"download/", "download/",
DownloadApiListView.as_view(), DownloadApiListView.as_view(),

View File

@ -222,6 +222,41 @@ class ChannelApiListView(ApiBaseView):
return Response(data) return Response(data)
class ChannelApiVideoView(ApiBaseView):
"""resolves to /api/channel/<channel-id>/video
GET: returns a list of videos of channel
"""
search_base = "ta_video/_search/"
def get(self, request, channel_id):
# pylint: disable=unused-argument
"""handle get request"""
data = {
"query": {"term": {"channel.channel_id": {"value": channel_id}}}
}
self.get_document_list(data)
self.get_paginate()
return Response(self.response)
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 PlaylistApiView(ApiBaseView): class PlaylistApiView(ApiBaseView):
"""resolves to /api/playlist/<playlist_id>/ """resolves to /api/playlist/<playlist_id>/
GET: returns metadata dict of playlist GET: returns metadata dict of playlist
@ -236,17 +271,19 @@ class PlaylistApiView(ApiBaseView):
return Response(self.response, status=self.status_code) return Response(self.response, status=self.status_code)
class PlaylistApiListView(ApiBaseView): class PlaylistApiVideoView(ApiBaseView):
"""resolves to /api/playlist/ """resolves to /api/playlist/<playlist_id>/video
GET: returns list of indexed playlists GET: returns list of videos in playlist
""" """
search_base = "ta_playlist/_search/" search_base = "ta_video/_search/"
def get(self, request): def get(self, request, playlist_id):
# pylint: disable=unused-argument # pylint: disable=unused-argument
"""handle get request""" """handle get request"""
data = {"query": {"match_all": {}}} data = {
"query": {"term": {"playlist.keyword": {"value": playlist_id}}}
}
self.get_document_list(data) self.get_document_list(data)
self.get_paginate() self.get_paginate()
return Response(self.response) return Response(self.response)