mirror of
https://github.com/revanced/revanced-api.git
synced 2025-06-13 05:37:44 +02:00
feat: remove appinfo capabilities
This commit is contained in:

committed by
Alexandre Teles (afterSt0rm)

parent
5482d9c442
commit
10f5225f51
32
api/apkdl.py
32
api/apkdl.py
@ -1,32 +0,0 @@
|
||||
"""
|
||||
This module provides a blueprint for the app endpoint.
|
||||
|
||||
Routes:
|
||||
- GET /app/info: Get app info.
|
||||
"""
|
||||
|
||||
from sanic import Blueprint, Request
|
||||
from sanic.response import JSONResponse, json
|
||||
from sanic_ext import openapi
|
||||
|
||||
from api.backends.apkdl import ApkDl
|
||||
from api.backends.entities import AppInfo
|
||||
from api.models.appinfo import AppInfoModel
|
||||
|
||||
from config import api_version
|
||||
|
||||
apkdl: Blueprint = Blueprint("app", version=api_version)
|
||||
|
||||
apkdl_backend: ApkDl = ApkDl()
|
||||
|
||||
|
||||
@apkdl.get("/app/info/<app_id:str>")
|
||||
@openapi.definition(
|
||||
summary="Get information about an app",
|
||||
response=[AppInfoModel],
|
||||
)
|
||||
async def root(request: Request, app_id: str) -> JSONResponse:
|
||||
data: dict[str, AppInfo] = {
|
||||
"app_info": await apkdl_backend.get_app_info(package_name=app_id)
|
||||
}
|
||||
return json(data, status=200)
|
@ -1,64 +0,0 @@
|
||||
from base64 import b64encode
|
||||
|
||||
from aiohttp import ClientResponse
|
||||
from bs4 import BeautifulSoup
|
||||
from sanic import SanicException
|
||||
from toolz.functoolz import compose
|
||||
|
||||
from api.backends.backend import AppInfoProvider
|
||||
from api.backends.entities import AppInfo
|
||||
from api.utils.http_utils import http_get
|
||||
|
||||
name: str = "apkdl"
|
||||
base_url: str = "https://apk-dl.com"
|
||||
|
||||
|
||||
class ApkDl(AppInfoProvider):
|
||||
def __init__(self):
|
||||
super().__init__(name, base_url)
|
||||
|
||||
async def get_app_info(self, package_name: str) -> AppInfo:
|
||||
"""Fetches information about an Android app from the ApkDl website.
|
||||
|
||||
Args:
|
||||
package_name (str): The package name of the app to fetch.
|
||||
|
||||
Returns:
|
||||
AppInfo: An AppInfo object containing the name, category, and logo of the app.
|
||||
|
||||
Raises:
|
||||
SanicException: If the HTTP request fails or the app data is incomplete or not found.
|
||||
"""
|
||||
app_url: str = f"{base_url}/{package_name}"
|
||||
response: ClientResponse = await http_get(headers={}, url=app_url)
|
||||
if response.status != 200:
|
||||
raise SanicException(
|
||||
f"ApkDl: {response.status}", status_code=response.status
|
||||
)
|
||||
page = BeautifulSoup(await response.read(), "lxml")
|
||||
find_div_text = compose(
|
||||
lambda d: d.find_next_sibling("div"),
|
||||
lambda d: page.find("div", text=d),
|
||||
)
|
||||
fetch_logo_url = compose(
|
||||
lambda div: div.img["src"],
|
||||
lambda _: page.find("div", {"class": "logo"}),
|
||||
)
|
||||
logo_response: ClientResponse = await http_get(
|
||||
headers={}, url=fetch_logo_url(None)
|
||||
)
|
||||
logo: str = (
|
||||
f"data:image/png;base64,{b64encode(await logo_response.content.read()).decode('utf-8')}"
|
||||
if logo_response.status == 200
|
||||
else ""
|
||||
)
|
||||
app_data = dict(
|
||||
name=find_div_text("App Name").text,
|
||||
category=find_div_text("Category").text,
|
||||
logo=logo,
|
||||
)
|
||||
if not all(app_data.values()):
|
||||
raise SanicException(
|
||||
"ApkDl: App data incomplete or not found", status_code=500
|
||||
)
|
||||
return AppInfo(**app_data)
|
@ -1,19 +0,0 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class AppInfoFields(BaseModel):
|
||||
"""
|
||||
Fields for the AppInfo endpoint.
|
||||
"""
|
||||
|
||||
name: str
|
||||
category: str
|
||||
logo: str
|
||||
|
||||
|
||||
class AppInfoModel(BaseModel):
|
||||
"""
|
||||
Response model app info.
|
||||
"""
|
||||
|
||||
app_info: AppInfoFields
|
Reference in New Issue
Block a user