mirror of
https://github.com/SinTan1729/ReVancedBuilder.git
synced 2024-12-25 20:28:37 -06:00
new: Be more verbose while choosing versions
This commit is contained in:
parent
4e97393ea2
commit
a215aa6467
1 changed files with 49 additions and 32 deletions
|
@ -14,11 +14,15 @@ from bs4 import BeautifulSoup as bs
|
|||
from ReVancedBuilder.Cleanup import err_exit
|
||||
|
||||
# Determine the best version available to download
|
||||
|
||||
|
||||
def apkpure_best_match(version, soup):
|
||||
try:
|
||||
vers_list = [Version(x['data-dt-version']) for x in soup.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:
|
||||
err_exit(f" There was some error getting list of versions of {apk}...", appstate)
|
||||
err_exit(
|
||||
f" There was some error getting list of versions of {apk}...", appstate)
|
||||
|
||||
if version != '0':
|
||||
vers_list = filter(lambda x: x <= Version(version), vers_list)
|
||||
|
@ -26,13 +30,18 @@ def apkpure_best_match(version, soup):
|
|||
return str(max(vers_list))
|
||||
|
||||
# Download an apk from APKPure.com
|
||||
|
||||
|
||||
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:
|
||||
version = apkpure_best_match(version, soup)
|
||||
apkpure_version = apkpure_best_match(version, soup)
|
||||
if version != apkpure_version:
|
||||
print(f"Required version {version} not found in APKPure, choosing version {apkpure_version} instead.")
|
||||
version=apkpure_version
|
||||
|
||||
if flag == 'checkonly' and present_vers[apk] != version:
|
||||
print(f"{apk} has an update ({present_vers[apk]} -> {version})")
|
||||
|
@ -40,7 +49,8 @@ def apkpure_dl(apk, appname, version, hard_version, session, present_vers, flag)
|
|||
|
||||
try:
|
||||
if present_vers[apk] == version and flag != 'force' and os.path.isfile(apk+'.apk'):
|
||||
print(f"Recommended version {version} of {apk} is already present.")
|
||||
print(
|
||||
f"Recommended version {version} of {apk} is already present.")
|
||||
return
|
||||
except KeyError:
|
||||
pass
|
||||
|
@ -48,11 +58,14 @@ def apkpure_dl(apk, appname, version, hard_version, session, present_vers, flag)
|
|||
|
||||
# Get the version code
|
||||
try:
|
||||
ver_code = soup.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:
|
||||
err_exit(f" There was some error while downloading {apk}...", appstate)
|
||||
err_exit(
|
||||
f" There was some error while downloading {apk}...", appstate)
|
||||
|
||||
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()
|
||||
with open(apk+'.apk', 'wb') as f:
|
||||
for chunk in res.iter_content(chunk_size=8192):
|
||||
|
@ -71,13 +84,16 @@ def get_apks(appstate):
|
|||
|
||||
# Get latest patches using the ReVanced API
|
||||
try:
|
||||
patches_json = next(filter(lambda x: x['repository'] == 'revanced/revanced-patches', appstate['tools'])) # Get the first result
|
||||
# Get the first result
|
||||
patches_json=next(filter(
|
||||
lambda x: x['repository'] == 'revanced/revanced-patches', appstate['tools']))
|
||||
patches=req.get(patches_json['browser_download_url']).json()
|
||||
except req.exceptions.RequestException as e:
|
||||
err_exit(f"Error fetching patches, {e}", appstate)
|
||||
|
||||
session=req.Session()
|
||||
session.headers.update({'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0'})
|
||||
session.headers.update(
|
||||
{'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0'})
|
||||
|
||||
for app in build_config:
|
||||
# Check if we need to build an app
|
||||
|
@ -96,7 +112,7 @@ def get_apks(appstate):
|
|||
required_ver=build_config[app]['version']
|
||||
required_ver[0]
|
||||
hard_version=True
|
||||
print(f"Using version {required_ver} of {app} from ")
|
||||
print(f"Using version {required_ver} of {app} from build_config.")
|
||||
except:
|
||||
hard_version=False
|
||||
compatible_vers=[]
|
||||
|
@ -113,7 +129,8 @@ def get_apks(appstate):
|
|||
else:
|
||||
required_ver=min(map(lambda x: Version(x), compatible_vers))
|
||||
|
||||
apkpure_dl(apk, apkpure_appname, str(required_ver), hard_version, session, present_vers, flag)
|
||||
apkpure_dl(apk, apkpure_appname, str(required_ver),
|
||||
hard_version, session, present_vers, flag)
|
||||
|
||||
present_vers.update({apk: str(required_ver)})
|
||||
|
||||
|
|
Loading…
Reference in a new issue