mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-24 19:38:36 +09:00
🎨 Chore (#289)
This commit is contained in:
+23
-17
@@ -7,7 +7,7 @@ from bs4 import BeautifulSoup
|
||||
from google_play_scraper import app as gplay_app
|
||||
from google_play_scraper.exceptions import GooglePlayScraperException
|
||||
|
||||
from src.exceptions import APKMirrorScrapperFailure
|
||||
from src.exceptions import APKMirrorIconScrapFailure
|
||||
from src.patches import Patches
|
||||
from src.utils import (
|
||||
apk_mirror_base_url,
|
||||
@@ -28,7 +28,9 @@ def apkcombo_scrapper(package_name: str) -> str:
|
||||
"""Apkcombo scrapper."""
|
||||
try:
|
||||
apkcombo_url = f"https://apkcombo.com/genericApp/{package_name}"
|
||||
r = requests.get(apkcombo_url, headers=headers, allow_redirects=True)
|
||||
r = requests.get(
|
||||
apkcombo_url, headers=headers, allow_redirects=True, timeout=10
|
||||
)
|
||||
soup = BeautifulSoup(r.text, bs4_parser)
|
||||
url = soup.select_one("div.avatar > img")["data-src"]
|
||||
return re.sub(r"=.*$", "", url)
|
||||
@@ -39,22 +41,26 @@ def apkcombo_scrapper(package_name: str) -> str:
|
||||
def apkmirror_scrapper(package_name: str) -> str:
|
||||
"""Apkmirror URL."""
|
||||
response = apkmirror_status_check(package_name)
|
||||
search_url = f"{apk_mirror_base_url}/?s={package_name}"
|
||||
if response["data"][0]["exists"]:
|
||||
search_url = f"{apk_mirror_base_url}/?s={package_name}"
|
||||
r = requests.get(search_url, headers=headers)
|
||||
soup = BeautifulSoup(r.text, bs4_parser)
|
||||
sub_url = soup.select_one("div.bubble-wrap > img")["src"]
|
||||
new_width = 500
|
||||
new_height = 500
|
||||
new_quality = 100
|
||||
return _extracted_from_apkmirror_scrapper(search_url)
|
||||
raise APKMirrorIconScrapFailure(url=search_url)
|
||||
|
||||
# regular expression pattern to match w=xx&h=xx&q=xx
|
||||
pattern = r"(w=\d+&h=\d+&q=\d+)"
|
||||
|
||||
return apk_mirror_base_url + re.sub(
|
||||
pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url
|
||||
)
|
||||
raise APKMirrorScrapperFailure()
|
||||
def _extracted_from_apkmirror_scrapper(search_url: str) -> str:
|
||||
r = requests.get(search_url, headers=headers, timeout=10)
|
||||
soup = BeautifulSoup(r.text, bs4_parser)
|
||||
sub_url = soup.select_one("div.bubble-wrap > img")["src"]
|
||||
new_width = 500
|
||||
new_height = 500
|
||||
new_quality = 100
|
||||
|
||||
# regular expression pattern to match w=xx&h=xx&q=xx
|
||||
pattern = r"(w=\d+&h=\d+&q=\d+)"
|
||||
|
||||
return apk_mirror_base_url + re.sub(
|
||||
pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url
|
||||
)
|
||||
|
||||
|
||||
def gplay_icon_scrapper(package_name: str) -> str:
|
||||
@@ -70,7 +76,7 @@ def gplay_icon_scrapper(package_name: str) -> str:
|
||||
except GooglePlayScraperException:
|
||||
try:
|
||||
return apkmirror_scrapper(package_name)
|
||||
except APKMirrorScrapperFailure:
|
||||
except APKMirrorIconScrapFailure:
|
||||
return apkcombo_scrapper(package_name)
|
||||
except Exception:
|
||||
return not_found_icon
|
||||
@@ -96,7 +102,7 @@ def generate_markdown_table(data: List[List[str]]) -> str:
|
||||
|
||||
def main() -> None:
|
||||
repo_url = "https://api.revanced.app/v2/patches/latest"
|
||||
response = requests.get(repo_url)
|
||||
response = requests.get(repo_url, timeout=10)
|
||||
handle_github_response(response)
|
||||
|
||||
parsed_data = response.json()
|
||||
|
||||
Reference in New Issue
Block a user