mirror of
https://github.com/SinTan1729/ReVancedBuilder.git
synced 2025-02-05 22:22:35 -06:00
new: Build works (mostly)
This commit is contained in:
parent
7bf4eccc6a
commit
4c29f61e39
3 changed files with 118 additions and 27 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
from packaging.version import Version
|
from packaging.version import Version
|
||||||
|
@ -5,27 +6,32 @@ import requests as req
|
||||||
from bs4 import BeautifulSoup as bs
|
from bs4 import BeautifulSoup as bs
|
||||||
|
|
||||||
# Determine the best version available to download
|
# Determine the best version available to download
|
||||||
def apkpure_best_match(apk, appname, version, session):
|
def apkpure_best_match(version, soup):
|
||||||
res = session.get(f"https://apkpure.com/{appname}/{apk}/versions")
|
|
||||||
res.raise_for_status()
|
|
||||||
data = bs(res.text, 'html.parser')
|
|
||||||
try:
|
try:
|
||||||
vers_list = [Version(x['data-dt-version']) for x in data.css.select(f"a[data-dt-apkid^=\"b/APK/\"]")]
|
vers_list = [Version(x['data-dt-version']) for x in soup.css.select(f"a[data-dt-apkid^=\"b/APK/\"]")]
|
||||||
except:
|
except:
|
||||||
sys.exit(f" There was some error getting list of versions of {apk}...")
|
sys.exit(f" There was some error getting list of versions of {apk}...")
|
||||||
|
|
||||||
if version != '0':
|
if version != '0':
|
||||||
vers_list = filter(lambda x: x <= Version(version), vers_list)
|
vers_list = filter(lambda x: x <= Version(version), vers_list)
|
||||||
|
|
||||||
return max(vers_list)
|
return str(max(vers_list))
|
||||||
|
|
||||||
# Download an apk from APKPure.com
|
# Download an apk from APKPure.com
|
||||||
def apkpure_dl(apk, appname, version, hard_version, session, present_vers):
|
def apkpure_dl(apk, appname, version, hard_version, session, present_vers, flag):
|
||||||
|
res = session.get(f"https://apkpure.com/{appname}/{apk}/versions")
|
||||||
|
res.raise_for_status()
|
||||||
|
soup = bs(res.text, 'html.parser')
|
||||||
|
|
||||||
if not hard_version:
|
if not hard_version:
|
||||||
version = apkpure_best_match(apk, appname, version, session)
|
version = apkpure_best_match(version, soup)
|
||||||
|
|
||||||
|
if flag == 'checkonly' and present_vers[apk] != version:
|
||||||
|
print(f"{apk} has an update ({present_vers[apk]} -> {version})")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if present_vers[apk] == version:
|
if present_vers[apk] == version and flag != 'force' and os.path.isfile(apk):
|
||||||
print(f"Recommended version {version} of {apk} is already present.")
|
print(f"Recommended version {version} of {apk} is already present.")
|
||||||
return
|
return
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -33,17 +39,14 @@ def apkpure_dl(apk, appname, version, hard_version, session, present_vers):
|
||||||
print(f" Downloading {apk} version {version}...")
|
print(f" Downloading {apk} version {version}...")
|
||||||
|
|
||||||
# Get the version code
|
# Get the version code
|
||||||
res = session.get(f"https://apkpure.com/{appname}/{apk}/versions")
|
|
||||||
res.raise_for_status()
|
|
||||||
data = bs(res.text, 'html.parser')
|
|
||||||
try:
|
try:
|
||||||
ver_code = data.css.select(f"a[data-dt-version=\"{version}\"][data-dt-apkid^=\"b/APK/\"]")[0]['data-dt-versioncode']
|
ver_code = soup.css.select(f"a[data-dt-version=\"{version}\"][data-dt-apkid^=\"b/APK/\"]")[0]['data-dt-versioncode']
|
||||||
except:
|
except:
|
||||||
sys.exit(f" There was some error while downloading {apk}...")
|
sys.exit(f" There was some error while downloading {apk}...")
|
||||||
|
|
||||||
res = session.get(f"https://d.apkpure.com/b/APK/{apk}?versionCode={ver_code}", stream=True)
|
res = session.get(f"https://d.apkpure.com/b/APK/{apk}?versionCode={ver_code}", stream=True)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
with open(apk, 'wb') as f:
|
with open(apk+'.apk', 'wb') as f:
|
||||||
for chunk in res.iter_content(chunk_size=8192):
|
for chunk in res.iter_content(chunk_size=8192):
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
print(" Done!")
|
print(" Done!")
|
||||||
|
@ -51,7 +54,7 @@ def apkpure_dl(apk, appname, version, hard_version, session, present_vers):
|
||||||
|
|
||||||
|
|
||||||
# Download apk files, if needed
|
# Download apk files, if needed
|
||||||
def get_apks(present_vers, build_config):
|
def get_apks(present_vers, build_config, flag):
|
||||||
print('Downloading required apk files from APKPure...')
|
print('Downloading required apk files from APKPure...')
|
||||||
|
|
||||||
# Get latest patches using the ReVanced API
|
# Get latest patches using the ReVanced API
|
||||||
|
@ -67,14 +70,15 @@ def get_apks(present_vers, build_config):
|
||||||
# Check if we need to build an app
|
# Check if we need to build an app
|
||||||
if not build_config[app].getboolean('build'):
|
if not build_config[app].getboolean('build'):
|
||||||
continue
|
continue
|
||||||
print(f"Checking {app}...")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
apk = build_config[app]['apk']
|
apk = build_config[app]['apk']
|
||||||
|
pretty_name = build_config[app]['pretty_name']
|
||||||
apkpure_appname = build_config[app]['apkpure_appname']
|
apkpure_appname = build_config[app]['apkpure_appname']
|
||||||
except:
|
except:
|
||||||
sys.exit(f"Invalid config for {app} in build_config.toml!")
|
sys.exit(f"Invalid config for {app} in build_config.toml!")
|
||||||
|
|
||||||
|
print(f"Checking {pretty_name}...")
|
||||||
try:
|
try:
|
||||||
required_ver = build_config[app]['version']
|
required_ver = build_config[app]['version']
|
||||||
required_ver[0]
|
required_ver[0]
|
||||||
|
@ -96,7 +100,7 @@ def get_apks(present_vers, build_config):
|
||||||
else:
|
else:
|
||||||
required_ver = min(map(lambda x: Version(x), compatible_vers))
|
required_ver = min(map(lambda x: Version(x), compatible_vers))
|
||||||
|
|
||||||
apkpure_dl(apk, apkpure_appname, str(required_ver), hard_version, session, present_vers)
|
apkpure_dl(apk, apkpure_appname, str(required_ver), hard_version, session, present_vers, flag)
|
||||||
|
|
||||||
present_vers.update({apk: str(required_ver)})
|
present_vers.update({apk: str(required_ver)})
|
||||||
return present_vers
|
return present_vers
|
78
JAVABuilder.py
Normal file
78
JAVABuilder.py
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import configparser as cp
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
# Build the revanced apps
|
||||||
|
def build_apps(build_config, flag):
|
||||||
|
chosen_patches = cp.ConfigParser()
|
||||||
|
chosen_patches.read('chosen_patches.toml')
|
||||||
|
|
||||||
|
try:
|
||||||
|
included_patches = json.loads(chosen_patches['patches']['included'])
|
||||||
|
except:
|
||||||
|
included_patches = []
|
||||||
|
try:
|
||||||
|
excluded_patches = json.loads(chosen_patches['patches']['excluded'])
|
||||||
|
except Exception as e:
|
||||||
|
excluded_patches = []
|
||||||
|
|
||||||
|
for app in build_config:
|
||||||
|
# Check if we need to build an app
|
||||||
|
if not build_config[app].getboolean('build'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Build the command to be run
|
||||||
|
cmd = 'java -jar revanced-cli.jar -m revanced-integrations.apk -b revanced-patches.jar'
|
||||||
|
|
||||||
|
try:
|
||||||
|
root = build_config[app].getboolean('root')
|
||||||
|
except:
|
||||||
|
root = False
|
||||||
|
|
||||||
|
if root:
|
||||||
|
cmd += ' --mount -e microg-support'
|
||||||
|
|
||||||
|
for item in included_patches:
|
||||||
|
cmd += f" -i {item}"
|
||||||
|
for item in excluded_patches:
|
||||||
|
cmd += f" -e {item}"
|
||||||
|
|
||||||
|
if flag == 'experimental':
|
||||||
|
cmd += ' --experimental'
|
||||||
|
|
||||||
|
try:
|
||||||
|
keystore = build_config[app]['keystore']
|
||||||
|
if not root:
|
||||||
|
cmd += f" --keystore {keystore}"
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
apk = build_config[app]['apk']
|
||||||
|
pretty_name = build_config[app]['pretty_name']
|
||||||
|
apkpure_appname = build_config[app]['apkpure_appname']
|
||||||
|
output_name = build_config[app]['output_name']
|
||||||
|
except:
|
||||||
|
sys.exit(f"Invalid config for {app} in build_config.toml!")
|
||||||
|
|
||||||
|
cmd += f" -a {apk}.apk -o {output_name}.apk"
|
||||||
|
|
||||||
|
if root:
|
||||||
|
print(f"Building {pretty_name} (root)...")
|
||||||
|
else:
|
||||||
|
print(f"Building {pretty_name} (nonroot)...")
|
||||||
|
|
||||||
|
# if os.system(cmd) != 0:
|
||||||
|
# sys.exit('There was an error while building!')
|
||||||
|
try:
|
||||||
|
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, text=True)
|
||||||
|
except Exception as e:
|
||||||
|
sys.exit(f"There was an error while building! {e.output}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.rename(output_name+'.apk', output_name+'.apk') # TODO: Add timestamp here
|
||||||
|
except FileNotFoundError:
|
||||||
|
sys.exit(f"There was an error while building {pretty_name}!")
|
||||||
|
|
|
@ -7,6 +7,15 @@ import requests as req
|
||||||
import json
|
import json
|
||||||
from packaging.version import Version
|
from packaging.version import Version
|
||||||
from APKPure_dl import *
|
from APKPure_dl import *
|
||||||
|
from JAVABuilder import *
|
||||||
|
|
||||||
|
# TODO: Logging
|
||||||
|
# TODO: Timestamp
|
||||||
|
# TODO: Notifications
|
||||||
|
# TODO: Notification for errors (maybe by writing custom exit function? Exit function should also cleanup output files. printerr?)
|
||||||
|
# TODO: Moving files in proper locations
|
||||||
|
# TODO: Run post_script (preferably in any language)
|
||||||
|
# TODO: README
|
||||||
|
|
||||||
# Update the ReVanced tools, if needed
|
# Update the ReVanced tools, if needed
|
||||||
def update_tools():
|
def update_tools():
|
||||||
|
@ -19,11 +28,11 @@ def update_tools():
|
||||||
except KeyError:
|
except KeyError:
|
||||||
present_ver = Version('0')
|
present_ver = Version('0')
|
||||||
|
|
||||||
if present_ver < latest_ver:
|
output_file = item+os.path.splitext(tool['name'])[1]
|
||||||
|
if flag == 'force' or not os.path.isfile(output_file) or present_ver < latest_ver:
|
||||||
global up_to_date
|
global up_to_date
|
||||||
up_to_date = False
|
up_to_date = False
|
||||||
print(f"{item} has an update ({str(present_ver)} -> {str(latest_ver)})")
|
print(f"{item} has an update ({str(present_ver)} -> {str(latest_ver)})")
|
||||||
output_file = item.split('-')[1]+os.path.splitext(tool['name'])[1]
|
|
||||||
if flag != 'checkonly':
|
if flag != 'checkonly':
|
||||||
print(f"Downloading {output_file}...")
|
print(f"Downloading {output_file}...")
|
||||||
res = req.get(tool['browser_download_url'], stream=True)
|
res = req.get(tool['browser_download_url'], stream=True)
|
||||||
|
@ -47,12 +56,12 @@ def update_microg():
|
||||||
except KeyError:
|
except KeyError:
|
||||||
present_ver = Version('0')
|
present_ver = Version('0')
|
||||||
|
|
||||||
if present_ver < latest_ver:
|
if flag == 'force' or not os.path.isfile('microg.apk') or present_ver < latest_ver:
|
||||||
global up_to_date
|
global up_to_date
|
||||||
up_to_date = False
|
up_to_date = False
|
||||||
print(f"Vanced microG has an update ({str(present_ver)} -> {str(latest_ver)})")
|
print(f"Vanced microG has an update ({str(present_ver)} -> {str(latest_ver)})")
|
||||||
if flag != 'checkonly':
|
if flag != 'checkonly':
|
||||||
print(f"Downloading microg.apk...")
|
print(f"Downloading vanced-microg.apk...")
|
||||||
res = req.get('https://github.com/inotia00/VancedMicroG/releases/latest/download/microg.apk', stream=True)
|
res = req.get('https://github.com/inotia00/VancedMicroG/releases/latest/download/microg.apk', stream=True)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
with open('microg.apk', 'wb') as f:
|
with open('microg.apk', 'wb') as f:
|
||||||
|
@ -103,15 +112,15 @@ up_to_date = True
|
||||||
if flag != 'buildonly':
|
if flag != 'buildonly':
|
||||||
update_tools()
|
update_tools()
|
||||||
update_microg()
|
update_microg()
|
||||||
# if not up_to_date:
|
if not up_to_date or flag == 'force':
|
||||||
present_vers = get_apks(present_vers, build_config)
|
present_vers = get_apks(present_vers, build_config, flag)
|
||||||
|
|
||||||
# if (flag != 'checkonly' and not up_to_date) or flag == 'force':
|
if (flag != 'checkonly' and not up_to_date) or flag in ['force', 'buildonly']:
|
||||||
# build_apps()
|
build_apps(build_config, flag)
|
||||||
|
|
||||||
# Update version numbers in the versions.json file
|
# Update version numbers in the versions.json file
|
||||||
if up_to_date:
|
if up_to_date and flag != 'buildonly':
|
||||||
print('There\'s nothing to do.')
|
print('There\'s nothing to do.')
|
||||||
elif flag != 'checkonly':
|
elif flag not in ['checkonly', 'buildonly']:
|
||||||
with open('versions.json', 'w') as f:
|
with open('versions.json', 'w') as f:
|
||||||
json.dump(present_vers, f, indent=4)
|
json.dump(present_vers, f, indent=4)
|
||||||
|
|
Loading…
Reference in a new issue