mirror of
https://github.com/SinTan1729/ReVancedBuilder.git
synced 2024-12-27 05:08:35 -06:00
chg: Switched to APKPure
This commit is contained in:
parent
530786a7e8
commit
f27d503105
3 changed files with 152 additions and 139 deletions
|
@ -95,7 +95,7 @@ echo "$(date) | Starting check..."
|
||||||
|
|
||||||
if [[ $2 != buildonly ]]; then
|
if [[ $2 != buildonly ]]; then
|
||||||
# Create a backup of versions
|
# Create a backup of versions
|
||||||
[ -f versions.json ] && cp versions.json versions.json.old || touch versions.json
|
[ -f versions.json ] && cp versions.json versions.json.old || echo "{}" >versions.json
|
||||||
# Fetch all the dependencies
|
# Fetch all the dependencies
|
||||||
try=0
|
try=0
|
||||||
while :; do
|
while :; do
|
||||||
|
@ -141,14 +141,14 @@ if [[ $2 != buildonly ]]; then
|
||||||
if [[ $check_flag == false ]]; then
|
if [[ $check_flag == false ]]; then
|
||||||
echo "Nothing to update"
|
echo "Nothing to update"
|
||||||
else
|
else
|
||||||
"$SDIR/download_apkmirror.sh" "$WDIR" checkonly
|
"$SDIR/download_apk.sh" "$WDIR" checkonly
|
||||||
fi
|
fi
|
||||||
echo "--------------------"$'\n'"--------------------"
|
echo "--------------------"$'\n'"--------------------"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Download required apk files
|
# Download required apk files
|
||||||
"$SDIR/download_apkmirror.sh" "$WDIR"
|
"$SDIR/download_apk.sh" "$WDIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If the variables are NOT empty, call populate_patches with proper arguments
|
# If the variables are NOT empty, call populate_patches with proper arguments
|
||||||
|
|
149
download_apk.sh
Executable file
149
download_apk.sh
Executable file
|
@ -0,0 +1,149 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
declare -A apks
|
||||||
|
|
||||||
|
apks["com.google.android.youtube"]=dl_yt
|
||||||
|
apks["com.google.android.apps.youtube.music"]=dl_ytm
|
||||||
|
|
||||||
|
flag=$2
|
||||||
|
|
||||||
|
# Read the settings
|
||||||
|
source "$1/build_settings"
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
# Wget user agent
|
||||||
|
WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0"
|
||||||
|
|
||||||
|
# Wget function
|
||||||
|
req() { wget -nv -O "$2" --header="$WGET_HEADER" "$1"; }
|
||||||
|
|
||||||
|
# Returns true if $1 is less than $2
|
||||||
|
ver_less_than() {
|
||||||
|
[[ ${1:0:1} == "v" ]] && var1=${1:1} || var1=$1
|
||||||
|
[[ ${2:0:1} == "v" ]] && var2=${2:1} || var2=$2
|
||||||
|
[[ $(echo $var1$'\n'$var2 | sort -V | tail -n1) != $var1 ]] && echo true || echo false
|
||||||
|
}
|
||||||
|
|
||||||
|
# APKPure Download function
|
||||||
|
dl_apkpure() {
|
||||||
|
version="$1"
|
||||||
|
app="$2"
|
||||||
|
apkpure_appname="$3"
|
||||||
|
best_match="$(apkpure_best_match $version $app $apkpure_appname)"
|
||||||
|
|
||||||
|
if [[ "$version" == "$best_match" || "$version" == "latest" ]]; then
|
||||||
|
echo "Downloading version $best_match from APKPure"
|
||||||
|
else
|
||||||
|
echo "Unable to get version $version, downloading version $best_match instead"
|
||||||
|
fi
|
||||||
|
|
||||||
|
version="$best_match"
|
||||||
|
vers_code="$(req https://apkpure.com/$apkpure_appname/$app/versions - | htmlq --attribute data-dt-versioncode 'a[data-dt-version="'$version'"][data-dt-apkid^="b\/APK\/"]')"
|
||||||
|
url="https://d.apkpure.com/b/APK/$app?versionCode=$vers_code"
|
||||||
|
|
||||||
|
req "$url" "$app.apk"
|
||||||
|
echo "$url"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the best match even if the desired version isn't there
|
||||||
|
# OUtputs the latest version with supplied version 0
|
||||||
|
apkpure_best_match() {
|
||||||
|
version="$1"
|
||||||
|
app="$2"
|
||||||
|
apkpure_appname="$3"
|
||||||
|
|
||||||
|
vers_list=$(req https://apkpure.com/$apkpure_appname/$app/versions - | htmlq --attribute data-dt-version 'a[data-dt-apkid^="b\/APK\/"]')
|
||||||
|
if [[ "$version" == "latest" ]]; then
|
||||||
|
match="$(echo "$vers_list" | head -1)"
|
||||||
|
elif $(echo "$vers_list" | grep -q "$version"); then
|
||||||
|
match="$version"
|
||||||
|
else
|
||||||
|
match="$(echo "$vers_list"$'\n'"$version" | sort -V | grep -B 1 "$version" | head -1)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$match"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Downloading youtube
|
||||||
|
dl_yt() {
|
||||||
|
appname=com.google.android.youtube
|
||||||
|
version="$(apkpure_best_match "$version" $appname youtube)"
|
||||||
|
if [[ ! $(ver_less_than "$version_present" "$version") && -f $appname.apk ]]; then
|
||||||
|
echo "Version $version is already present"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $flag == checkonly ]]; then
|
||||||
|
echo "[checkonly] YouTube has an update ($version_present -> $version)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
echo "Downloading YouTube"
|
||||||
|
|
||||||
|
echo "Choosing version $version"
|
||||||
|
declare -r dl_url=$(dl_apkpure "$version" $appname youtube)
|
||||||
|
echo "YouTube version: $version"
|
||||||
|
echo "downloaded from: [APKMirror - YouTube]($dl_url)"
|
||||||
|
jq ".\"$apk\" = \"$version\"" versions.json >versions.json.tmp && mv versions.json.tmp versions.json
|
||||||
|
}
|
||||||
|
|
||||||
|
# Downloading youtube music
|
||||||
|
dl_ytm() {
|
||||||
|
appname=com.google.android.apps.youtube.music
|
||||||
|
version="$(apkpure_best_match "$version" $appname youtube-music)"
|
||||||
|
if [[ ! $(ver_less_than "$version_present" "$version") && -f $appname.apk ]]; then
|
||||||
|
echo "Version $version is already present"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $flag == checkonly ]]; then
|
||||||
|
echo "[checkonly] YouTube Music has an update ($version_present -> $version)"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
echo "Downloading YouTube Music"
|
||||||
|
|
||||||
|
echo "Choosing version '${version}'"
|
||||||
|
declare -r dl_url=$(dl_apkpure "$version" $appname youtube-music)
|
||||||
|
echo "YouTube Music version: $version"
|
||||||
|
echo "downloaded from: [APKMirror - YouTube Music]($dl_url)"
|
||||||
|
jq ".\"$apk\" = \"$version\"" versions.json >versions.json.tmp && mv versions.json.tmp versions.json
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get into the build directory
|
||||||
|
|
||||||
|
if [ -d "$1" ]; then
|
||||||
|
cd "$1"
|
||||||
|
else
|
||||||
|
echo "Working directory not provided"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Main
|
||||||
|
try=0
|
||||||
|
while :; do
|
||||||
|
try=$(($try + 1))
|
||||||
|
[ $try -gt 10 ] && echo "API error!" && exit 3
|
||||||
|
curl -X 'GET' 'https://releases.revanced.app/patches' -H 'accept: application/json' -o patches.json
|
||||||
|
cat patches.json | jq -e '.error' >/dev/null 2>&1 || break
|
||||||
|
echo "API failure, trying again. $((10 - $try)) tries left..."
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
|
for apk in "${!apks[@]}"; do
|
||||||
|
# Skip if app not specified for build
|
||||||
|
[[ "$apk" == "com.google.android.youtube" && "$YT_NONROOT" == false && "$YT_ROOT" == false ]] && continue
|
||||||
|
[[ "$apk" == "com.google.android.apps.youtube.music" && "$YTM_NONROOT" == false && "$YTM_ROOT" == false ]] && continue
|
||||||
|
|
||||||
|
echo "Checking $apk"
|
||||||
|
supported_vers="$(jq -r '.[].compatiblePackages[] | select(.name == "'$apk'") | .versions | last' patches.json)"
|
||||||
|
version=0
|
||||||
|
for vers in $supported_vers; do
|
||||||
|
[ $vers != "null" ] && [[ $(ver_less_than $vers $version) == true || $version == 0 ]] && version=$vers
|
||||||
|
done
|
||||||
|
|
||||||
|
version_present=$(jq -r ".\"$apk\"" versions.json)
|
||||||
|
[ -z "$version_present" ] && version_present=0
|
||||||
|
[[ "$version" == "0" ]] && version=latest
|
||||||
|
|
||||||
|
[[ $(ver_less_than $version_present $version) == true || ! -f $apk.apk || $2 == force ]] && ${apks[$apk]} || echo "Recommended version ($version_present) of "$apk" is already present"
|
||||||
|
done
|
|
@ -1,136 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
declare -A apks
|
|
||||||
|
|
||||||
apks["com.google.android.youtube"]=dl_yt
|
|
||||||
apks["com.google.android.apps.youtube.music"]=dl_ytm
|
|
||||||
|
|
||||||
flag=$2
|
|
||||||
|
|
||||||
# Read the settings
|
|
||||||
source "$1/build_settings"
|
|
||||||
|
|
||||||
## 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
|
|
||||||
# }
|
|
||||||
|
|
||||||
# Returns if $1 is less than $2
|
|
||||||
ver_less_than() {
|
|
||||||
[[ ${1:0:1} == "v" ]] && var1=${1:1} || var1=$1
|
|
||||||
[[ ${2:0:1} == "v" ]] && var2=${2:1} || var2=$2
|
|
||||||
[[ $(echo $var1$'\n'$var2 | sort -V | tail -n1) != $var1 ]] && echo true || echo false
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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() {
|
|
||||||
if [[ $flag == checkonly ]]; then
|
|
||||||
echo "[checkonly] YouTube has an update ($version_present -> $version)"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
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"
|
|
||||||
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)"
|
|
||||||
jq ".\"$apk\" = \"$last_ver\"" versions.json >versions.json.tmp && mv versions.json.tmp versions.json
|
|
||||||
}
|
|
||||||
|
|
||||||
# Architectures
|
|
||||||
ARM64_V8A="arm64-v8a"
|
|
||||||
ARM_V7A="arm-v7a"
|
|
||||||
|
|
||||||
# Downloading youtube music
|
|
||||||
dl_ytm() {
|
|
||||||
if [[ $flag == checkonly ]]; then
|
|
||||||
echo "[checkonly] YouTube Music has an update ($version_present -> $version)"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
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 [ "$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)"
|
|
||||||
jq ".\"$apk\" = \"$last_ver\"" versions.json >versions.json.tmp && mv versions.json.tmp versions.json
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get into the build directory
|
|
||||||
|
|
||||||
if [ -d "$1" ]; then
|
|
||||||
cd "$1"
|
|
||||||
else
|
|
||||||
echo "Working directory not provided"
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Main
|
|
||||||
try=0
|
|
||||||
while :; do
|
|
||||||
try=$(($try + 1))
|
|
||||||
[ $try -gt 10 ] && echo "API error!" && exit 3
|
|
||||||
curl -X 'GET' 'https://releases.revanced.app/patches' -H 'accept: application/json' -o patches.json
|
|
||||||
cat patches.json | jq -e '.error' >/dev/null 2>&1 || break
|
|
||||||
echo "API failure, trying again. $((10 - $try)) tries left..."
|
|
||||||
sleep 10
|
|
||||||
done
|
|
||||||
|
|
||||||
for apk in "${!apks[@]}"; do
|
|
||||||
# Skip if app not specified for build
|
|
||||||
[[ "$apk" == "com.google.android.youtube" && "$YT_NONROOT" == false && "$YT_ROOT" == false ]] && continue
|
|
||||||
[[ "$apk" == "com.google.android.apps.youtube.music" && "$YTM_NONROOT" == false && "$YTM_ROOT" == false ]] && continue
|
|
||||||
|
|
||||||
echo "Checking $apk"
|
|
||||||
supported_vers="$(jq -r '.[].compatiblePackages[] | select(.name == "'$apk'") | .versions | last' patches.json)"
|
|
||||||
version=0
|
|
||||||
for vers in $supported_vers; do
|
|
||||||
[ $vers != "null" ] && [[ $(ver_less_than $vers $version) == true || $version == 0 ]] && version=$vers
|
|
||||||
done
|
|
||||||
version_present=$(jq -r ".\"$apk\"" versions.json)
|
|
||||||
[ -z "$version_present" ] && version_present=0
|
|
||||||
[[ $(ver_less_than $version_present $version) == true || ! -f $apk.apk || $2 == force ]] && ${apks[$apk]} || echo "Recommended version ($version_present) of "$apk" is already present"
|
|
||||||
done
|
|
Loading…
Reference in a new issue