implement channel list and subscribe api

This commit is contained in:
simon 2022-01-11 16:53:02 +07:00
parent 8d5b4ac242
commit 50006e423c
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 43 additions and 1 deletions

View File

@ -1,6 +1,7 @@
"""all api urls""" """all api urls"""
from api.views import ( from api.views import (
ChannelApiListView,
ChannelApiView, ChannelApiView,
DownloadApiListView, DownloadApiListView,
DownloadApiView, DownloadApiView,
@ -15,6 +16,11 @@ urlpatterns = [
VideoApiView.as_view(), VideoApiView.as_view(),
name="api-video", name="api-video",
), ),
path(
"channel/",
ChannelApiListView.as_view(),
name="api-channel-list",
),
path( path(
"channel/<slug:channel_id>/", "channel/<slug:channel_id>/",
ChannelApiView.as_view(), ChannelApiView.as_view(),

View File

@ -3,7 +3,7 @@
import requests import requests
from home.src.config import AppConfig from home.src.config import AppConfig
from home.src.helper import UrlListParser from home.src.helper import UrlListParser
from home.tasks import extrac_dl from home.tasks import extrac_dl, subscribe_to
from rest_framework.authentication import ( from rest_framework.authentication import (
SessionAuthentication, SessionAuthentication,
TokenAuthentication, TokenAuthentication,
@ -92,6 +92,42 @@ class ChannelApiView(ApiBaseView):
return Response(self.response, status=self.status_code) return Response(self.response, status=self.status_code)
class ChannelApiListView(ApiBaseView):
"""resolves to /api/channel/
GET: returns list of channels
POST: edit a list of channels
"""
search_base = "/ta_channel/_search/"
def get(self, request):
# pylint: disable=unused-argument
"""get request"""
data = {"query": {"match_all": {}}}
self.config_builder()
self.get_document_list(data)
self.get_paginate()
return Response(self.response)
@staticmethod
def post(request):
"""subscribe to list of channels"""
data = request.data
try:
to_add = data["data"]
except KeyError:
message = "missing expected data key"
print(message)
return Response({"message": message}, status=400)
pending = [i["channel_id"] for i in to_add if i["channel_subscribed"]]
url_str = " ".join(pending)
subscribe_to.delay(url_str)
return Response(data)
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