diff --git a/src/config.py b/src/config.py index b581b65..3788aaa 100644 --- a/src/config.py +++ b/src/config.py @@ -89,3 +89,4 @@ class RevancedConfig(object): ) self.existing_downloaded_apks = env.list("EXISTING_DOWNLOADED_APKS", []) self.personal_access_token = env.str("PERSONAL_ACCESS_TOKEN", None) + self.dry_run = env.bool("DRY_RUN", False) diff --git a/src/downloader/download.py b/src/downloader/download.py index aa4dfcc..9c2ed80 100644 --- a/src/downloader/download.py +++ b/src/downloader/download.py @@ -25,8 +25,13 @@ class Downloader(object): self.patcher = patcher def _download(self, url: str, file_name: str) -> None: - if os.path.exists(self.config.temp_folder.joinpath(file_name)): - logger.debug(f"Skipping download of {file_name}. File already exists.") + if ( + os.path.exists(self.config.temp_folder.joinpath(file_name)) + or self.config.dry_run + ): + logger.debug( + f"Skipping download of {file_name}. File already exists or dry running." + ) return logger.info(f"Trying to download {file_name} from {url}") self._QUEUE_LENGTH += 1 @@ -86,6 +91,8 @@ class Downloader(object): :param version: version to download :param app: App to download """ + if self.config.dry_run: + return if app in self.config.existing_downloaded_apks: logger.debug(f"Will not download {app} -v{version} from the internet.") return diff --git a/src/patches.py b/src/patches.py index 4827a29..fe3b4e4 100644 --- a/src/patches.py +++ b/src/patches.py @@ -1,4 +1,5 @@ """Revanced Patches.""" +import json import subprocess from typing import Any, Dict, List, Tuple @@ -79,13 +80,17 @@ class Patches(object): def fetch_patches(self) -> None: """Function to fetch all patches.""" session = Session() - - logger.debug("fetching all patches") - response = session.get( - "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json" - ) - handle_response(response) - patches = response.json() + if self.config.dry_run: + logger.debug("fetching all patches from local file") + with open("patches.json") as f: + patches = json.load(f) + else: + logger.debug("fetching all patches") + response = session.get( + "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json" + ) + handle_response(response) + patches = response.json() for app_name in (self.revanced_app_ids[x][1] for x in self.revanced_app_ids): setattr(self, app_name, []) @@ -100,14 +105,16 @@ class Patches(object): p["app"] = compatible_package p["version"] = version[-1] if version else "all" getattr(self, app_name).append(p) - if self.config.build_extended: - url = "https://raw.githubusercontent.com/inotia00/revanced-patches/revanced-extended/patches.json" + if self.config.dry_run: + extended_patches = patches else: - url = "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json" - - response = session.get(url) - handle_response(response) - extended_patches = response.json() + if self.config.build_extended: + url = "https://raw.githubusercontent.com/inotia00/revanced-patches/revanced-extended/patches.json" + else: + url = "https://raw.githubusercontent.com/revanced/revanced-patches/main/patches.json" + response = session.get(url) + handle_response(response) + extended_patches = response.json() for app_name in ( self.revanced_extended_app_ids[x][1] for x in self.revanced_extended_app_ids ):