n0k0m3 / revanced-build-template

Github Template for building Revanced
GNU General Public License v3.0
138 stars 151 forks source link

Download from APKMirror #54

Closed Chicos123 closed 2 years ago

Chicos123 commented 2 years ago

Saw the issue about cloudflare rate limiting #14

Try this apkmirror download script. Looks like they solved the problem. https://github.com/j-hc/revanced-magisk-module/blob/main/utils.sh

The code below is simply copied

[Source from - https://github.com/j-hc/revanced-magisk-module]

WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"

req() { wget -nv -O "$2" --header="$WGET_HEADER" "$1"; }

get_apk_vers() { req "$1" - | sed -n 's;.*Version:</span><span class="infoSlide-value">\(.*\) </span>.*;\1;p'; }

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
}

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"
}

dl_youtube() {
    echo "Downloading YouTube"
    local last_ver
    last_ver="17.29.34"
    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
}

Workflow ReVanced Test Build runs https://github.com/Chicos123/revanced-build-template/runs/7743417099

n0k0m3 commented 2 years ago

Can you make a PR for this?

On Tue, Aug 9, 2022 at 5:18 AM Chico @.***> wrote:

Saw the issue about cloudflare rate limiting #14 https://github.com/n0k0m3/revanced-build-template/issues/14

Try this apkmirror download script. Looks like they solved the problem. https://github.com/j-hc/revanced-magisk-module/blob/main/utils.sh

The code below is simply copied

[Source from - https://github.com/j-hc/revanced-magisk-module] WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"

req() { wget -nv -O "$2" --header="$WGET_HEADER" "$1"; }

get_apk_vers() { req "$1" - | sed -n 's;.Version:(.) .*;\1;p'; }

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" }

dl_youtube() { echo "Downloading YouTube" local last_ver last_ver="17.29.34" last_ver="${last_ver:-$(get_apk_vers "https://www.apkmirror.com/apk/google-inc/youtube/" | head -n 1)}"

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[^@]@([^#])" \ "$base_apk") echo "YouTube version: ${last_ver}" echo "downloaded from: APKMirror - YouTube" fi }

— Reply to this email directly, view it on GitHub https://github.com/n0k0m3/revanced-build-template/issues/54, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACTLJ4UEKV2HOIATPWOLM7TVYIPABANCNFSM56ABFRDA . You are receiving this because you are subscribed to this thread.Message ID: @.***>