From 5931265a5cb2c0a0349b49c2a1c685b47a318d38 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Mon, 22 Aug 2022 19:47:59 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20ability=20to=20dynamically?= =?UTF-8?q?=20exclude=20patches.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 +++++++++++------ main.py | 36 ++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 265a6ca..6ee2b22 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,10 @@ You can use any of the following methods to build ```python python main.py ``` -- In GitHub +- In GitHub 1. Fork the project. Add following secrets to the repo 1. _GH_TOKEN_ (**required**) - Github token so that it can upload to github after building. - 2. _VT_API_KEY_ (required , only if you want Virus total scan) - So that it can send + 2. _VT_API_KEY_ (required , only if you want Virus total scan) - So that it can send apks for VirusTotal Scan. 3. _ENVS_ (optional) - If you want cook specific apps/versions ```dotenv @@ -67,16 +67,21 @@ By default script build the version as recommended by revanced team. TIKTOK_VERSION=latest WARNWETTER_VERSION=latest ``` -3. By default it will build all build app supported by revanced team. If you don't - want to waste time and build only few apps. Add following(the apps you want to +3. By default, it will build all build app supported by revanced team. If you don't + want to waste time and build only few apps. Add following(the apps you want to build) `environment`. ```dotenv PATCH_APPS=youtube,twitter,reddit ``` -4. If you don't want to use default keystore. You can provide your own by placing it +4. If you don't want to use default keystore. You can provide your own by placing it inside `apks` folder. And adding the name of file in `environment` ```dotenv KEYSTORE_FILE_NAME=revanced.keystore ``` - +5. If you want to exclude any patch. Set comma seperated environment variable like + ```dotenv + EXCLUDE_PATCH_YOUTUBE=custom-branding,hide-get-premium + EXCLUDE_PATCH_YOUTUBE_MUSIC=yt-music-is-shit + ``` + Thanks to [@aliharslan0](https://github.com/aliharslan0/pyrevanced) for his work. diff --git a/main.py b/main.py index 8b9fff4..7c0f6e3 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ from queue import PriorityQueue from shutil import rmtree from subprocess import PIPE, Popen from time import perf_counter -from typing import Any, Dict, List, Tuple +from typing import Any, Dict, List, Tuple, Type from environs import Env from loguru import logger @@ -247,6 +247,7 @@ class Patches: class ArgParser: _PATCHES = [] + _EXCLUDED = [] @classmethod def include(cls, name: str) -> None: @@ -255,6 +256,11 @@ class ArgParser: @classmethod def exclude(cls, name: str) -> None: cls._PATCHES.extend(["-e", name]) + cls._EXCLUDED.append(name) + + @classmethod + def get_excluded_patches(cls) -> List[Any]: + return cls._EXCLUDED @classmethod def run(cls, app: str, version: str, is_experimental: bool = False) -> None: @@ -324,24 +330,30 @@ def pre_requisite(): return patches -def main() -> None: - patches = pre_requisite() - downloader = Downloader +def download_revanced(downloader: Type[Downloader]) -> None: downloader.repository("revanced-cli") downloader.repository("revanced-integrations") downloader.repository("revanced-patches") downloader.repository("VancedMicroG", "TeamVanced") + +def main() -> None: + patches = pre_requisite() + downloader = Downloader + download_revanced(downloader) + def get_patches() -> None: logger.debug(f"Excluding patches for app {app}") - selected_patches = list(range(0, len(app_patches))) - if app == "youtube": - selected_patches.remove(9) - for i, v in enumerate(app_patches): - arg_parser.include( - v["name"] - ) if i in selected_patches else arg_parser.exclude(v["name"]) - logger.debug(f"Excluded patches for app {app}") + excluded_patches = env.list(f"EXCLUDE_PATCH_{app}".upper(), []) + for patch in app_patches: + arg_parser.include(patch["name"]) if patch[ + "name" + ] not in excluded_patches else arg_parser.exclude(patch["name"]) + excluded = arg_parser.get_excluded_patches() + if excluded: + logger.debug(f"Excluded patches {excluded} for {app}") + else: + logger.debug(f"No excluded patches for {app}") def get_patches_version() -> Any: experiment = False