forked from n0k0m3/revanced-build-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload_apkmirror.sh
executable file
·130 lines (111 loc) · 4.1 KB
/
download_apkmirror.sh
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
#!/usr/bin/env bash
declare -A apks
apks["com.google.android.youtube.apk"]=dl_yt
apks["com.google.android.apps.youtube.music.apk"]=dl_ytm
apks["com.zhiliaoapp.musically.apk"]=dl_tt
apks["tv.twitch.android.app.apk"]=dl_twi
## Functions
# Wget user agent
WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
# Wget function
req() { wget -nv -O "$2" --header="$WGET_HEADER" "$1"; }
# Wget apk verions
get_apk_vers() { req "$1" - | sed -n 's;.*Version:</span><span class="infoSlide-value">\(.*\) </span>.*;\1;p'; }
# Wget apk verions(largest)
get_largest_ver() {
local max=0
while read -r v || [ -n "$v" ]; do
if [[ ${v//[!0-9]/} -gt ${max//[!0-9]/} ]]; then max=$v; fi
done
if [[ $max = 0 ]]; then echo ""; else echo "$max"; fi
}
# Wget download apk
dl_apk() {
local url=$1 regexp=$2 output=$3
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n "s/href=\"/@/g; s;.*${regexp}.*;\1;p")"
echo "$url"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
req "$url" "$output"
}
# Downloading youtube
dl_yt() {
echo "Downloading YouTube"
local last_ver
last_ver="$version"
last_ver="${last_ver:-$(get_apk_vers "https://www.apkmirror.com/uploads/?appcategory=youtube" | get_largest_ver)}"
echo "Choosing version '${last_ver}'"
local base_apk="com.google.android.youtube.apk"
if [ ! -f "$base_apk" ]; then
declare -r dl_url=$(dl_apk "https://www.apkmirror.com/apk/google-inc/youtube/youtube-${last_ver//./-}-release/" \
"APK</span>[^@]*@\([^#]*\)" \
"$base_apk")
echo "YouTube version: ${last_ver}"
echo "downloaded from: [APKMirror - YouTube]($dl_url)"
fi
}
# Architectures
ARM64_V8A="arm64-v8a"
ARM_V7A="arm-v7a"
# Downloading youtube music
dl_ytm() {
local arch=$ARM64_V8A
echo "Downloading YouTube Music (${arch})"
local last_ver
last_ver="$version"
last_ver="${last_ver:-$(get_apk_vers "https://www.apkmirror.com/uploads/?appcategory=youtube-music" | get_largest_ver)}"
echo "Choosing version '${last_ver}'"
local base_apk="com.google.android.apps.youtube.music.apk"
if [ ! -f "$base_apk" ]; then
if [ "$arch" = "$ARM64_V8A" ]; then
local regexp_arch='arm64-v8a</div>[^@]*@\([^"]*\)'
elif [ "$arch" = "$ARM_V7A" ]; then
local regexp_arch='armeabi-v7a</div>[^@]*@\([^"]*\)'
fi
declare -r dl_url=$(dl_apk "https://www.apkmirror.com/apk/google-inc/youtube-music/youtube-music-${last_ver//./-}-release/" \
"$regexp_arch" \
"$base_apk")
echo "\nYouTube Music (${arch}) version: ${last_ver}"
echo "downloaded from: [APKMirror - YouTube Music ${arch}]($dl_url)"
fi
}
# Downloading tiktok
dl_tt() {
echo "Downloading TikTok"
local last_ver
last_ver="$version"
last_ver="${last_ver:-$(get_apk_vers "https://www.apkmirror.com/uploads/?appcategory=tik-tok-including-musical-ly" | get_largest_ver)}"
echo "Choosing version '${last_ver}'"
local base_apk="com.zhiliaoapp.musically.apk"
if [ ! -f "$base_apk" ]; then
declare -r dl_url=$(dl_apk "https://www.apkmirror.com/apk/tiktok-pte-ltd/tik-tok-including-musical-ly/tik-tok-including-musical-ly-${last_ver//./-}-release/" \
"APK</span>[^@]*@\([^#]*\)" \
"$base_apk")
echo "TikTok version: ${last_ver}"
echo "downloaded from: [APKMirror - TikTok]($dl_url)"
fi
}
# Downloading twitch
dl_twi() {
echo "Downloading Twitch"
local last_ver
last_ver="$version"
last_ver="${last_ver:-$(get_apk_vers "https://www.apkmirror.com/uploads/?appcategory=twitch" | get_largest_ver)}"
echo "Choosing version '${last_ver}'"
local base_apk="tv.twitch.android.app.apk"
if [ ! -f "$base_apk" ]; then
declare -r dl_url=$(dl_apk "https://www.apkmirror.com/apk/twitch-interactive-inc/twitch/twitch-${last_ver//./-}-release/" \
"APK</span>[^@]*@\([^#]*\)" \
"$base_apk")
echo "Twitch version: ${last_ver}"
echo "downloaded from: [APKMirror - Twitch]($dl_url)"
fi
}
## Main
for apk in "${!apks[@]}"; do
if [ ! -f $apk ]; then
echo "Downloading $apk"
version=$(jq -r ".\"$apk\"" <versions.json)
${apks[$apk]}
fi
done