mirror of
https://github.com/revanced/revanced-api.git
synced 2025-04-30 14:44:28 +02:00

* feat: sanic framework settings * feat: initial implementation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor: backend changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: docstrings out of place * feat: more gh endpoints * ci: fix pre-commit issues * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat: app info * ci: merge CI and fix triggers * chore: bump deps * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: typing issues * chore: deps * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor: clean up returns * ci: spread jobs correctly * ci: move to quodana * ci: fix issues with python modules * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore: pycharm config * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor: improve code quality * feat: better README * ci: add quodana baseline config * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ci: fix quodana config * ci: more qodana stuff * ci: revert qodana changes * ci: python interpreter detection is broken * feat: tests * ci: testing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ci: fix workflow names * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore: add deps * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * test: more tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat: /tools compat * feat: donations endpoint * feat: teams endpoint * fix: lock pydantic version * chore: deps * ci: docker builds * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ci: remove coverage action and others * ci: pre-commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
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)
|