better apkmirror stub downloading

This commit is contained in:
j-hc 2023-03-09 20:51:19 +03:00
parent ae129817bc
commit 7a1a574618
No known key found for this signature in database
GPG Key ID: FCBF5E9C57092AD9

View File

@ -180,22 +180,16 @@ dl_apkmirror() {
node=$($HTMLQ "div.table-row:nth-child($n)" -r "span:nth-child(n+3)" <<<"$resp")
if [ -z "$node" ]; then break; fi
app_table=$($HTMLQ --text --ignore-whitespace <<<"$node")
if [ "$(sed -n 3p <<<"$app_table")" = "$apkorbundle" ]; then
if [ "$apkorbundle" = APK ]; then
if [ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] && isoneof "$(sed -n 4p <<<"$app_table")" "${apparch[@]}"; then
dlurl=https://www.apkmirror.com$($HTMLQ --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node")
break
fi
elif [ "$apkorbundle" = BUNDLE ]; then
dlurl=https://www.apkmirror.com$($HTMLQ --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node")
break
else
abort "unreachable"
fi
if [ "$(sed -n 3p <<<"$app_table")" = "$apkorbundle" ] && { [ "$apkorbundle" = BUNDLE ] ||
{ [ "$apkorbundle" = APK ] && [ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] &&
isoneof "$(sed -n 4p <<<"$app_table")" "${apparch[@]}"; }; }; then
dlurl=https://www.apkmirror.com$($HTMLQ --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node")
break
fi
done
[ -z "$dlurl" ] && return 1
url="https://www.apkmirror.com$(req "$dlurl" - | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
url="https://www.apkmirror.com$(req "$dlurl" - | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p' | tail -1)"
if [ "$apkorbundle" = BUNDLE ] && [[ "$url" != *"&forcebaseapk=true" ]]; then url="${url}&forcebaseapk=true"; fi
url="https://www.apkmirror.com$(req "$url" - | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
req "$url" "$output"
}
@ -364,7 +358,6 @@ build_rv() {
p_patcher_args=("${p_patcher_args[@]//-[ei] ${microg_patch}/}")
fi
local stock_bundle="${TEMP_DIR}/${pkg_name}-${version_f}-${arch}-bundle.zip"
local stock_bundle_apk="${TEMP_DIR}/${pkg_name}-${version_f}-${arch}-bundle.apk"
local is_bundle=false
if [ "$mode_arg" = module ] || [ "$mode_arg" = both ]; then
@ -372,12 +365,13 @@ build_rv() {
is_bundle=true
elif [ "$dl_from" = apkmirror ]; then
pr "Downloading '${app_name}' bundle from APKMirror"
if dl_apkmirror "${args[apkmirror_dlurl]}" "$version" "$stock_bundle" BUNDLE "" ""; then
pr "'${app_name}' bundle was downloaded successfully and will be used for the module"
is_bundle=true
unzip "$stock_bundle" "base.apk" -d $TEMP_DIR
mv ${TEMP_DIR}/base.apk "$stock_bundle_apk"
rm -f "$stock_bundle"
if dl_apkmirror "${args[apkmirror_dlurl]}" "$version" "$stock_bundle_apk" BUNDLE "" ""; then
if (($(stat -c%s "$stock_apk") - $(stat -c%s "$stock_bundle_apk") > 10000000)); then
pr "'${app_name}' bundle was downloaded successfully and will be used for the module"
is_bundle=true
else
pr "'${app_name}' bundle was downloaded but will not be used"
fi
else
pr "'${app_name}' bundle was not found"
fi