From f599c370c51e7e8fe835035c1a18e2a70dcd288f Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Thu, 10 Aug 2023 21:43:07 +0530 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=8E=A8=20Use=20join=20instead=20of=20?= =?UTF-8?q?+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/utils.py b/src/utils.py index d94c0cc3f8..d72b837052 100644 --- a/src/utils.py +++ b/src/utils.py @@ -27,13 +27,15 @@ def update_changelog(name: str, response: Dict[str, str]) -> None: publish_time = f"**Published at** -
{response['published_at']}" footer = f"
Change logs generated by [Docker Py Revanced]({parent_repo})\n" collapse_end = "" - 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) From c9ba3f5c1c6c4548e485c1f1b7d9fdfb726a1e23 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Thu, 10 Aug 2023 21:45:05 +0530 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=93=9D=20Added=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODOs.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/TODOs.md b/TODOs.md index 291b737167..3c98425331 100644 --- a/TODOs.md +++ b/TODOs.md @@ -1,7 +1,8 @@ ## Things to work on -| | | -|:--------------------------------------------|---------------:| -| Parallelize app object creation. |
  • [ ]
  • | -| Parallelize app patching. |
  • [ ]
  • | -| Ability to provide local patching resources |
  • [X]
  • | +| | | +|:------------------------------------------------------|---------------:| +| Parallelize app object creation. |
  • [ ]
  • | +| Parallelize app patching. |
  • [ ]
  • | +| Ability to provide local patching resources |
  • [X]
  • | +| Ability to provide changelog repo in update_changelog |
  • [ ]
  • | From 73ae6aa59d5d36492691d83237aeaf45828d5318 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Thu, 10 Aug 2023 21:47:53 +0530 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=8E=A8=20Updated=20function=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/status_check.py | 4 ++-- src/downloader/download.py | 4 ++-- src/downloader/github.py | 6 +++--- src/utils.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/status_check.py b/scripts/status_check.py index 253bb712e1..3eeeaba95a 100644 --- a/scripts/status_check.py +++ b/scripts/status_check.py @@ -10,7 +10,7 @@ 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"] diff --git a/src/downloader/download.py b/src/downloader/download.py index 4f40a7128a..c0e560bbe3 100644 --- a/src/downloader/download.py +++ b/src/downloader/download.py @@ -12,7 +12,7 @@ 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 @@ def _download(self, url: str, file_name: str) -> None: stream=True, headers=headers, ) - handle_response(response) + handle_github_response(response) total = int(response.headers.get("content-length", 0)) bar = tqdm( desc=file_name, diff --git a/src/downloader/github.py b/src/downloader/github.py index 30e494abb0..fb8a014ed3 100644 --- a/src/downloader/github.py +++ b/src/downloader/github.py @@ -8,7 +8,7 @@ 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 @@ def latest_version(self, app: str, **kwargs: Dict[str, str]) -> None: 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 @@ def _get_release_assets( 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) diff --git a/src/utils.py b/src/utils.py index d72b837052..46248c5846 100644 --- a/src/utils.py +++ b/src/utils.py @@ -40,7 +40,7 @@ def update_changelog(name: str, response: Dict[str, str]) -> None: 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: From e3a36f16f87428585329ec4d6cee681eb797a8c7 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Thu, 10 Aug 2023 21:51:18 +0530 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=8E=A8=20Updated=20variable=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils.py b/src/utils.py index 46248c5846..6ff8b15a84 100644 --- a/src/utils.py +++ b/src/utils.py @@ -52,21 +52,21 @@ def handle_github_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: From 21912d99fe8258f09f60374a64f4b04632a99856 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Thu, 10 Aug 2023 22:04:17 +0530 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=8E=A8=20Skip=20instead=20of=20raisin?= =?UTF-8?q?g=20exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils.py b/src/utils.py index 6ff8b15a84..ad3f723ec0 100644 --- a/src/utils.py +++ b/src/utils.py @@ -97,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( From a1b4563f415e1dabce9e7ee6c8b3ab6c640aee2f Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Thu, 10 Aug 2023 22:07:40 +0530 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=8E=A8=20Try=20to=20open=20file=20ins?= =?UTF-8?q?tead=20of=20checking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/patches.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/patches.py b/src/patches.py index 6161229523..e7a0cda855 100644 --- a/src/patches.py +++ b/src/patches.py @@ -1,6 +1,5 @@ """Revanced Patches.""" import json -import os from typing import Any, Dict, List, Tuple from loguru import logger @@ -66,11 +65,12 @@ def support_app() -> Dict[str, str]: def scrap_patches(self, file_name: str) -> Any: """Scrap Patches.""" - if os.path.exists(file_name): + try: with open(file_name) as f: patches = json.load(f) return patches - raise PatchesJsonFailed() + except FileNotFoundError: + raise PatchesJsonFailed() # noinspection DuplicatedCode def fetch_patches(self, config: RevancedConfig, app: APP) -> None: From b70d14cc24dc74d095a20fe078ad02477f57cce3 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Thu, 10 Aug 2023 22:12:22 +0530 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=8E=A8=20Custom=20class=20for=20loadi?= =?UTF-8?q?ng=20patches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/patches.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/patches.py b/src/patches.py index e7a0cda855..3d479d447b 100644 --- a/src/patches.py +++ b/src/patches.py @@ -63,19 +63,10 @@ def support_app() -> Dict[str, str]: """Return supported apps.""" return Patches._revanced_app_ids - def scrap_patches(self, file_name: str) -> Any: - """Scrap Patches.""" - try: - with open(file_name) as f: - patches = json.load(f) - return patches - except FileNotFoundError: - 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 @@ def get(self, app: str) -> Tuple[List[Dict[str, str]], str]: 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 @@ def get_app_configs(self, app: "APP") -> List[Dict[str, str]]: 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() From 677f3023bd5e15e161251059da6e6204f2d083da Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Thu, 10 Aug 2023 22:16:51 +0530 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=8E=A8=20Removed=20hardcode=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/parser.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/parser.py b/src/parser.py index 4db166cd7d..7532b5f562 100644 --- a/src/parser.py +++ b/src/parser.py @@ -15,6 +15,14 @@ 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 @@ def patch_app( :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: