mirror of
https://github.com/SinTan1729/ReVancedBuilder.git
synced 2024-12-26 12:48:36 -06:00
fix: Check required version
This commit is contained in:
parent
0a701f4588
commit
8e126d4d45
1 changed files with 25 additions and 25 deletions
|
@ -48,8 +48,9 @@ def apkpure_dl(apk, appname, version, hard_version, session, present_vers, flag)
|
||||||
if not hard_version:
|
if not hard_version:
|
||||||
apkpure_version = apkpure_best_match(version, soup)
|
apkpure_version = apkpure_best_match(version, soup)
|
||||||
if version not in [apkpure_version, '0']:
|
if version not in [apkpure_version, '0']:
|
||||||
print(f"Required version {version} not found in APKPure, choosing version {apkpure_version} instead.")
|
print(
|
||||||
version=apkpure_version
|
f"Required version {version} not found in APKPure, choosing version {apkpure_version} instead.")
|
||||||
|
version = apkpure_version
|
||||||
try:
|
try:
|
||||||
if present_vers[apk] == version and flag != 'force' and os.path.isfile(apk+'.apk'):
|
if present_vers[apk] == version and flag != 'force' and os.path.isfile(apk+'.apk'):
|
||||||
print(
|
print(
|
||||||
|
@ -66,13 +67,13 @@ def apkpure_dl(apk, appname, version, hard_version, session, present_vers, flag)
|
||||||
|
|
||||||
# Get the version code
|
# Get the version code
|
||||||
try:
|
try:
|
||||||
ver_code=soup.css.select(
|
ver_code = soup.css.select(
|
||||||
f"a[data-dt-version=\"{version}\"][data-dt-apkid^=\"b/APK/\"]")[0]['data-dt-versioncode']
|
f"a[data-dt-version=\"{version}\"][data-dt-apkid^=\"b/APK/\"]")[0]['data-dt-versioncode']
|
||||||
except:
|
except:
|
||||||
err_exit(
|
err_exit(
|
||||||
f" There was some error while downloading {apk}...", appstate)
|
f" There was some error while downloading {apk}...", appstate)
|
||||||
|
|
||||||
res=session.get(
|
res = session.get(
|
||||||
f"https://d.apkpure.com/b/APK/{apk}?versionCode={ver_code}", stream=True)
|
f"https://d.apkpure.com/b/APK/{apk}?versionCode={ver_code}", stream=True)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
with open(apk+'.apk', 'wb') as f:
|
with open(apk+'.apk', 'wb') as f:
|
||||||
|
@ -81,25 +82,24 @@ def apkpure_dl(apk, appname, version, hard_version, session, present_vers, flag)
|
||||||
print(" Done!")
|
print(" Done!")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Download apk files, if needed
|
# Download apk files, if needed
|
||||||
def get_apks(appstate):
|
def get_apks(appstate):
|
||||||
present_vers=appstate['present_vers']
|
present_vers = appstate['present_vers']
|
||||||
build_config=appstate['build_config']
|
build_config = appstate['build_config']
|
||||||
flag=appstate['flag']
|
flag = appstate['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
|
||||||
try:
|
try:
|
||||||
# Get the first result
|
# Get the first result
|
||||||
patches_json=next(filter(
|
patches_json = next(filter(
|
||||||
lambda x: x['repository'] == 'revanced/revanced-patches', appstate['tools']))
|
lambda x: x['repository'] == 'revanced/revanced-patches', appstate['tools']))
|
||||||
patches=req.get(patches_json['browser_download_url']).json()
|
patches = req.get(patches_json['browser_download_url']).json()
|
||||||
except req.exceptions.RequestException as e:
|
except req.exceptions.RequestException as e:
|
||||||
err_exit(f"Error fetching patches, {e}", appstate)
|
err_exit(f"Error fetching patches, {e}", appstate)
|
||||||
|
|
||||||
session=req.Session()
|
session = req.Session()
|
||||||
session.headers.update(
|
session.headers.update(
|
||||||
{'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0'})
|
{'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0'})
|
||||||
|
|
||||||
|
@ -109,38 +109,38 @@ def get_apks(appstate):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
apk=build_config[app]['apk']
|
apk = build_config[app]['apk']
|
||||||
pretty_name=build_config[app]['pretty_name']
|
pretty_name = build_config[app]['pretty_name']
|
||||||
apkpure_appname=build_config[app]['apkpure_appname']
|
apkpure_appname = build_config[app]['apkpure_appname']
|
||||||
except:
|
except:
|
||||||
err_exit(f"Invalid config for {app} in build_config!", appstate)
|
err_exit(f"Invalid config for {app} in build_config!", appstate)
|
||||||
|
|
||||||
print(f"Checking {pretty_name}...")
|
print(f"Checking {pretty_name}...")
|
||||||
try:
|
try:
|
||||||
required_ver=build_config[app]['version']
|
required_ver = build_config[app]['version']
|
||||||
required_ver[0]
|
required_ver = Version(required_ver)
|
||||||
hard_version=True
|
hard_version = True
|
||||||
print(f"Using version {required_ver} of {app} from build_config.")
|
print(f"Using version {required_ver} of {app} from build_config.")
|
||||||
except:
|
except:
|
||||||
hard_version=False
|
hard_version = False
|
||||||
compatible_vers=[]
|
compatible_vers = []
|
||||||
for patch in patches:
|
for patch in patches:
|
||||||
for pkg in patch['compatiblePackages']:
|
for pkg in patch['compatiblePackages']:
|
||||||
if pkg['name'] == apk:
|
if pkg['name'] == apk:
|
||||||
try:
|
try:
|
||||||
compatible_vers.append(pkg['versions'][-1])
|
compatible_vers.append(pkg['versions'][-1])
|
||||||
except IndexError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not compatible_vers:
|
if not compatible_vers:
|
||||||
required_ver=Version('0')
|
required_ver = Version('0')
|
||||||
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),
|
apkpure_dl(apk, apkpure_appname, str(required_ver),
|
||||||
hard_version, session, present_vers, flag)
|
hard_version, session, present_vers, flag)
|
||||||
|
|
||||||
present_vers.update({apk: str(required_ver)})
|
present_vers.update({apk: str(required_ver)})
|
||||||
|
|
||||||
appstate['present_vers']=present_vers
|
appstate['present_vers'] = present_vers
|
||||||
return appstate
|
return appstate
|
||||||
|
|
Loading…
Reference in a new issue