build youtube music

does not crash ;)


Former-commit-id: b2ec362e94f4aef312e308f274345e2726e0209a
This commit is contained in:
j-hc 2022-07-07 20:14:02 +03:00
parent 8541d597dd
commit 1a6339042b
9 changed files with 232 additions and 121 deletions

View File

@ -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

4
.gitignore vendored
View File

@ -2,7 +2,9 @@
*.apk
*.zip
*.keystore
revanced-cache
*.so
/revanced-cache
/temp
build.log
.v*

View File

@ -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
```

View File

@ -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</span>[^@]*@\([^#]*\).*;\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}'"

45
build.sh Executable file
View File

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

View File

@ -0,0 +1 @@
# utils

View File

@ -1,6 +1 @@
id=ytrvi
name=YouTube ReVanced
version=v17.25.34
versionCode=1
author=j-hc
description=mounts base.apk for YouTube ReVanced
# utils

View File

@ -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
# <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
fi
fi
# utils

170
utils.sh Executable file
View File

@ -0,0 +1,170 @@
#!/bin/bash
YT_PATCHER_ARGS="-e microg-support -e premium-heading"
MUSIC_PATCHER_ARGS="-e microg-support"
MODULE_TEMPLATE_DIR="revanced-magisk"
TEMP_DIR="temp"
WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
get_prebuilts() {
echo "Getting prebuilts"
mkdir -p "$TEMP_DIR"
RV_CLI_URL=$(req https://api.github.com/repos/revanced/revanced-cli/releases/latest - | tr -d ' ' | sed -n 's/.*"browser_download_url":"\(.*jar\)".*/\1/p')
RV_CLI_JAR="${TEMP_DIR}/$(echo "$RV_CLI_URL" | awk -F/ '{ print $NF }')"
log "CLI: ${RV_CLI_JAR#"$TEMP_DIR/"}"
RV_INTEGRATIONS_URL=$(req https://api.github.com/repos/revanced/revanced-integrations/releases/latest - | tr -d ' ' | sed -n 's/.*"browser_download_url":"\(.*apk\)".*/\1/p')
RV_INTEGRATIONS_APK="${TEMP_DIR}/$(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 "Integrations: ${RV_INTEGRATIONS_APK#"$TEMP_DIR/"}"
RV_PATCHES_URL=$(req https://api.github.com/repos/revanced/revanced-patches/releases/latest - | tr -d ' ' | sed -n 's/.*"browser_download_url":"\(.*jar\)".*/\1/p')
RV_PATCHES_JAR="${TEMP_DIR}/$(echo "$RV_PATCHES_URL" | awk -F/ '{ print $NF }')"
log "Patches: ${RV_PATCHES_JAR#"$TEMP_DIR/"}"
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"
}
reset_template() {
echo "# utils" >"${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</span>[^@]*@\([^#]*\).*;\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</div>[^@]*@\([^"]*\).*;\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"
}