mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
@@ -1,7 +1,8 @@
|
||||
## Things to work on
|
||||
|
||||
| | |
|
||||
|:--------------------------------------------|---------------:|
|
||||
| Parallelize app object creation. | <li> [ ] </li> |
|
||||
| Parallelize app patching. | <li> [ ] </li> |
|
||||
| Ability to provide local patching resources | <li> [X] </li> |
|
||||
| | |
|
||||
|:------------------------------------------------------|---------------:|
|
||||
| Parallelize app object creation. | <li> [ ] </li> |
|
||||
| Parallelize app patching. | <li> [ ] </li> |
|
||||
| Ability to provide local patching resources | <li> [X] </li> |
|
||||
| Ability to provide changelog repo in update_changelog | <li> [ ] </li> |
|
||||
|
||||
@@ -10,7 +10,7 @@ from google_play_scraper.exceptions import GooglePlayScraperException
|
||||
|
||||
from src.exceptions import APKMirrorScrapperFailure
|
||||
from src.patches import Patches
|
||||
from src.utils import handle_response
|
||||
from src.utils import handle_github_response
|
||||
|
||||
not_found_icon = "https://img.icons8.com/bubbles/500/android-os.png"
|
||||
headers = {
|
||||
@@ -105,7 +105,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)
|
||||
handle_response(response)
|
||||
handle_github_response(response)
|
||||
|
||||
parsed_data = response.json()
|
||||
compatible_packages = parsed_data["patches"]
|
||||
|
||||
@@ -12,7 +12,7 @@ from src.config import RevancedConfig
|
||||
from src.downloader.utils import implement_method
|
||||
from src.exceptions import PatchingFailed
|
||||
from src.patches import Patches
|
||||
from src.utils import handle_response
|
||||
from src.utils import handle_github_response
|
||||
|
||||
|
||||
class Downloader(object):
|
||||
@@ -54,7 +54,7 @@ class Downloader(object):
|
||||
stream=True,
|
||||
headers=headers,
|
||||
)
|
||||
handle_response(response)
|
||||
handle_github_response(response)
|
||||
total = int(response.headers.get("content-length", 0))
|
||||
bar = tqdm(
|
||||
desc=file_name,
|
||||
|
||||
@@ -8,7 +8,7 @@ from loguru import logger
|
||||
|
||||
from src.config import RevancedConfig
|
||||
from src.downloader.download import Downloader
|
||||
from src.utils import handle_response, update_changelog
|
||||
from src.utils import handle_github_response, update_changelog
|
||||
|
||||
|
||||
class Github(Downloader):
|
||||
@@ -35,7 +35,7 @@ class Github(Downloader):
|
||||
logger.debug("Using personal access token")
|
||||
headers["Authorization"] = f"token {self.config.personal_access_token}"
|
||||
response = requests.get(repo_url, headers=headers)
|
||||
handle_response(response)
|
||||
handle_github_response(response)
|
||||
if repo_name == "revanced-patches":
|
||||
download_url = response.json()["assets"][1]["browser_download_url"]
|
||||
else:
|
||||
@@ -78,7 +78,7 @@ class Github(Downloader):
|
||||
if config.personal_access_token:
|
||||
headers["Authorization"] = f"token {config.personal_access_token}"
|
||||
response = requests.get(api_url, headers=headers)
|
||||
handle_response(response)
|
||||
handle_github_response(response)
|
||||
assets = response.json()["assets"]
|
||||
try:
|
||||
filter_pattern = re.compile(asset_filter)
|
||||
|
||||
+15
-7
@@ -15,6 +15,14 @@ from src.utils import possible_archs
|
||||
class Parser(object):
|
||||
"""Revanced Parser."""
|
||||
|
||||
CLI_JAR = "-jar"
|
||||
APK_ARG = "-a"
|
||||
PATCHES_ARG = "-b"
|
||||
INTEGRATIONS_ARG = "-m"
|
||||
OUTPUT_ARG = "-o"
|
||||
KEYSTORE_ARG = "--keystore"
|
||||
OPTIONS_ARG = "--options"
|
||||
|
||||
def __init__(self, patcher: Patches, config: RevancedConfig) -> None:
|
||||
self._PATCHES: List[str] = []
|
||||
self._EXCLUDED: List[str] = []
|
||||
@@ -78,19 +86,19 @@ class Parser(object):
|
||||
:param app: Name of the app
|
||||
"""
|
||||
args = [
|
||||
"-jar",
|
||||
self.CLI_JAR,
|
||||
app.resource["cli"],
|
||||
"-a",
|
||||
self.APK_ARG,
|
||||
f"{app.app_name}.apk",
|
||||
"-b",
|
||||
self.PATCHES_ARG,
|
||||
app.resource["patches"],
|
||||
"-m",
|
||||
self.INTEGRATIONS_ARG,
|
||||
app.resource["integrations"],
|
||||
"-o",
|
||||
self.OUTPUT_ARG,
|
||||
app.get_output_file_name(),
|
||||
"--keystore",
|
||||
self.KEYSTORE_ARG,
|
||||
app.keystore_name,
|
||||
"--options",
|
||||
self.OPTIONS_ARG,
|
||||
"options.json",
|
||||
]
|
||||
if app.experiment:
|
||||
|
||||
+16
-12
@@ -1,6 +1,5 @@
|
||||
"""Revanced Patches."""
|
||||
import json
|
||||
import os
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
from loguru import logger
|
||||
@@ -64,18 +63,10 @@ class Patches(object):
|
||||
"""Return supported apps."""
|
||||
return Patches._revanced_app_ids
|
||||
|
||||
def scrap_patches(self, file_name: str) -> Any:
|
||||
"""Scrap Patches."""
|
||||
if os.path.exists(file_name):
|
||||
with open(file_name) as f:
|
||||
patches = json.load(f)
|
||||
return patches
|
||||
raise PatchesJsonFailed()
|
||||
|
||||
# noinspection DuplicatedCode
|
||||
def fetch_patches(self, config: RevancedConfig, app: APP) -> None:
|
||||
"""Function to fetch all patches."""
|
||||
patches = self.scrap_patches(
|
||||
patch_loader = PatchLoader()
|
||||
patches = patch_loader.load_patches(
|
||||
f'{config.temp_folder}/{app.resource["patches_json"]}'
|
||||
)
|
||||
for app_name in (self.revanced_app_ids[x][1] for x in self.revanced_app_ids):
|
||||
@@ -121,7 +112,6 @@ class Patches(object):
|
||||
pass
|
||||
return patches, version
|
||||
|
||||
# noinspection IncorrectFormatting
|
||||
def include_exclude_patch(
|
||||
self, app: APP, parser: Any, patches: List[Dict[str, str]]
|
||||
) -> None:
|
||||
@@ -164,3 +154,17 @@ class Patches(object):
|
||||
recommended_version = app.app_version
|
||||
app.set_recommended_version(recommended_version, experiment)
|
||||
return total_patches
|
||||
|
||||
|
||||
class PatchLoader:
|
||||
"""Patch Loader."""
|
||||
|
||||
@staticmethod
|
||||
def load_patches(file_name: str) -> Any:
|
||||
"""Load patches from a file."""
|
||||
try:
|
||||
with open(file_name) as f:
|
||||
patches = json.load(f)
|
||||
return patches
|
||||
except FileNotFoundError:
|
||||
raise PatchesJsonFailed()
|
||||
|
||||
+21
-18
@@ -27,18 +27,20 @@ def update_changelog(name: str, response: Dict[str, str]) -> None:
|
||||
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 = (
|
||||
collapse_start
|
||||
+ release_version
|
||||
+ change_log
|
||||
+ publish_time
|
||||
+ footer
|
||||
+ collapse_end
|
||||
change_log = "".join(
|
||||
[
|
||||
collapse_start,
|
||||
release_version,
|
||||
change_log,
|
||||
publish_time,
|
||||
footer,
|
||||
collapse_end,
|
||||
]
|
||||
)
|
||||
file1.write(change_log)
|
||||
|
||||
|
||||
def handle_response(response: Response) -> None:
|
||||
def handle_github_response(response: Response) -> None:
|
||||
"""Handle Get Request Response."""
|
||||
response_code = response.status_code
|
||||
if response_code != 200:
|
||||
@@ -50,21 +52,21 @@ def handle_response(response: Response) -> None:
|
||||
def slugify(string: str) -> str:
|
||||
"""Converts a string to a slug format."""
|
||||
# Convert to lowercase
|
||||
string = string.lower()
|
||||
modified_string = string.lower()
|
||||
|
||||
# Remove special characters
|
||||
string = re.sub(r"[^\w\s-]", "", string)
|
||||
modified_string = re.sub(r"[^\w\s-]", "", modified_string)
|
||||
|
||||
# Replace spaces with dashes
|
||||
string = re.sub(r"\s+", "-", string)
|
||||
modified_string = re.sub(r"\s+", "-", modified_string)
|
||||
|
||||
# Remove consecutive dashes
|
||||
string = re.sub(r"-+", "-", string)
|
||||
modified_string = re.sub(r"-+", "-", modified_string)
|
||||
|
||||
# Remove leading and trailing dashes
|
||||
string = string.strip("-")
|
||||
modified_string = modified_string.strip("-")
|
||||
|
||||
return string
|
||||
return modified_string
|
||||
|
||||
|
||||
def check_java(dry_run: bool) -> None:
|
||||
@@ -95,10 +97,11 @@ def extra_downloads(config: RevancedConfig) -> None:
|
||||
url, file_name = extra.split("@")
|
||||
file_name_without_extension, file_extension = os.path.splitext(file_name)
|
||||
|
||||
if file_extension.lower() == ".apk":
|
||||
new_file_name = f"{file_name_without_extension}-output{file_extension}"
|
||||
else:
|
||||
raise ValueError("Only .apk extensions are allowed.")
|
||||
if file_extension.lower() != ".apk":
|
||||
logger.info(f"Only .apk extensions are allowed {file_name}.")
|
||||
continue
|
||||
|
||||
new_file_name = f"{file_name_without_extension}-output{file_extension}"
|
||||
APP.download(url, config, assets_filter=".*apk", file_name=new_file_name)
|
||||
except (ValueError, IndexError):
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user