mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
🎨 Chore (#289)
This commit is contained in:
@@ -14,4 +14,4 @@ jobs:
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: github_secrets
|
||||
path: .github_secrets
|
||||
path: .github_secrets
|
||||
|
||||
+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()
|
||||
|
||||
+3
-1
@@ -12,6 +12,8 @@ default_integrations = (
|
||||
"https://github.com/revanced/revanced-integrations/releases/latest"
|
||||
)
|
||||
|
||||
APK_MIRROR_BASE_URL = "https://www.apkmirror.com"
|
||||
|
||||
|
||||
class RevancedConfig(object):
|
||||
"""Revanced Configurations."""
|
||||
@@ -23,7 +25,7 @@ class RevancedConfig(object):
|
||||
self.temp_folder = Path("apks")
|
||||
self.session = Session()
|
||||
self.session.headers["User-Agent"] = "anything"
|
||||
self.apk_mirror = "https://www.apkmirror.com"
|
||||
self.apk_mirror = APK_MIRROR_BASE_URL
|
||||
self.upto_down = {
|
||||
"spotify": "spotify",
|
||||
"nyx-music-player": "nyx-music-player",
|
||||
|
||||
+15
-3
@@ -1,7 +1,19 @@
|
||||
class APKMirrorScrapperFailure(Exception):
|
||||
"""Failed to scrap icon from apkmirror."""
|
||||
from typing import Any
|
||||
|
||||
pass
|
||||
|
||||
class APKMirrorIconScrapFailure(Exception):
|
||||
"""Exception raised when the icon cannot be scraped from apkmirror."""
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""Initialize the APKMirrorIconScrapFailure exception.
|
||||
|
||||
Args:
|
||||
*args: Variable length argument list.
|
||||
**kwargs: Arbitrary keyword arguments.
|
||||
url (str, optional): The URL of the failed icon scraping. Defaults to None.
|
||||
"""
|
||||
super().__init__(*args)
|
||||
self.url = kwargs.get("url", None)
|
||||
|
||||
|
||||
class PatchingFailed(Exception):
|
||||
|
||||
+2
-1
@@ -113,7 +113,8 @@ class Patches(object):
|
||||
app_names = {value[0]: value[1] for value in self.revanced_app_ids.values()}
|
||||
|
||||
if not (app_name := app_names.get(app)):
|
||||
raise AppNotFound(app)
|
||||
raise AppNotFound(f"App '{app}' not found in the supported apps.")
|
||||
|
||||
patches = getattr(self, app_name)
|
||||
version = "latest"
|
||||
with contextlib.suppress(StopIteration):
|
||||
|
||||
+49
-27
@@ -1,5 +1,4 @@
|
||||
"""Utilities."""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
@@ -28,27 +27,46 @@ bs4_parser = "html.parser"
|
||||
|
||||
def update_changelog(name: str, response: Dict[str, str]) -> None:
|
||||
"""Updated Changelog."""
|
||||
parent_repo = "https://github.com/nikhilbadyal/docker-py-revanced"
|
||||
with open("changelog.md", "a", encoding="utf_8") as file1:
|
||||
collapse_start = f"\n<details> <summary>👀 {name} </summary>\n\n"
|
||||
release_version = f"**Release Version** - [{response['tag_name']}]({response['html_url']})<br>"
|
||||
change_log = f"**Changelog** -<br> {response['body']}"
|
||||
publish_time = f"**Published at** -<br> {response['published_at']}"
|
||||
footer = f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
|
||||
collapse_end = "</details>"
|
||||
change_log = "".join(
|
||||
[
|
||||
collapse_start,
|
||||
release_version,
|
||||
change_log,
|
||||
publish_time,
|
||||
footer,
|
||||
collapse_end,
|
||||
]
|
||||
)
|
||||
parent_repo = get_parent_repo()
|
||||
change_log = format_changelog(name, response, parent_repo)
|
||||
write_to_file(change_log)
|
||||
|
||||
|
||||
def format_changelog(name: str, response: Dict[str, str], parent_repo: str) -> str:
|
||||
"""Format changelog."""
|
||||
collapse_start = f"\n<details> <summary>👀 {name} </summary>\n\n"
|
||||
release_version = (
|
||||
f"**Release Version** - [{response['tag_name']}]({response['html_url']})<br>"
|
||||
)
|
||||
change_log = f"**Changelog** -<br> {response['body']}"
|
||||
publish_time = f"**Published at** -<br> {response['published_at']}"
|
||||
footer = (
|
||||
f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
|
||||
)
|
||||
collapse_end = "</details>"
|
||||
return "".join(
|
||||
[
|
||||
collapse_start,
|
||||
release_version,
|
||||
change_log,
|
||||
publish_time,
|
||||
footer,
|
||||
collapse_end,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def write_to_file(change_log: str) -> None:
|
||||
"""Write changelog to file."""
|
||||
with open("changelog.md", "w", encoding="utf_8") as file1:
|
||||
file1.write(change_log)
|
||||
|
||||
|
||||
def get_parent_repo() -> str:
|
||||
"""Get parent repository URL from configuration file."""
|
||||
return "https://github.com/nikhilbadyal/docker-py-revanced"
|
||||
|
||||
|
||||
def handle_github_response(response: Response) -> None:
|
||||
"""Handle Get Request Response."""
|
||||
response_code = response.status_code
|
||||
@@ -93,7 +111,7 @@ def check_java(dry_run: bool) -> None:
|
||||
raise subprocess.CalledProcessError(-1, "java -version")
|
||||
logger.debug("Cool!! Java is available")
|
||||
except subprocess.CalledProcessError:
|
||||
logger.error("Java>= 17 Must be installed")
|
||||
logger.error("Java>= 17 must be installed")
|
||||
exit(-1)
|
||||
|
||||
|
||||
@@ -119,11 +137,15 @@ def extra_downloads(config: RevancedConfig) -> None:
|
||||
|
||||
|
||||
def apkmirror_status_check(package_name: str) -> Any:
|
||||
"""Check if app exists on APKMirror."""
|
||||
check_if_exist = f"{apk_mirror_base_url}/wp-json/apkm/v1/app_exists/"
|
||||
"""Check if app exists on APKMirror.
|
||||
|
||||
Args:
|
||||
package_name (str): The name of the package to check.
|
||||
|
||||
Returns:
|
||||
dict: The response from APKMirror API as a JSON object.
|
||||
"""
|
||||
api_url = f"{apk_mirror_base_url}/wp-json/apkm/v1/app_exists/"
|
||||
body = {"pnames": [package_name]}
|
||||
return json.loads(
|
||||
requests.post(
|
||||
check_if_exist, data=json.dumps(body), headers=apk_mirror_header
|
||||
).content
|
||||
)
|
||||
response = requests.post(api_url, json=body, headers=apk_mirror_header)
|
||||
return response.json()
|
||||
|
||||
Reference in New Issue
Block a user