1
1
"""Revanced Parser."""
2
+ from pathlib import Path
2
3
from subprocess import PIPE , Popen
3
4
from time import perf_counter
4
5
from typing import List , Self
@@ -17,6 +18,7 @@ class Parser(object):
17
18
18
19
CLI_JAR = "-jar"
19
20
APK_ARG = "-a"
21
+ NEW_APK_ARG = "patch"
20
22
PATCHES_ARG = "-b"
21
23
INTEGRATIONS_ARG = "-m"
22
24
OUTPUT_ARG = "-o"
@@ -101,6 +103,21 @@ def exclude_all_patches(self: Self) -> None:
101
103
if item == "-i" :
102
104
self ._PATCHES [idx ] = "-e"
103
105
106
+ @staticmethod
107
+ def is_new_cli (cli_path : Path ) -> bool :
108
+ """Check if new cli is being used."""
109
+ process = Popen (["java" , "-jar" , cli_path , "-V" ], stdout = PIPE )
110
+ output = process .stdout
111
+ if not output :
112
+ msg = "Failed to send request for patching."
113
+ raise PatchingFailedError (msg )
114
+ combined_result = "" .join (line .decode () for line in output )
115
+ if "v3" in combined_result :
116
+ logger .debug ("New cli" )
117
+ return True
118
+ logger .debug ("Old cli" )
119
+ return False
120
+
104
121
# noinspection IncorrectFormatting
105
122
def patch_app (
106
123
self : Self ,
@@ -114,10 +131,16 @@ def patch_app(
114
131
The `app` parameter is an instance of the `APP` class. It represents an application that needs
115
132
to be patched.
116
133
"""
134
+ if self .is_new_cli (self .config .temp_folder .joinpath (app .resource ["cli" ])):
135
+ apk_arg = self .NEW_APK_ARG
136
+ exp = "--force"
137
+ else :
138
+ apk_arg = self .APK_ARG
139
+ exp = "--experimental"
117
140
args = [
118
141
self .CLI_JAR ,
119
142
app .resource ["cli" ],
120
- self . APK_ARG ,
143
+ apk_arg ,
121
144
app .download_file_name ,
122
145
self .PATCHES_ARG ,
123
146
app .resource ["patches" ],
@@ -132,7 +155,7 @@ def patch_app(
132
155
]
133
156
if app .experiment :
134
157
logger .debug ("Using experimental features" )
135
- args .append ("--experimental" )
158
+ args .append (exp )
136
159
args [1 ::2 ] = map (self .config .temp_folder .joinpath , args [1 ::2 ])
137
160
if self .config .ci_test :
138
161
self .exclude_all_patches ()
0 commit comments