mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-05 07:44:38 +00:00
split to modules. ADD index page.
This commit is contained in:
parent
025ef2be93
commit
c82b6e7265
11 changed files with 120 additions and 53 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
# Python
|
||||
__pycache__
|
||||
venv
|
||||
.mypy_cache
|
||||
|
||||
# VSCode
|
||||
.VSCode
|
||||
|
|
|
@ -1,60 +1,16 @@
|
|||
import requests
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from fastapi import Request
|
||||
from modules.pages import index
|
||||
from modules.release import release
|
||||
from modules.user import profile
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
API_URL = "https://api.anixart.tv"
|
||||
ENDPOINTS = {
|
||||
"release": f"{API_URL}/release",
|
||||
"profile": f"{API_URL}/profile",
|
||||
}
|
||||
USER_AGENT = "AnixartApp/8.2.1-23121216 (Android 11; SDK 30; arm64-v8a;)"
|
||||
app.include_router(profile.router, prefix="/profile")
|
||||
|
||||
app.include_router(release.router, prefix="/release")
|
||||
|
||||
async def apiRequest(
|
||||
# noqa: E501
|
||||
request: Request = None,
|
||||
endpoint: str = "",
|
||||
path: str = "",
|
||||
query: str = "",
|
||||
):
|
||||
app.include_router(index.router, prefix="/page")
|
||||
|
||||
headers = {
|
||||
"User-Agent": USER_AGENT,
|
||||
"Content-Type": "application/json; charset=UTF-8",
|
||||
}
|
||||
|
||||
if request.method == "POST":
|
||||
r = requests.post(
|
||||
# noqa: E501
|
||||
f"{endpoint}/{path}{query}",
|
||||
headers=headers,
|
||||
data=await request.body(),
|
||||
)
|
||||
else:
|
||||
r = requests.get(f"{endpoint}/{path}{query}", headers=headers)
|
||||
|
||||
if r.status_code != 200:
|
||||
return {"error": r.text}
|
||||
return r.json()
|
||||
|
||||
|
||||
@app.get("/profile/{user_id}")
|
||||
async def getUserById(request: Request, user_id: str, short: bool = False):
|
||||
res = await apiRequest(request, ENDPOINTS["profile"], user_id)
|
||||
if short is False:
|
||||
return res
|
||||
return {
|
||||
"code": res["code"],
|
||||
"profile": {
|
||||
"id": res["profile"]["id"],
|
||||
"login": res["profile"]["login"],
|
||||
"avatar": res["profile"]["avatar"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@app.get("/release/{release_id}")
|
||||
async def GetReleaseById(request: Request, release_id: str):
|
||||
return await apiRequest(request, ENDPOINTS["release"], release_id)
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("main:app", host="0.0.0.0", port=8000)
|
||||
|
|
0
backend/modules/__init__.py
Normal file
0
backend/modules/__init__.py
Normal file
0
backend/modules/models/__init__.py
Normal file
0
backend/modules/models/__init__.py
Normal file
0
backend/modules/pages/__init__.py
Normal file
0
backend/modules/pages/__init__.py
Normal file
37
backend/modules/pages/index.py
Normal file
37
backend/modules/pages/index.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import json
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import Request
|
||||
from modules.proxy import apiRequest
|
||||
from modules.proxy import ENDPOINTS
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# TODO: Add filters?
|
||||
@router.post("/index", summary="Get main page")
|
||||
async def GetMainPage(request: Request, page: int = 0):
|
||||
|
||||
data = json.dumps(
|
||||
{
|
||||
"country": None,
|
||||
"season": None,
|
||||
"sort": 0,
|
||||
"studio": None,
|
||||
"age_ratings": [],
|
||||
"category_id": None,
|
||||
"end_year": None,
|
||||
"episode_duration_from": None,
|
||||
"episode_duration_to": None,
|
||||
"episodes_from": None,
|
||||
"episodes_to": None,
|
||||
"genres": [],
|
||||
"profile_list_exclusions": [],
|
||||
"start_year": None,
|
||||
"status_id": None,
|
||||
"types": [],
|
||||
"is_genres_exclude_mode_enabled": False,
|
||||
}
|
||||
)
|
||||
|
||||
return await apiRequest(request, ENDPOINTS["filter"], page, data=data)
|
41
backend/modules/proxy.py
Normal file
41
backend/modules/proxy.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from typing import Union
|
||||
|
||||
import requests
|
||||
from fastapi import Request
|
||||
|
||||
API_URL = "https://api.anixart.tv"
|
||||
ENDPOINTS = {
|
||||
"release": f"{API_URL}/release",
|
||||
"profile": f"{API_URL}/profile",
|
||||
"filter": f"{API_URL}/filter",
|
||||
}
|
||||
USER_AGENT = "AnixartApp/8.2.1-23121216 (Android 11; SDK 30; arm64-v8a;)"
|
||||
|
||||
|
||||
async def apiRequest(
|
||||
# noqa: E501
|
||||
request: Request = None,
|
||||
endpoint: str = "",
|
||||
path: str = "",
|
||||
query: str = "",
|
||||
data: Union[None, str, dict] = None,
|
||||
):
|
||||
|
||||
headers = {
|
||||
"User-Agent": USER_AGENT,
|
||||
"Content-Type": "application/json; charset=UTF-8",
|
||||
}
|
||||
|
||||
if request.method == "POST":
|
||||
r = requests.post(
|
||||
# noqa: E501
|
||||
f"{endpoint}/{path}{query}",
|
||||
headers=headers,
|
||||
data=data,
|
||||
)
|
||||
else:
|
||||
r = requests.get(f"{endpoint}/{path}{query}", headers=headers)
|
||||
|
||||
if r.status_code != 200:
|
||||
return {"error": r.text}
|
||||
return r.json()
|
0
backend/modules/release/__init__.py
Normal file
0
backend/modules/release/__init__.py
Normal file
11
backend/modules/release/release.py
Normal file
11
backend/modules/release/release.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from fastapi import APIRouter
|
||||
from fastapi import Request
|
||||
from modules.proxy import apiRequest
|
||||
from modules.proxy import ENDPOINTS
|
||||
|
||||
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)
|
0
backend/modules/user/__init__.py
Normal file
0
backend/modules/user/__init__.py
Normal file
21
backend/modules/user/profile.py
Normal file
21
backend/modules/user/profile.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from fastapi import APIRouter
|
||||
from fastapi import Request
|
||||
from modules.proxy import apiRequest
|
||||
from modules.proxy import ENDPOINTS
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/{user_id}", summary="Get user profile by user ID")
|
||||
async def getUserById(request: Request, user_id: str, short: bool = False):
|
||||
res = await apiRequest(request, ENDPOINTS["profile"], user_id)
|
||||
if short is False:
|
||||
return res
|
||||
return {
|
||||
"code": res["code"],
|
||||
"profile": {
|
||||
"id": res["profile"]["id"],
|
||||
"login": res["profile"]["login"],
|
||||
"avatar": res["profile"]["avatar"],
|
||||
},
|
||||
}
|
Loading…
Add table
Reference in a new issue