From ed21441f9ff263a094f60c2d925093294d5c1cfa Mon Sep 17 00:00:00 2001 From: Kentai Radiquum Date: Thu, 18 Apr 2024 23:00:04 +0500 Subject: [PATCH] Changelog: Backend: - ADD Search API - EXTEND Release API --- backend/main.py | 6 +++ backend/modules/pages/search.py | 14 +++++++ backend/modules/proxy.py | 10 ++++- backend/modules/release/release.py | 65 +++++++++++++++++++++++++++++- 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 backend/modules/pages/search.py diff --git a/backend/main.py b/backend/main.py index 0691dc3..a694361 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2,6 +2,7 @@ import uvicorn from fastapi import FastAPI from modules.pages import favorites from modules.pages import index +from modules.pages import search from modules.release import release from modules.user import auth from modules.user import profile @@ -23,6 +24,10 @@ TAGS = [ "name": "Favorites", "description": "Favorites API requests", }, + { + "name": "Search", + "description": "Search API requests", + }, ] app = FastAPI() @@ -34,6 +39,7 @@ app.include_router(release.router, prefix="/release", tags=["Releases"]) app.include_router(index.router, prefix="/index", tags=["Index"]) app.include_router(favorites.router, prefix="/favorites", tags=["Favorites"]) +app.include_router(search.router, prefix="/search", tags=["Search"]) if __name__ == "__main__": uvicorn.run("main:app", host="0.0.0.0", port=8000) diff --git a/backend/modules/pages/search.py b/backend/modules/pages/search.py new file mode 100644 index 0000000..e49790a --- /dev/null +++ b/backend/modules/pages/search.py @@ -0,0 +1,14 @@ +import json + +from fastapi import APIRouter +from fastapi import Request +from modules.proxy import apiRequest +from modules.proxy import ENDPOINTS + +router = APIRouter() + + +@router.post("", summary="Search for a release") +async def Search(request: Request, query: str, page: int = 0): + data = json.dumps({"query": query, "searchBy": 0}) + return await apiRequest(request, ENDPOINTS["search"], page, data=data) diff --git a/backend/modules/proxy.py b/backend/modules/proxy.py index 7176c2f..756d776 100644 --- a/backend/modules/proxy.py +++ b/backend/modules/proxy.py @@ -5,7 +5,10 @@ from fastapi import Request API_URL = "https://api.anixart.tv" ENDPOINTS = { - "release": f"{API_URL}/release", + "release": { + "info": f"{API_URL}/release", + "episode": f"{API_URL}/episode", + }, "profile": f"{API_URL}/profile", "filter": f"{API_URL}/filter", "auth": f"{API_URL}/auth/signIn", @@ -17,6 +20,11 @@ ENDPOINTS = { "delayed": f"{API_URL}/profile/list/all/4", "abandoned": f"{API_URL}/profile/list/all/5", }, + "search": f"{API_URL}/search/releases", + "statistic": { + "addHistory": f"{API_URL}/history/add", + "markWatched": f"{API_URL}/episode/watch", + }, } USER_AGENT = "AnixartApp/8.2.1-23121216 (Android 11; SDK 30; arm64-v8a;)" diff --git a/backend/modules/release/release.py b/backend/modules/release/release.py index 45009fb..53345e3 100644 --- a/backend/modules/release/release.py +++ b/backend/modules/release/release.py @@ -8,4 +8,67 @@ router = APIRouter() @router.get("/{release_id}", summary="Get release info by release ID") async def GetReleaseById(request: Request, release_id: str): - return await apiRequest(request, ENDPOINTS["release"], release_id) + return await apiRequest(request, ENDPOINTS["release"]["info"], release_id) + + +@router.get( + "/{release_id}/voiceover", summary="Get release voiceover info by release ID" +) +async def GetReleaseVoiceover(request: Request, release_id: str): + return await apiRequest(request, ENDPOINTS["release"]["episode"], release_id) + + +@router.get( + "/{release_id}/{voiceover_id}", + summary="Get available players for selected voiceover of an release", +) +async def GetReleaseVoiceoverPlayer( + request: Request, release_id: str, voiceover_id: str +): + return await apiRequest( + request, ENDPOINTS["release"]["episode"], f"{release_id}/{voiceover_id}" + ) + + +@router.get( + "/{release_id}/{voiceover_id}/{source_id}", + summary="Get available episodes for selected voiceover and a player of an release", +) +async def GetReleaseEpisodes( + request: Request, release_id: str, voiceover_id: str, source_id: str +): + return await apiRequest( + request, + ENDPOINTS["release"]["episode"], + f"{release_id}/{voiceover_id}/{source_id}", + ) + + +@router.get( + "/{release_id}/{episode}/markWatched", + summary="mark episode of a selected voiceover as watched", +) +async def MarkEpisodeAsWatched( + request: Request, release_id: str, source_id: str, episode: str, token: str +): + return await apiRequest( + request, + ENDPOINTS["statistic"]["markWatched"], + f"${release_id}/${source_id}/${episode}", + query=f"?token={token}", + ) + + +@router.get( + "/{release_id}/{episode}/addHistory", + summary="mark episode of a selected voiceover as watched", +) +async def AddEpisodeToHistory( + request: Request, release_id: str, source_id: str, episode: str, token: str +): + return await apiRequest( + request, + ENDPOINTS["statistic"]["addHistory"], + f"${release_id}/${source_id}/${episode}", + query=f"?token={token}", + )