mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
🎨 Added apkmonk icon scrapper (#327)
This commit is contained in:
+46
-4
@@ -12,11 +12,13 @@ from src.downloader.sources import (
|
||||
APK_COMBO_GENERIC_URL,
|
||||
APK_MIRROR_BASE_URL,
|
||||
APK_MIRROR_PACKAGE_URL,
|
||||
APK_MONK_APK_URL,
|
||||
APK_MONK_ICON_URL,
|
||||
PLAY_STORE_APK_URL,
|
||||
not_found_icon,
|
||||
revanced_api,
|
||||
)
|
||||
from src.exceptions import APKComboIconScrapError, APKMirrorIconScrapError, UnknownError
|
||||
from src.exceptions import APKComboIconScrapError, APKMirrorIconScrapError, APKMonkIconScrapError, UnknownError
|
||||
from src.patches import Patches
|
||||
from src.utils import apkmirror_status_check, bs4_parser, handle_request_response, request_header
|
||||
|
||||
@@ -42,6 +44,43 @@ def apkcombo_scrapper(package_name: str) -> str:
|
||||
raise APKComboIconScrapError(url=apkcombo_url) from e
|
||||
|
||||
|
||||
def bigger_image(possible_links: List[str]) -> str:
|
||||
"""Select image with higher dimension."""
|
||||
higher_dimension_url = ""
|
||||
max_dimension = 0
|
||||
|
||||
for url in possible_links:
|
||||
dimensions = url.split("_")[-1].split(".")[0].split("x")
|
||||
width = int(dimensions[0])
|
||||
height = int(dimensions[1])
|
||||
|
||||
area = width * height
|
||||
|
||||
if area > max_dimension:
|
||||
max_dimension = area
|
||||
higher_dimension_url = url
|
||||
|
||||
return higher_dimension_url
|
||||
|
||||
|
||||
def apkmonk_scrapper(package_name: str) -> str:
|
||||
"""APKMonk scrapper."""
|
||||
apkmonk_url = APK_MONK_APK_URL.format(package_name)
|
||||
icon_logo = APK_MONK_ICON_URL.format(package_name)
|
||||
r = requests.get(apkmonk_url, headers=combo_headers, allow_redirects=True, timeout=60)
|
||||
if head := BeautifulSoup(r.text, bs4_parser).head:
|
||||
parsed_head = BeautifulSoup(str(head), bs4_parser)
|
||||
href_elements = parsed_head.find_all(href=True)
|
||||
possible_link = []
|
||||
for element in href_elements:
|
||||
href_value = element.get("href")
|
||||
if href_value.startswith(icon_logo):
|
||||
possible_link.append(href_value)
|
||||
if possible_link:
|
||||
return bigger_image(possible_link)
|
||||
raise APKMonkIconScrapError(url=apkmonk_url)
|
||||
|
||||
|
||||
def apkmirror_scrapper(package_name: str) -> str:
|
||||
"""Apkmirror URL."""
|
||||
response = apkmirror_status_check(package_name)
|
||||
@@ -92,7 +131,10 @@ def icon_scrapper(package_name: str) -> str:
|
||||
try:
|
||||
return apkcombo_scrapper(package_name)
|
||||
except APKComboIconScrapError:
|
||||
return not_found_icon
|
||||
try:
|
||||
return apkmonk_scrapper(package_name)
|
||||
except APKMonkIconScrapError:
|
||||
return not_found_icon
|
||||
except UnknownError:
|
||||
return not_found_icon
|
||||
|
||||
@@ -103,7 +145,7 @@ def generate_markdown_table(data: List[List[str]]) -> str:
|
||||
return "No data to generate for the table."
|
||||
|
||||
table = (
|
||||
"| Package Name | App Icon | PlayStore link | APKMirror link|APKCombo Link| Supported?|\n"
|
||||
"| Package Name | App Icon | PlayStore link | APKMirror link|APKMonk Link| Supported?|\n"
|
||||
"|-------------|----------|----------------|---------------|------------------|----------|\n"
|
||||
)
|
||||
for row in data:
|
||||
@@ -137,7 +179,7 @@ def main() -> None:
|
||||
f'<img src="{icon_scrapper(app)}" width=50 height=50>',
|
||||
f"[PlayStore Link]({PLAY_STORE_APK_URL.format(app)})",
|
||||
f"[APKMirror Link]({APK_MIRROR_PACKAGE_URL.format(app)})",
|
||||
f"[APKCombo Link]({APK_COMBO_GENERIC_URL.format(app)})",
|
||||
f"[APKMonk Link]({APK_MONK_APK_URL.format(app)})",
|
||||
"<li>- [ ] </li>",
|
||||
]
|
||||
for app in missing_support
|
||||
|
||||
@@ -17,6 +17,7 @@ not_found_icon = "https://img.icons8.com/bubbles/500/android-os.png"
|
||||
revanced_api = "https://releases.revanced.app/patches"
|
||||
APK_MONK_BASE_URL = "https://www.apkmonk.com"
|
||||
APK_MONK_APK_URL = APK_MONK_BASE_URL + "/app/{}/"
|
||||
APK_MONK_ICON_URL = "https://cdn.apkmonk.com/logos/{}"
|
||||
apk_sources = {
|
||||
"backdrops": f"{APK_MIRROR_BASE_APK_URL}/backdrops/backdrops-wallpapers/",
|
||||
"bacon": f"{APK_MIRROR_BASE_APK_URL}/onelouder-apps/baconreader-for-reddit/",
|
||||
|
||||
@@ -22,6 +22,10 @@ class APKComboIconScrapError(APKMirrorIconScrapError):
|
||||
"""Exception raised when the icon cannot be scraped from apkcombo."""
|
||||
|
||||
|
||||
class APKMonkIconScrapError(APKMirrorIconScrapError):
|
||||
"""Exception raised when the icon cannot be scraped from apkmonk."""
|
||||
|
||||
|
||||
class DownloadError(Exception):
|
||||
"""Generic Download failure."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user