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:
+23
-17
@@ -7,7 +7,7 @@ from bs4 import BeautifulSoup
|
|||||||
from google_play_scraper import app as gplay_app
|
from google_play_scraper import app as gplay_app
|
||||||
from google_play_scraper.exceptions import GooglePlayScraperException
|
from google_play_scraper.exceptions import GooglePlayScraperException
|
||||||
|
|
||||||
from src.exceptions import APKMirrorScrapperFailure
|
from src.exceptions import APKMirrorIconScrapFailure
|
||||||
from src.patches import Patches
|
from src.patches import Patches
|
||||||
from src.utils import (
|
from src.utils import (
|
||||||
apk_mirror_base_url,
|
apk_mirror_base_url,
|
||||||
@@ -28,7 +28,9 @@ def apkcombo_scrapper(package_name: str) -> str:
|
|||||||
"""Apkcombo scrapper."""
|
"""Apkcombo scrapper."""
|
||||||
try:
|
try:
|
||||||
apkcombo_url = f"https://apkcombo.com/genericApp/{package_name}"
|
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)
|
soup = BeautifulSoup(r.text, bs4_parser)
|
||||||
url = soup.select_one("div.avatar > img")["data-src"]
|
url = soup.select_one("div.avatar > img")["data-src"]
|
||||||
return re.sub(r"=.*$", "", url)
|
return re.sub(r"=.*$", "", url)
|
||||||
@@ -39,22 +41,26 @@ def apkcombo_scrapper(package_name: str) -> str:
|
|||||||
def apkmirror_scrapper(package_name: str) -> str:
|
def apkmirror_scrapper(package_name: str) -> str:
|
||||||
"""Apkmirror URL."""
|
"""Apkmirror URL."""
|
||||||
response = apkmirror_status_check(package_name)
|
response = apkmirror_status_check(package_name)
|
||||||
|
search_url = f"{apk_mirror_base_url}/?s={package_name}"
|
||||||
if response["data"][0]["exists"]:
|
if response["data"][0]["exists"]:
|
||||||
search_url = f"{apk_mirror_base_url}/?s={package_name}"
|
return _extracted_from_apkmirror_scrapper(search_url)
|
||||||
r = requests.get(search_url, headers=headers)
|
raise APKMirrorIconScrapFailure(url=search_url)
|
||||||
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(
|
def _extracted_from_apkmirror_scrapper(search_url: str) -> str:
|
||||||
pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url
|
r = requests.get(search_url, headers=headers, timeout=10)
|
||||||
)
|
soup = BeautifulSoup(r.text, bs4_parser)
|
||||||
raise APKMirrorScrapperFailure()
|
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:
|
def gplay_icon_scrapper(package_name: str) -> str:
|
||||||
@@ -70,7 +76,7 @@ def gplay_icon_scrapper(package_name: str) -> str:
|
|||||||
except GooglePlayScraperException:
|
except GooglePlayScraperException:
|
||||||
try:
|
try:
|
||||||
return apkmirror_scrapper(package_name)
|
return apkmirror_scrapper(package_name)
|
||||||
except APKMirrorScrapperFailure:
|
except APKMirrorIconScrapFailure:
|
||||||
return apkcombo_scrapper(package_name)
|
return apkcombo_scrapper(package_name)
|
||||||
except Exception:
|
except Exception:
|
||||||
return not_found_icon
|
return not_found_icon
|
||||||
@@ -96,7 +102,7 @@ def generate_markdown_table(data: List[List[str]]) -> str:
|
|||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
repo_url = "https://api.revanced.app/v2/patches/latest"
|
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)
|
handle_github_response(response)
|
||||||
|
|
||||||
parsed_data = response.json()
|
parsed_data = response.json()
|
||||||
|
|||||||
+3
-1
@@ -12,6 +12,8 @@ default_integrations = (
|
|||||||
"https://github.com/revanced/revanced-integrations/releases/latest"
|
"https://github.com/revanced/revanced-integrations/releases/latest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
APK_MIRROR_BASE_URL = "https://www.apkmirror.com"
|
||||||
|
|
||||||
|
|
||||||
class RevancedConfig(object):
|
class RevancedConfig(object):
|
||||||
"""Revanced Configurations."""
|
"""Revanced Configurations."""
|
||||||
@@ -23,7 +25,7 @@ class RevancedConfig(object):
|
|||||||
self.temp_folder = Path("apks")
|
self.temp_folder = Path("apks")
|
||||||
self.session = Session()
|
self.session = Session()
|
||||||
self.session.headers["User-Agent"] = "anything"
|
self.session.headers["User-Agent"] = "anything"
|
||||||
self.apk_mirror = "https://www.apkmirror.com"
|
self.apk_mirror = APK_MIRROR_BASE_URL
|
||||||
self.upto_down = {
|
self.upto_down = {
|
||||||
"spotify": "spotify",
|
"spotify": "spotify",
|
||||||
"nyx-music-player": "nyx-music-player",
|
"nyx-music-player": "nyx-music-player",
|
||||||
|
|||||||
+15
-3
@@ -1,7 +1,19 @@
|
|||||||
class APKMirrorScrapperFailure(Exception):
|
from typing import Any
|
||||||
"""Failed to scrap icon from apkmirror."""
|
|
||||||
|
|
||||||
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):
|
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()}
|
app_names = {value[0]: value[1] for value in self.revanced_app_ids.values()}
|
||||||
|
|
||||||
if not (app_name := app_names.get(app)):
|
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)
|
patches = getattr(self, app_name)
|
||||||
version = "latest"
|
version = "latest"
|
||||||
with contextlib.suppress(StopIteration):
|
with contextlib.suppress(StopIteration):
|
||||||
|
|||||||
+49
-27
@@ -1,5 +1,4 @@
|
|||||||
"""Utilities."""
|
"""Utilities."""
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -28,27 +27,46 @@ bs4_parser = "html.parser"
|
|||||||
|
|
||||||
def update_changelog(name: str, response: Dict[str, str]) -> None:
|
def update_changelog(name: str, response: Dict[str, str]) -> None:
|
||||||
"""Updated Changelog."""
|
"""Updated Changelog."""
|
||||||
parent_repo = "https://github.com/nikhilbadyal/docker-py-revanced"
|
parent_repo = get_parent_repo()
|
||||||
with open("changelog.md", "a", encoding="utf_8") as file1:
|
change_log = format_changelog(name, response, parent_repo)
|
||||||
collapse_start = f"\n<details> <summary>👀 {name} </summary>\n\n"
|
write_to_file(change_log)
|
||||||
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']}"
|
def format_changelog(name: str, response: Dict[str, str], parent_repo: str) -> str:
|
||||||
footer = f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
|
"""Format changelog."""
|
||||||
collapse_end = "</details>"
|
collapse_start = f"\n<details> <summary>👀 {name} </summary>\n\n"
|
||||||
change_log = "".join(
|
release_version = (
|
||||||
[
|
f"**Release Version** - [{response['tag_name']}]({response['html_url']})<br>"
|
||||||
collapse_start,
|
)
|
||||||
release_version,
|
change_log = f"**Changelog** -<br> {response['body']}"
|
||||||
change_log,
|
publish_time = f"**Published at** -<br> {response['published_at']}"
|
||||||
publish_time,
|
footer = (
|
||||||
footer,
|
f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
|
||||||
collapse_end,
|
)
|
||||||
]
|
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)
|
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:
|
def handle_github_response(response: Response) -> None:
|
||||||
"""Handle Get Request Response."""
|
"""Handle Get Request Response."""
|
||||||
response_code = response.status_code
|
response_code = response.status_code
|
||||||
@@ -93,7 +111,7 @@ def check_java(dry_run: bool) -> None:
|
|||||||
raise subprocess.CalledProcessError(-1, "java -version")
|
raise subprocess.CalledProcessError(-1, "java -version")
|
||||||
logger.debug("Cool!! Java is available")
|
logger.debug("Cool!! Java is available")
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
logger.error("Java>= 17 Must be installed")
|
logger.error("Java>= 17 must be installed")
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
@@ -119,11 +137,15 @@ def extra_downloads(config: RevancedConfig) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def apkmirror_status_check(package_name: str) -> Any:
|
def apkmirror_status_check(package_name: str) -> Any:
|
||||||
"""Check if app exists on APKMirror."""
|
"""Check if app exists on APKMirror.
|
||||||
check_if_exist = f"{apk_mirror_base_url}/wp-json/apkm/v1/app_exists/"
|
|
||||||
|
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]}
|
body = {"pnames": [package_name]}
|
||||||
return json.loads(
|
response = requests.post(api_url, json=body, headers=apk_mirror_header)
|
||||||
requests.post(
|
return response.json()
|
||||||
check_if_exist, data=json.dumps(body), headers=apk_mirror_header
|
|
||||||
).content
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user