diff --git a/tubearchivist/api/README.md b/tubearchivist/api/README.md index dada701..c0889d3 100644 --- a/tubearchivist/api/README.md +++ b/tubearchivist/api/README.md @@ -213,3 +213,21 @@ POST /api/task/ List of valid task names: - **download_pending**: Start the download queue - **rescan_pending**: Rescan your subscriptions + + +## Cookie View +Check your youtube cookie settings +GET /api/cookie/ +```json +{ + "cookie_enabled": true +} +``` + +POST /api/cookie/ +Send empty post request to validate cookie. +```json +{ + "cookie_validated": true +} +``` diff --git a/tubearchivist/api/urls.py b/tubearchivist/api/urls.py index e059f75..eedcbe2 100644 --- a/tubearchivist/api/urls.py +++ b/tubearchivist/api/urls.py @@ -4,6 +4,7 @@ from api.views import ( ChannelApiListView, ChannelApiVideoView, ChannelApiView, + CookieView, DownloadApiListView, DownloadApiView, LoginApiView, @@ -87,4 +88,9 @@ urlpatterns = [ TaskApiView.as_view(), name="api-task", ), + path( + "cookie/", + CookieView.as_view(), + name="api-cookie", + ), ] diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index 88b8a0e..fe07637 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -3,6 +3,7 @@ from api.src.search_processor import SearchProcess from api.src.task_processor import TaskHandler from home.src.download.queue import PendingInteract +from home.src.download.yt_cookie import CookieHandler from home.src.es.connect import ElasticWrap from home.src.index.generic import Pagination from home.src.index.video import SponsorBlock @@ -462,3 +463,27 @@ class TaskApiView(ApiBaseView): response = TaskHandler(data).run_task() return Response(response) + + +class CookieView(ApiBaseView): + """resolves to /api/cookie/ + GET: check if cookie is enabled + POST: verify validity of cookie + """ + + @staticmethod + def get(request): + """handle get request""" + # pylint: disable=unused-argument + config = AppConfig().config + cookie_enabled = config["downloads"]["cookie_import"] + + return Response({"cookie_enabled": cookie_enabled}) + + @staticmethod + def post(request): + """handle post request""" + # pylint: disable=unused-argument + validated = CookieHandler().validate() + + return Response({"cookie_validated": validated})