Compare commits

..
3 Commits
Author SHA1 Message Date
nezumi d24f8939d0 fix: download apk issues 2026-02-24 17:04:12 +07:00
nezumi 3becfad4f7 fix: resolve the utils logic 2026-01-17 13:03:35 +07:00
nezumi 0e85707946 fix: resolve the utils logic 2026-01-17 12:58:05 +07:00
+62 -32
View File
@@ -99,7 +99,15 @@ get_rv_prebuilts() {
resp=$(gh_req "$rv_rel" -) || return 1
if [ "$ver" = "dev" ]; then resp=$(jq -r '.[0]' <<<"$resp"); fi
tag_name=$(jq -r '.tag_name' <<<"$resp")
asset=$(jq -e -r ".assets[] | select(.name | endswith(\"$ext\"))" <<<"$resp") || return 1
# Filter assets by extension and handle multiple matches
# Use jq array syntax to get first match as a complete JSON object
if [ "$ver" = "dev" ]; then
# For dev version, prefer the one with "dev" in the name
asset=$(jq -e -r "[.assets[] | select(.name | endswith(\"$ext\") and contains(\"dev\"))][0] // [.assets[] | select(.name | endswith(\"$ext\"))][0]" <<<"$resp") || return 1
else
# For non-dev versions, exclude dev builds and take the first match
asset=$(jq -e -r "[.assets[] | select(.name | endswith(\"$ext\") and (contains(\"dev\") | not))][0] // [.assets[] | select(.name | endswith(\"$ext\"))][0]" <<<"$resp") || return 1
fi
url=$(jq -r .url <<<"$asset")
name=$(jq -r .name <<<"$asset")
file="${dir}/${name}"
@@ -287,7 +295,7 @@ isoneof() {
merge_splits() {
local bundle=$1 output=$2
pr "Merging splits"
gh_dl "$TEMP_DIR/apkeditor.jar" "https://github.com/REAndroid/APKEditor/releases/download/V1.4.2/APKEditor-1.4.2.jar" >/dev/null || return 1
gh_dl "$TEMP_DIR/apkeditor.jar" "https://github.com/REAndroid/APKEditor/releases/download/V1.4.7/APKEditor-1.4.7.jar" >/dev/null || return 1
if ! OP=$(java -jar "$TEMP_DIR/apkeditor.jar" merge -i "${bundle}" -o "${bundle}.mzip" -clean-meta -f 2>&1); then
epr "Apkeditor ERROR: $OP"
return 1
@@ -312,23 +320,32 @@ merge_splits() {
}
# -------------------- apkmirror --------------------
apk_mirror_search() {
apkmirror_search() {
local resp="$1" dpi="$2" arch="$3" apk_bundle="$4"
local apparch dlurl node app_table
local apparch dlurl="" node app_table emptyCheck
if [ "$arch" = all ]; then
apparch=(universal noarch 'arm64-v8a + armeabi-v7a')
else apparch=("$arch" universal noarch 'arm64-v8a + armeabi-v7a'); fi
for ((n = 1; n < 40; n++)); do
node=$($HTMLQ "div.table-row.headerFont:nth-last-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")" = "$apk_bundle" ] && [ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] &&
isoneof "$(sed -n 4p <<<"$app_table")" "${apparch[@]}"; then
emptyCheck=$($HTMLQ -t -w "div.table-cell:nth-child(1) > a:nth-child(1)" --attribute class <<<"$node" | xargs)
if [ "$emptyCheck" ]; then
dlurl=$($HTMLQ --base https://www.apkmirror.com --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node")
else break; fi
app_table=$($HTMLQ --text --ignore-whitespace <<<"$node")
if [ "$(sed -n 3p <<<"$app_table")" = "$apk_bundle" ] &&
[ "$(sed -n 6p <<<"$app_table")" = "$dpi" ] &&
isoneof "$(sed -n 4p <<<"$app_table")" "${apparch[@]}"; then
echo "$dlurl"
return 0
fi
done
if [ "$n" -eq 2 ] && [ "$dlurl" ]; then
# only one apk exists, return it
echo "$dlurl"
return 0
fi
return 1
}
dl_apkmirror() {
@@ -337,18 +354,21 @@ dl_apkmirror() {
is_bundle=true
else
if [ "$arch" = "arm-v7a" ]; then arch="armeabi-v7a"; fi
local resp node app_table uurl dlurl=""
uurl=$(grep -F "downloadLink" <<<"$__APKMIRROR_RESP__" | grep -F "${version//./-}-release/" | head -1 |
sed -n 's;.*href="\(.*-release\).*;\1;p')
if [ -z "$uurl" ]; then url="${url}/${url##*/}-${version//./-}-release/"; else url=https://www.apkmirror.com$uurl; fi
local resp node app_table apkmname dlurl=""
apkmname=$($HTMLQ "h1.marginZero" --text <<<"$__APKMIRROR_RESP__")
apkmname="${apkmname,,}" apkmname="${apkmname// /-}" apkmname="${apkmname//[^a-z0-9-]/}"
url="${url}/${apkmname}-${version//./-}-release/"
resp=$(req "$url" -) || return 1
node=$($HTMLQ "div.table-row.headerFont:nth-last-child(1)" -r "span:nth-child(n+3)" <<<"$resp")
if [ "$node" ]; then
if ! dlurl=$(apk_mirror_search "$resp" "$dpi" "${arch}" "APK"); then
if ! dlurl=$(apk_mirror_search "$resp" "$dpi" "${arch}" "BUNDLE"); then
return 1
else is_bundle=true; fi
fi
for current_dpi in $dpi; do
for type in APK BUNDLE; do
if dlurl=$(apkmirror_search "$resp" "$current_dpi" "${arch}" "$type"); then
[[ "$type" == "BUNDLE" ]] && is_bundle=true || is_bundle=false
break 2
fi
done
done
[ -z "$dlurl" ] && return 1
resp=$(req "$dlurl" -)
fi
@@ -381,14 +401,14 @@ get_apkmirror_vers() {
}
get_apkmirror_pkg_name() { sed -n 's;.*id=\(.*\)" class="accent_color.*;\1;p' <<<"$__APKMIRROR_RESP__"; }
get_apkmirror_resp() {
__APKMIRROR_RESP__=$(req "${1}" -)
__APKMIRROR_RESP__=$(req "${1}" -) || return 1
__APKMIRROR_CAT__="${1##*/}"
}
# -------------------- uptodown --------------------
get_uptodown_resp() {
__UPTODOWN_RESP__=$(req "${1}/versions" -)
__UPTODOWN_RESP_PKG__=$(req "${1}/download" -)
__UPTODOWN_RESP__=$(req "${1}/versions" -) || return 1
__UPTODOWN_RESP_PKG__=$(req "${1}/download" -) || return 1
}
get_uptodown_vers() { $HTMLQ --text ".version" <<<"$__UPTODOWN_RESP__"; }
dl_uptodown() {
@@ -396,14 +416,14 @@ dl_uptodown() {
local apparch
if [ "$arch" = "arm-v7a" ]; then arch="armeabi-v7a"; fi
if [ "$arch" = all ]; then
apparch=('arm64-v8a, armeabi-v7a, x86, x86_64' 'arm64-v8a, armeabi-v7a')
else apparch=("$arch" 'arm64-v8a, armeabi-v7a, x86, x86_64' 'arm64-v8a, armeabi-v7a'); fi
apparch=('arm64-v8a, armeabi-v7a, x86_64' 'arm64-v8a, armeabi-v7a, x86, x86_64' 'arm64-v8a, armeabi-v7a')
else apparch=("$arch" 'arm64-v8a, armeabi-v7a, x86_64' 'arm64-v8a, armeabi-v7a, x86, x86_64' 'arm64-v8a, armeabi-v7a'); fi
local op resp data_code
data_code=$($HTMLQ "#detail-app-name" --attribute data-code <<<"$__UPTODOWN_RESP__")
local versionURL=""
local is_bundle=false
for i in {1..5}; do
for i in {1..20}; do
resp=$(req "${uptodown_dlurl}/apps/${data_code}/versions/${i}" -)
if ! op=$(jq -e -r ".data | map(select(.version == \"${version}\")) | .[0]" <<<"$resp"); then
continue
@@ -412,20 +432,30 @@ dl_uptodown() {
if versionURL=$(jq -e -r '.versionURL' <<<"$op"); then break; else return 1; fi
done
if [ -z "$versionURL" ]; then return 1; fi
versionURL=$(jq -e -r '.url + "/" + .extraURL + "/" + (.versionID | tostring)' <<<"$versionURL")
resp=$(req "$versionURL" -) || return 1
local data_version files node_arch data_file_id
local data_version files node_arch="" data_file_id node_class
data_version=$($HTMLQ '.button.variants' --attribute data-version <<<"$resp") || return 1
files=$(req "${uptodown_dlurl%/*}/app/${data_code}/version/${data_version}/files" - | jq -e -r .content) || return 1
for ((n = 1; n < 12; n += 2)); do
node_arch=$($HTMLQ ".content > p:nth-child($n)" --text <<<"$files" | xargs) || return 1
if [ -z "$node_arch" ]; then return 1; fi
if ! isoneof "$node_arch" "${apparch[@]}"; then continue; fi
data_file_id=$($HTMLQ "div.variant:nth-child($((n + 1))) > .v-report" --attribute data-file-id <<<"$files") || return 1
resp=$(req "${uptodown_dlurl}/download/${data_file_id}-x" -)
break
done
if [ "$data_version" ]; then
files=$(req "${uptodown_dlurl%/*}/app/${data_code}/version/${data_version}/files" - | jq -e -r .content) || return 1
for ((n = 1; n < 12; n += 1)); do
node_class=$($HTMLQ -w -t ".content > :nth-child($n)" --attribute class <<<"$files") || return 1
if [ "$node_class" != "variant" ]; then
node_arch=$($HTMLQ -w -t ".content > :nth-child($n)" <<<"$files" | xargs) || return 1
continue
fi
if [ -z "$node_arch" ]; then return 1; fi
if ! isoneof "$node_arch" "${apparch[@]}"; then continue; fi
file_type=$($HTMLQ -w -t ".content > :nth-child($n) > .v-file > span" <<<"$files") || return 1
if [ "$file_type" = "xapk" ]; then is_bundle=true; else is_bundle=false; fi
data_file_id=$($HTMLQ ".content > :nth-child($n) > .v-report" --attribute data-file-id <<<"$files") || return 1
resp=$(req "${uptodown_dlurl}/download/${data_file_id}-x" -)
break
done
if [ $n -eq 12 ]; then return 1; fi
fi
local data_url
data_url=$($HTMLQ "#detail-download-button" --attribute data-url <<<"$resp") || return 1
if [ $is_bundle = true ]; then