From 1a6339042be97b7416b9adf2a2da84043753e2d3 Mon Sep 17 00:00:00 2001 From: j-hc Date: Thu, 7 Jul 2022 20:14:02 +0300 Subject: [PATCH] build youtube music does not crash ;) Former-commit-id: b2ec362e94f4aef312e308f274345e2726e0209a --- .github/workflows/build.yml | 20 ++-- .gitignore | 4 +- README.md | 4 +- build-module.sh | 84 --------------- build.sh | 45 ++++++++ revanced-magisk/common/install.sh | 1 + revanced-magisk/module.prop | 7 +- revanced-magisk/service.sh | 18 +--- utils.sh | 170 ++++++++++++++++++++++++++++++ 9 files changed, 232 insertions(+), 121 deletions(-) delete mode 100755 build-module.sh create mode 100755 build.sh create mode 100755 utils.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8e40e74..c9defbf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,27 +10,25 @@ jobs: java-version: "17" - name: Checkout uses: actions/checkout@v3 - - run: ./build-module.sh + - run: ./build.sh all - id: get_output run: | - FILE=$(find . -maxdepth 1 -name "revanced-magisk-*.zip" -printf '%P') - echo ::set-output name=OUTPUT::$FILE - echo ::set-output name=VERSION::$(echo $FILE | sed -n 's/.*revanced-magisk-\(.*\)\.zip.*/\1/p') + YT_FILE=$(find . -maxdepth 1 -name "yt-revanced-magisk-*.zip" -printf '%P') + echo ::set-output name=YT_OUTPUT::$YT_FILE BUILD_LOG=$(cat build.log) BUILD_LOG="${BUILD_LOG//'%'/'%25'}" BUILD_LOG="${BUILD_LOG//$'\n'/'%0A'}" BUILD_LOG="${BUILD_LOG//$'\r'/'%0D'}" echo ::set-output name=BUILD_LOG::$BUILD_LOG - echo "::set-output name=DATE::$(date +'%m-%d')" + echo ::set-output name=DATE::$(date +'%Y-%m-%d') shell: bash - - name: Upload release + - name: Upload modules to release uses: svenstaro/upload-release-action@v2 with: body: ${{ steps.get_output.outputs.BUILD_LOG }} repo_token: ${{ secrets.GITHUB_TOKEN }} - file: ${{ steps.get_output.outputs.OUTPUT }} - asset_name: ${{ steps.get_output.outputs.OUTPUT }} - release_name: ${{ steps.get_output.outputs.OUTPUT }} - tag: ${{ steps.get_output.outputs.VERSION }}-${{ steps.get_output.outputs.DATE }} - overwrite: false + file: ./*.zip + release_name: ${{ steps.get_output.outputs.YT_OUTPUT }} + tag: ${{ steps.get_output.outputs.DATE }} + file_glob: true diff --git a/.gitignore b/.gitignore index c10a7ec..6ed22cd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,9 @@ *.apk *.zip *.keystore -revanced-cache +*.so +/revanced-cache +/temp build.log .v* diff --git a/README.md b/README.md index 78ed5ee..a316220 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ You will need to install the stock YouTube app matching with the module version You can go grab the split APKs from APKMirror (the bundle, not the apk or it will crash) -You can get the [latest CI release](https://github.com/j-hc/revanced-magisk-module/releases) if you do not want to build yourself. +You can get the [latest CI release](https://github.com/j-hc/revanced-magisk-module/releases) if you do not wish to build yourself. # Building the Magisk Module ```bash -$ ./build-module.sh +$ ./build.sh all ``` diff --git a/build-module.sh b/build-module.sh deleted file mode 100755 index e8fa787..0000000 --- a/build-module.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash - -set -e - -if [ "$1" == "clean" ]; then - rm -r revanced-cache *.jar *.apk *.zip *.keystore build.log -fi - -PATCHER_ARGS="-e microg-support -e premium-heading" - -WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0" -PATCHED_APK="revanced-base.apk" - -function req() { - wget -nv -O "$2" --header="$WGET_HEADER" $1 -} - -# 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')" - log "downloaded from: $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 "$2" -} - -function dl_if_dne() { - if [ ! -f "$1" ]; then - echo -e "\nGetting '$1' from '$2'" - req "$2" "$1" - fi -} - -function log() { - echo -e "$1" >>build.log -} - ->build.log - -log "$(date +'%Y-%m-%d')\n" - -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" - -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 }') -log $RV_CLI_JAR - -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]}') -log $RV_INTEGRATIONS_APK - -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 }') -log $RV_PATCHES_JAR - -dl_if_dne $RV_CLI_JAR $RV_CLI_URL -dl_if_dne $RV_INTEGRATIONS_APK $RV_INTEGRATIONS_URL -dl_if_dne $RV_PATCHES_JAR $RV_PATCHES_URL - -# This only finds the supported versions of some random patch wrt the first occurance of the string but that's fine -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}'" -log "\nYouTube version: ${LAST_VER}" -BASE_APK="base-v${LAST_VER}.apk" - -if [ ! -f "$BASE_APK" ]; then - DL_OUTPUT="yt-stock-v${LAST_VER}.zip" - dl_yt "https://www.apkmirror.com/apk/google-inc/youtube/youtube-${LAST_VER//./-}-release/" $DL_OUTPUT - unzip -p $DL_OUTPUT base.apk >$BASE_APK -fi - -java -jar $RV_CLI_JAR -a $BASE_APK -c -o $PATCHED_APK -b $RV_PATCHES_JAR -m $RV_INTEGRATIONS_APK $PATCHER_ARGS -mv -f $PATCHED_APK ./revanced-magisk/${PATCHED_APK} - -echo "Creating the magisk module..." -OUTPUT="revanced-magisk-v${LAST_VER}.zip" -sed -i "s/version=v.*$/version=v${LAST_VER}/g" ./revanced-magisk/module.prop - -cd revanced-magisk -zip -r ../$OUTPUT . - -echo "Created the magisk module '${OUTPUT}'" diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..3ba23de --- /dev/null +++ b/build.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +set -e + +source utils.sh + +BUILD_YT=false +BUILD_MUSIC=false + +print_usage() { + echo -e "Usage:\n${0} youtube|music|all|clean" +} + +if [ -z "$1" ]; then + print_usage + exit 0 +elif [ "$1" == "clean" ]; then + rm -rf ./temp ./revanced-cache ./*.jar ./*.apk ./*.zip ./*.keystore build.log + reset_template + exit 0 +elif [ "$1" == "all" ]; then + BUILD_YT=true + BUILD_MUSIC=true +elif [ "$1" == "youtube" ]; then + BUILD_YT=true +elif [ "$1" == "music" ]; then + BUILD_MUSIC=true +else + print_usage + exit 1 +fi + +>build.log +log "$(date +'%Y-%m-%d')\n" +get_prebuilts + +if $BUILD_YT; then + build_yt +fi + +if $BUILD_MUSIC; then + build_music +fi + +echo "Done" diff --git a/revanced-magisk/common/install.sh b/revanced-magisk/common/install.sh index e69de29..06588bf 100755 --- a/revanced-magisk/common/install.sh +++ b/revanced-magisk/common/install.sh @@ -0,0 +1 @@ +# utils diff --git a/revanced-magisk/module.prop b/revanced-magisk/module.prop index 9f7570a..06588bf 100755 --- a/revanced-magisk/module.prop +++ b/revanced-magisk/module.prop @@ -1,6 +1 @@ -id=ytrvi -name=YouTube ReVanced -version=v17.25.34 -versionCode=1 -author=j-hc -description=mounts base.apk for YouTube ReVanced \ No newline at end of file +# utils diff --git a/revanced-magisk/service.sh b/revanced-magisk/service.sh index ed09a61..06588bf 100644 --- a/revanced-magisk/service.sh +++ b/revanced-magisk/service.sh @@ -1,17 +1 @@ -while [ "$(getprop sys.boot_completed)" != 1 ]; do - sleep 1 -done - -# >A11 -YTPATH=$(readlink -f /data/app/*/com.google.android.youtube*/oat | sed 's/\/oat//g') - -if [ ! -z "$YTPATH" ]; then - su -c mount $MODDIR/revanced-base.apk $YTPATH/base.apk -else - # "${MODULE_TEMPLATE_DIR}/common/install.sh" + echo "# utils" >"${MODULE_TEMPLATE_DIR}/service.sh" + echo "# utils" >"${MODULE_TEMPLATE_DIR}/module.prop" + rm -f "${MODULE_TEMPLATE_DIR}/base.apk" "${MODULE_TEMPLATE_DIR}/libjsc.so" +} + +req() { + wget -nv -O "$2" --header="$WGET_HEADER" "$1" +} + +dl_if_dne() { + if [ ! -f "$1" ]; then + echo -e "\nGetting '$1' from '$2'" + req "$2" "$1" + fi +} + +log() { + echo -e "$1" >>build.log +} + +# yes this is how i download the stock yt apk from apkmirror +dl_yt() { + echo "Downloading YouTube" + local url="https://www.apkmirror.com/apk/google-inc/youtube/youtube-${1//./-}-release/" + url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's/href="/@/g; s;.*BUNDLE[^@]*@\([^#]*\).*;\1;p')" + log "\nYouTube version: $1\ndownloaded from: [APKMirror]($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" "$2" +} + +dl_music() { + echo "Downloading YouTube Music" + local url="https://www.apkmirror.com/apk/google-inc/youtube-music/youtube-music-${1//./-}-release/" + url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's/href="/@/g; s;.*arm64-v8a[^@]*@\([^"]*\).*;\1;p')" + log "\nYouTube Music version: $1\ndownloaded from: [APKMirror]($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" "$2" +} + +build_yt() { + echo "Patching YouTube" + reset_template + # This only finds the supported versions of some random patch wrt the first occurance of the string but that's fine + local supported_versions last_ver yt_base_apk dl_output yt_patched_apk output + 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 YouTube patch: $supported_versions" + last_ver=$(echo "$supported_versions" | awk -F, '{ print $NF }') + echo "Choosing '${last_ver}'" + yt_base_apk="${TEMP_DIR}/base-v${last_ver}.apk" + + if [ ! -f "$yt_base_apk" ]; then + dl_output="${TEMP_DIR}/yt-stock-v${last_ver}.zip" + dl_yt "$last_ver" "$dl_output" + unzip -p "$dl_output" "base.apk" >"$yt_base_apk" + fi + + yt_patched_apk="${TEMP_DIR}/yt-revanced-base.apk" + java -jar $RV_CLI_JAR -a $yt_base_apk -c -o $yt_patched_apk -b $RV_PATCHES_JAR -m $RV_INTEGRATIONS_APK $YT_PATCHER_ARGS + mv -f "$yt_patched_apk" "${MODULE_TEMPLATE_DIR}/base.apk" + + echo "Creating the magisk module for YouTube..." + output="yt-revanced-magisk-v${last_ver}-noarch.zip" + + service_sh "com.google.android.youtube" + yt_module_prop "$last_ver" + + cd "$MODULE_TEMPLATE_DIR" || return + zip -r "../$output" . + cd .. + + echo "Built YouTube: '${output}'" +} + +build_music() { + echo "Patching YouTube Music" + reset_template + local supported_versions last_ver music_apk music_patched_apk output + # This only finds the supported versions of some random patch wrt the first occurance of the string but that's fine + supported_versions=$(unzip -p "$RV_PATCHES_JAR" | strings -n 7 -s , | sed -rn 's/.*music,versions,(([0-9.]*,*)*),Lk.*/\1/p') + echo "Supported versions of the Music patch: $supported_versions" + last_ver=$(echo "$supported_versions" | awk -F, '{ print $NF }') + echo "Choosing '${last_ver}'" + music_apk="${TEMP_DIR}/music-stock-v${last_ver}.apk" + + if [ ! -f "$music_apk" ]; then + dl_music "$last_ver" "$music_apk" + fi + + unzip -p "$music_apk" "lib/arm64-v8a/libjsc.so" >"${MODULE_TEMPLATE_DIR}/libjsc.so" + + music_patched_apk="${TEMP_DIR}/music-revanced-base.apk" + java -jar $RV_CLI_JAR -a $music_apk -c -o $music_patched_apk -b $RV_PATCHES_JAR -m $RV_INTEGRATIONS_APK $MUSIC_PATCHER_ARGS + mv -f "$music_patched_apk" "${MODULE_TEMPLATE_DIR}/base.apk" + + echo "Creating the magisk module for YouTube Music" + output="music-revanced-magisk-v${last_ver}-arm64-v8a.zip" + + service_sh "com.google.android.apps.youtube.music" + music_module_prop "$last_ver" + echo 'YTPATH=$(pm path com.google.android.apps.youtube.music | grep base | sed "s/package://g; s/\/base.apk//g") +cp_ch -n $MODPATH/libjsc.so $YTPATH/lib/arm64 0755' >"${MODULE_TEMPLATE_DIR}/common/install.sh" + + cd "$MODULE_TEMPLATE_DIR" || return + zip -r "../$output" . + cd .. + + echo "Built Music '${output}'" +} + +service_sh() { + echo 'while [ "$(getprop sys.boot_completed)" != 1 ]; do + sleep 1 +done + +YTPATH=$(pm path PACKAGE | grep base | sed "s/package://g; s/\/base.apk//g") +if [ -n "$YTPATH" ]; then + su -c mount $MODDIR/base.apk $YTPATH/base.apk +fi' | sed "s/PACKAGE/$1/g" >"${MODULE_TEMPLATE_DIR}/service.sh" +} + +yt_module_prop() { + echo "id=ytrv-magisk +name=YouTube ReVanced +version=v${1} +versionCode=1 +author=j-hc +description=mounts base.apk for YouTube ReVanced" >"${MODULE_TEMPLATE_DIR}/module.prop" +} + +music_module_prop() { + echo "id=ytmusicrv-magisk +name=YouTube Music ReVanced +version=v${1} +versionCode=1 +author=j-hc +description=mounts base.apk for YouTube Music ReVanced" >"${MODULE_TEMPLATE_DIR}/module.prop" +}