Skip to content

Commit

Permalink
uptodown add support for arch option
Browse files Browse the repository at this point in the history
  • Loading branch information
j-hc committed Jun 7, 2024
1 parent 366286f commit 4d75168
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')}
REBUILD=${REBUILD:-false}
OS=$(uname -o)

# -------------------- json/toml --------------------
toml_prep() { __TOML__=$(tr -d '\t\r' <<<"$1" | tr "'" '"' | grep -o '^[^#]*' | grep -v '^$' | sed -r 's/(\".*\")|\s*/\1/g; 1i []'); }
toml_get_table_names() {
local tn
Expand All @@ -25,7 +24,6 @@ toml_get() {
local table=$1 key=$2 val
val=$(grep -m 1 "^${key}=" <<<"$table") && sed -e "s/^\"//; s/\"$//" <<<"${val#*=}"
}
# ---------------------------------------------------

pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; }
epr() {
Expand Down Expand Up @@ -254,7 +252,6 @@ get_apkmirror_resp() {
__APKMIRROR_RESP__=$(req "${1}" -)
__APKMIRROR_CAT__="${1##*/}"
}
# --------------------------------------------------

# -------------------- uptodown --------------------
get_uptodown_resp() {
Expand All @@ -263,29 +260,36 @@ get_uptodown_resp() {
}
get_uptodown_vers() { $HTMLQ --text ".version" <<<"$__UPTODOWN_RESP__"; }
dl_uptodown() {
local uptodown_dlurl=$1 version=$2 output=$3
local uptodown_dlurl=$1 version=$2 output=$3 arch=$4 is_latest=$6
local url
url=$(grep -F "${version}</span>" -B 2 <<<"$__UPTODOWN_RESP__" | head -1 | sed -n 's;.*data-url=".*download\/\(.*\)".*;\1;p') || return 1
url="https://dw.uptodown.com/dwn/$(req "${uptodown_dlurl}/post-download/${url}" - | sed -n 's;.*class="post-download" data-url="\(.*\)".*;\1;p')" || return 1
if [ "$is_latest" = false ]; then
url=$(grep -F "${version}</span>" -B 2 <<<"$__UPTODOWN_RESP__" | head -1 | sed -n 's;.*data-url=".*download\/\(.*\)".*;\1;p') || return 1
url="/$url"
else url=""; fi
if [ "$arch" != all ]; then
local app_code data_version files node_arch content resp
if [ "$is_latest" = false ]; then
resp=$(req "${1}/download${url}" -)
else resp="$__UPTODOWN_RESP_PKG__"; fi
app_code=$($HTMLQ "#detail-app-name" --attribute code <<<"$resp")
data_version=$($HTMLQ "button.button:nth-child(2)" --attribute data-version <<<"$resp")
files=$(req "${uptodown_dlurl%/*}/app/${app_code}/version/${data_version}/files" - | jq -r .content)
for ((n = 1; n < 40; n++)); do
node_arch=$($HTMLQ ".content > p:nth-child($n)" --text <<<"$files" | xargs) || return 1
if [ -z "$node_arch" ]; then return 1; fi
if [ "$node_arch" != "$arch" ]; then continue; fi
content=$($HTMLQ "div.variant:nth-child($((n + 1)))" <<<"$files")
url=$(sed -n "s;.*'.*android\/post-download\/\(.*\)'.*;\1;p" <<<"$content" | head -1)
url="/$url"
break
done
fi
url="https://dw.uptodown.com/dwn/$(req "${uptodown_dlurl}/post-download${url}" - | sed -n 's;.*class="post-download" data-url="\(.*\)".*;\1;p')" || return 1
req "$url" "$output"
}
get_uptodown_pkg_name() { $HTMLQ --text "tr.full:nth-child(1) > td:nth-child(3)" <<<"$__UPTODOWN_RESP_PKG__"; }
# --------------------------------------------------

# -------------------- apkmonk ---------------------
get_apkmonk_resp() {
__APKMONK_RESP__=$(req "${1}" -)
__APKMONK_PKG_NAME__=$(awk -F/ '{print $NF}' <<<"$1")
}
get_apkmonk_vers() { grep -oP 'download_ver.+?>\K([0-9,\.]*)' <<<"$__APKMONK_RESP__"; }
dl_apkmonk() {
local url=$1 version=$2 output=$3
url="https://www.apkmonk.com/down_file?pkg="$(grep -F "$version</a>" <<<"$__APKMONK_RESP__" | grep -oP 'href=\"/download-app/\K.+?(?=/?\">)' | sed 's;/;\&key=;') || return 1
url=$(req "$url" - | grep -oP 'https.+?(?=\",)') || return 1
req "$url" "$output"
}
get_apkmonk_pkg_name() { echo "$__APKMONK_PKG_NAME__"; }
# --------------------------------------------------
# -------------------- archive --------------------
dl_archive() {
local url=$1 version=$2 output=$3 arch=$4
local path version=${version// /}
Expand Down Expand Up @@ -381,7 +385,7 @@ build_rv() {
for dl_p in archive apkmirror uptodown apkmonk; do
if [ -z "${args[${dl_p}_dlurl]}" ]; then continue; fi
pr "Downloading '${table}' from ${dl_p}"
if ! dl_${dl_p} "${args[${dl_p}_dlurl]}" "$version" "$stock_apk" "$arch" "${args[dpi]}"; then
if ! dl_${dl_p} "${args[${dl_p}_dlurl]}" "$version" "$stock_apk" "$arch" "${args[dpi]}" "$get_latest_ver"; then
epr "ERROR: Could not download '${table}' from ${dl_p} with version '${version}', arch '${arch}', dpi '${args[dpi]}'"
continue
fi
Expand Down

0 comments on commit 4d75168

Please sign in to comment.