From 15f2442fe3c68a2cf45e0e1cfad3a1154bb2a9af Mon Sep 17 00:00:00 2001 From: j-hc Date: Thu, 30 Jun 2022 19:23:10 +0300 Subject: [PATCH] Fully automate youtube base apk download Former-commit-id: 7d102024c9372bfdc4ae1148f0eb680ea223a6d7 --- .github/workflows/build.yml | 2 +- .gitignore | 3 +- README.md | 25 +++++++----- base-v17.24.34.apk.REMOVED.git-id | 1 - build-module.sh | 68 ++++++++++++++++++------------- 5 files changed, 55 insertions(+), 44 deletions(-) delete mode 100644 base-v17.24.34.apk.REMOVED.git-id diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34c542c..50ab4ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: git clone "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" . ./build-module.sh - id: get_output_name - run: echo ::set-output name=OUTPUT::$(cat build-module.sh | sed -n 's/.*OUTPUT="\(.*\)".*/\1/p') + run: echo ::set-output name=OUTPUT::$(find . -maxdepth 1 -name "revanced-magisk-*.zip" -printf '%P') shell: bash - name: Upload release uses: svenstaro/upload-release-action@2.3.0 diff --git a/.gitignore b/.gitignore index 7126612..9389b3e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ *.zip *.keystore -!base-v17.24.34.apk -.v* \ No newline at end of file +.v* diff --git a/README.md b/README.md index 78e4215..0e6359f 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@ +# YouTube ReVanced Magisk Module + +(unaffiliated what-so-ever) + +This repo includes a simple script that +downloads all the latest version of necessary prebuilt revanced tools and the stock YouTube APK from APKMirror and creates a magisk module +1 +You will need to install the stock YouTube app matching with the module version on your phone using [SAI](https://play.google.com/store/apps/details?id=com.aefyr.sai&hl=tr&gl=US) with the split APKs +You can go grab the split APKs from APKMirror (the bundle, not the apk or it will crash) +1 + +You can get the [latest CI release](https://github.com/j-hc/revanced-magisk-module/releases/tag/main) if you do not want to build yourself. + + # Building the Magisk Module -This repo includes the base.apk of the stock YouTube app (v17.24.34) and a simple script that -download all the latest version of necessary prebuilt revanced tools and creates a magisk module - -You will need to install the stock YouTube app (v17.24.34) on your phone using [SAI](https://play.google.com/store/apps/details?id=com.aefyr.sai&hl=tr&gl=US) through split apks -You can go to apkmirror to grab the split apks (the bundle, not the apk or it will crash) - - -You can download the [latest CI release](https://github.com/j-hc/revanced-magisk-module/releases/tag/main) if you do not want to build yourself. - -# Usage - ```bash $ ./build-module.sh ``` diff --git a/base-v17.24.34.apk.REMOVED.git-id b/base-v17.24.34.apk.REMOVED.git-id deleted file mode 100644 index 7db1a73..0000000 --- a/base-v17.24.34.apk.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -dc5ef207bb934e9f91ce06b8d00ddde9738be756 \ No newline at end of file diff --git a/build-module.sh b/build-module.sh index 8fdb190..2b18314 100755 --- a/build-module.sh +++ b/build-module.sh @@ -1,52 +1,62 @@ #!/bin/bash -echo "All necessary files (revanced cli, patches and integrations) will be downloaded, Youtube apk will be patched and zipped into a Magisk module" +set -e -# CURRENT VERSION -YTBASE="base-v17.24.34.apk" -OUTPUT="revanced-magisk-v17.24.34.zip" +echo "All necessary files (revanced cli, patches and integrations, stock YouTube apk) will be downloaded, Youtube apk will be patched and zipped into a Magisk module" -function dl() { - wget -q --show-progress $1 || { - echo "Download Failed" - exit 1 - } +WGET_HEADER='User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0' + +function req() { + wget -nv --show-progress -O $2 --header="$WGET_HEADER" $1 } -if [[ ! -f "$YTBASE" ]]; then - echo "$YTBASE not found in the current directory" -fi +# yes this is how i download the stock yt apk from apkmirror +function dl_yt() { + URL="https://www.apkmirror.com$(req $1 - | tr '\n' ' ' | sed -n 's/href="/@/g; s;.*BUNDLE[^@]*@\([^#]*\).*;\1;p')" + 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 $2 +} -RV_CLI_URL=$(wget -nv -O - https://api.github.com/repos/revanced/revanced-cli/releases/latest | sed -n 's/.*"browser_download_url": "\(.*jar\)".*/\1/p') +RV_CLI_URL=$(req https://api.github.com/repos/revanced/revanced-cli/releases/latest - | sed -n 's/.*"browser_download_url": "\(.*jar\)".*/\1/p') RV_CLI_JAR=$(echo $RV_CLI_URL | awk -F/ '{ print $NF }') -RV_INTEGRATIONS_URL=$(wget -nv -O - https://api.github.com/repos/revanced/revanced-integrations/releases/latest | sed -n 's/.*"browser_download_url": "\(.*apk\)".*/\1/p') -RV_INTEGRATIONS_APK=$(echo $RV_INTEGRATIONS_URL | awk -F/ '{ print $NF }') +RV_INTEGRATIONS_URL=$(req https://api.github.com/repos/revanced/revanced-integrations/releases/latest - | sed -n 's/.*"browser_download_url": "\(.*apk\)".*/\1/p') +RV_INTEGRATIONS_APK=$(echo $RV_INTEGRATIONS_URL | awk '{n=split($0, arr, "/"); printf "%s-%s.apk", substr(arr[n], 0, length(arr[n]) - 4), arr[n-1]}') -RV_PATCHES_URL=$(wget -nv -O - https://api.github.com/repos/revanced/revanced-patches/releases/latest | sed -n 's/.*"browser_download_url": "\(.*jar\)".*/\1/p') +RV_PATCHES_URL=$(req https://api.github.com/repos/revanced/revanced-patches/releases/latest - | sed -n 's/.*"browser_download_url": "\(.*jar\)".*/\1/p') RV_PATCHES_JAR=$(echo $RV_PATCHES_URL | awk -F/ '{ print $NF }') -if [[ ! -f "$RV_CLI_JAR" ]]; then - dl $RV_CLI_URL +if [ ! -f $RV_CLI_JAR ]; then + req $RV_CLI_URL $RV_CLI_JAR fi -if [[ ! -f "$RV_INTEGRATIONS_APK" ]]; then - dl $RV_INTEGRATIONS_URL +if [ ! -f $RV_INTEGRATIONS_APK ]; then + req $RV_INTEGRATIONS_URL $RV_INTEGRATIONS_APK fi -if [[ ! -f "$RV_PATCHES_JAR" ]]; then - dl $RV_PATCHES_URL +if [ ! -f $RV_PATCHES_JAR ]; then + req $RV_PATCHES_URL $RV_PATCHES_JAR fi -java -jar $RV_CLI_JAR -a $YTBASE -c -o revanced-base.apk -b $RV_PATCHES_JAR -e microg-support -m $RV_INTEGRATIONS_APK || - { - echo "Building failed" - exit 1 - } +SUPPORTED_VERSIONS=$(unzip -p $RV_PATCHES_JAR | strings -n 8 -s , | sed -rn 's/.*youtube,versions,(([0-9.]*,*)*),Lk.*/\1/p') +echo "Supported versions of the patch: $SUPPORTED_VERSIONS" +LAST_VER=$(echo $SUPPORTED_VERSIONS | awk -F, '{ print $NF }') +echo "Choosing $LAST_VER" +BASE_APK="base-v$LAST_VER.apk" -mv -f revanced-base.apk ./revanced-magisk/revanced-base.apk +if [ ! -f $BASE_APK ]; then + echo "$BASE_APK could not be found, will be downloaded from apkmirror.." + dl_yt "https://www.apkmirror.com/apk/google-inc/youtube/youtube-${LAST_VER//./-}-release/" yt-stock-v$LAST_VER.zip + unzip -p yt-stock-v$LAST_VER.zip base.apk >$BASE_APK +fi + +java -jar $RV_CLI_JAR -a $BASE_APK -c -o revanced-base.apk -b $RV_PATCHES_JAR -e microg-support -m $RV_INTEGRATIONS_APK +mv -f revanced-base.apk ./MMT-Extended/revanced-base.apk echo "Creating the magisk module..." +OUTPUT="revanced-magisk-v$LAST_VER.zip" +sed -i "s/version=v.*$/version=v$LAST_VER/g" ./MMT-Extended/module.prop -cd revanced-magisk +cd MMT-Extended zip -r ../$OUTPUT . echo "Created the magisk module '$OUTPUT'"