🐛 Handle new v3 cli args (#339)

This commit is contained in:
Nikhil Badyal
2023-08-28 10:40:51 +05:30
committed by GitHub
parent f7bc2831e4
commit 10d91cc0f2
2 changed files with 26 additions and 2 deletions
+1
View File
@@ -5,6 +5,7 @@ venv
*/__pycache__*
*.pyc
/revanced-cache/
/revanced-resource-cache/
changelog.md
.idea
*.json
+25 -2
View File
@@ -1,4 +1,5 @@
"""Revanced Parser."""
from pathlib import Path
from subprocess import PIPE, Popen
from time import perf_counter
from typing import List, Self
@@ -17,6 +18,7 @@ class Parser(object):
CLI_JAR = "-jar"
APK_ARG = "-a"
NEW_APK_ARG = "patch"
PATCHES_ARG = "-b"
INTEGRATIONS_ARG = "-m"
OUTPUT_ARG = "-o"
@@ -101,6 +103,21 @@ class Parser(object):
if item == "-i":
self._PATCHES[idx] = "-e"
@staticmethod
def is_new_cli(cli_path: Path) -> bool:
"""Check if new cli is being used."""
process = Popen(["java", "-jar", cli_path, "-V"], stdout=PIPE)
output = process.stdout
if not output:
msg = "Failed to send request for patching."
raise PatchingFailedError(msg)
combined_result = "".join(line.decode() for line in output)
if "v3" in combined_result:
logger.debug("New cli")
return True
logger.debug("Old cli")
return False
# noinspection IncorrectFormatting
def patch_app(
self: Self,
@@ -114,10 +131,16 @@ class Parser(object):
The `app` parameter is an instance of the `APP` class. It represents an application that needs
to be patched.
"""
if self.is_new_cli(self.config.temp_folder.joinpath(app.resource["cli"])):
apk_arg = self.NEW_APK_ARG
exp = "--force"
else:
apk_arg = self.APK_ARG
exp = "--experimental"
args = [
self.CLI_JAR,
app.resource["cli"],
self.APK_ARG,
apk_arg,
app.download_file_name,
self.PATCHES_ARG,
app.resource["patches"],
@@ -132,7 +155,7 @@ class Parser(object):
]
if app.experiment:
logger.debug("Using experimental features")
args.append("--experimental")
args.append(exp)
args[1::2] = map(self.config.temp_folder.joinpath, args[1::2])
if self.config.ci_test:
self.exclude_all_patches()