Merge branch 'testing' of https://github.com/bbilly1/tubearchivist into feat/react-frontend

This commit is contained in:
Sean Norwood 2022-04-17 04:30:34 +00:00
commit 5e5680a661
3 changed files with 69 additions and 11 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

@ -52,7 +52,10 @@ class ApiBaseView(APIView):
print(self.search_base) print(self.search_base)
response, status_code = ElasticWrap(self.search_base).get(data=data) response, status_code = ElasticWrap(self.search_base).get(data=data)
self.response["data"] = SearchProcess(response).process() self.response["data"] = SearchProcess(response).process()
self.status_code = status_code if self.response["data"]:
self.status_code = status_code
else:
self.status_code = 404
class VideoApiView(ApiBaseView): class VideoApiView(ApiBaseView):
@ -222,17 +225,22 @@ class ChannelApiListView(ApiBaseView):
return Response(data) return Response(data)
class PlaylistApiView(ApiBaseView): class ChannelApiVideoView(ApiBaseView):
"""resolves to /api/playlist/<playlist_id>/ """resolves to /api/channel/<channel-id>/video
GET: returns metadata dict of playlist GET: returns a list of videos of channel
""" """
search_base = "ta_playlist/_doc/" search_base = "ta_video/_search/"
def get(self, request, playlist_id): def get(self, request, channel_id):
# pylint: disable=unused-argument # pylint: disable=unused-argument
"""get request""" """handle get request"""
self.get_document(playlist_id) data = {
"query": {"term": {"channel.channel_id": {"value": channel_id}}}
}
self.get_document_list(data)
self.get_paginate()
return Response(self.response, status=self.status_code) return Response(self.response, status=self.status_code)
@ -252,6 +260,38 @@ class PlaylistApiListView(ApiBaseView):
return Response(self.response) return Response(self.response)
class PlaylistApiView(ApiBaseView):
"""resolves to /api/playlist/<playlist_id>/
GET: returns metadata dict of playlist
"""
search_base = "ta_playlist/_doc/"
def get(self, request, playlist_id):
# pylint: disable=unused-argument
"""get request"""
self.get_document(playlist_id)
return Response(self.response, status=self.status_code)
class PlaylistApiVideoView(ApiBaseView):
"""resolves to /api/playlist/<playlist_id>/video
GET: returns list of videos in playlist
"""
search_base = "ta_video/_search/"
def get(self, request, playlist_id):
# pylint: disable=unused-argument
"""handle get request"""
data = {
"query": {"term": {"playlist.keyword": {"value": playlist_id}}}
}
self.get_document_list(data)
self.get_paginate()
return Response(self.response, status=self.status_code)
class DownloadApiView(ApiBaseView): class DownloadApiView(ApiBaseView):
"""resolves to /api/download/<video_id>/ """resolves to /api/download/<video_id>/
GET: returns metadata dict of an item in the download queue GET: returns metadata dict of an item in the download queue