-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapk-get
More file actions
executable file
·133 lines (112 loc) · 5.13 KB
/
Copy pathapk-get
File metadata and controls
executable file
·133 lines (112 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# Cli tool to download & Install apks from UpToDown, by KebabLord.
# VERSION: 3.0
# DEPENDS: curl, awk, grep
# Set default values
is_list=false
is_first=false
is_yes=false
res_limit=6
help_msg="USAGE: $0 <args> <app_name>
(no arg) : Prompts user to select one of the applications from list.
-l : Just list the available applications, don't install anything.
-f : Directly select the first result and install.
-y : Answer yes to \"Are you sure\" prompt.
-n : Select n'th result from list and install.
-a : Show all results, Don't limit results to $res_limit.
-h : Show this help message."
while getopts "lyan:fh" opt; do
case $opt in
l) is_list=true;;
y) is_yes=true;;
a) res_limit=36;;
n) custom_index="$OPTARG";;
f) res_limit=1;;
*) echo "$help_msg"; exit 0;;
esac
done
shift $((OPTIND-1))
app="$1"
[ -z "$app" ] && echo "$help_msg" && exit 1
# Function to send initial request.
send_req() {
# First param being the mirror subdomain, 2nd param is the application name to be searched.
curl -m 9 "https://$1.uptodown.com/android/search" -X POST -H \
'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0' -H \
'Referer: https://en.uptodown.com/' --data-raw "singlebutton=&q=$2" 2>/dev/null
}
# Try different mirrors until one bypasses 500,503 and 504.
mirrors="fr en de tr es it pt zh ar id ko"
for mirror in $mirrors; do
req=$(send_req $mirror $app) || continue
grep "Error 503 first byte timeout\|Uptodown 500\|504 Gateway Time" &>/dev/null <<< "$req" && continue
break
done
# Parse the results into url+title, exit if grep fails.
results=$(echo "$req" | grep -Po 'https:\/\/[a-z_-]+?\.[a-z][a-z].uptodown.com\/android" title="[^<>"]+')
[[ $? != 0 ]] && echo "ERROR: Couldn't find the application." && exit 1
amount=$(echo "$results" | wc -l)
# Print titles so user can choose one, also add each item to the lists.
i=1
while IFS= read -r res; do
urls[$i]="$(awk -F '" title="[^ ]+ ' '{print $1}' <<< "$res")"
titles[$i]="$(awk -F '" title="[^ ]+ ' '{print $2}' <<< "$res")"
[ $amount -gt 1 ] && (! $is_first) && [ -z $custom_index ] && echo "$i) ${titles[$i]}"
[[ "$i" == "$res_limit" ]] && break
((i++))
done <<< "$results"
# If "only list, not install" is enabled, quit.
$is_list && exit 0
# If "use directly the first result" or more than one result, show "choose" prompt.
if [[ "$custom_index" == ?(-)+([0-9]) ]]; then
index=$custom_index
elif [ $res_limit -ne 1 ] || [ -z "${titles[2]}" ]; then
echo -ne "\nSelect one from above: "
read -r index
echo
[[ "$index" != ?(-)+([0-9]) ]] && ( echo Not a valid number. ; exit 1 )
else
index=1
fi
app_url=${urls[$index]}
#app_url=$(sed "s/\.$mirror\./\./g" <<< $app_url ) #Remove .en.
app_title=${titles[$index]}
slug=$(grep -Po '(?<=https://)[^.]+' <<< $app_url) # Extract app-uri
echo -e "Selected: $app_title"
# Scrape file path by visiting the "downloads" page.
echo -e -n " - Loading download page.. "
#DEBUG: echo;echo DEBUG: curl -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0' -L --compressed "$app_url/dw"
src=$(curl -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0' -L --compressed "$app_url/dw" 2>/dev/null)
grep '404 Not Found' <<< "$src" >/dev/null && echo -e "\n\nERROR: Couldn't load download page, we might be blocked." && exit 1
echo OK
version=$(grep -Po '<div class="version">\K[^<]+' <<< "$src" | sed 's/\./-/g')
hash=$(grep -Po 'data-url="\K[^"]+(?="\s+data-download)' <<< "$src" )
[[ -z "$version" || -z "$hash" ]] && echo -e "\n\nERROR: Couldn't parse file url." && exit 1
file_url="https://dw.uptodown.net/dwn/$hash$slug-$version.apk"
grep 'class="button variants"' <<< "$src" && {
echo -n " - XAPK Detected, loading variant page... "
file_id=$(grep -m1 -Po 'data-file-id="\K\d+(?=")' <<< "$src") || { echo -e "\n\nERROR: Couldn't parse data-file-id."; exit 1; }
variant_url="https://lmr-loyalty-free-music.en.uptodown.com/android/download/$file_id-x"
src2=$(curl -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0' -L --compressed "$variant_url")
hash=$(grep -Po 'data-url="\K[^"]+(?="\s+data-download)' <<< "$src2" )
[[ -z "$hash" ]] && echo -e "\n\nERROR: Couldn't parse file hash." && exit 1
echo OK
file_url="https://dw.uptodown.net/dwn/$hash$slug-$version.xapk"
x="x";X="X"
}
#DEBUG: echo VARIANT: $variant_url;echo FILE_URL: $file_url;echo HASH: $hash;echo VERSION: $version;exit 0
# Download the file.
echo " - Downloading the ${X}APK"
curl -L --progress-bar -o "$app.${x}apk" "$file_url"
[[ -n "$x" ]] && exit 0 # Exit early as we can't install XAPK files for now.
# Install the apk.
if ($is_yes || (read -p "Do you want to install the apk? (y/n): " yn && [[ $yn == y ]])); then
if su -c true &>/dev/null;then
sudo="su -c"
fi
$sudo pm install "$app.apk" 2>/dev/null && exit 0
if which termux-open &>/dev/null;then
termux-open "$app.apk" && exit 0
fi
echo "Couldn't install the APK. Read the README of this script for more information regarding installing apks."; exit 1
fi