Skip to content

Instantly share code, notes, and snippets.

@Leo40Git
Last active January 28, 2023 09:40
Show Gist options
  • Save Leo40Git/a952b8bf0f2b45a1a6875ded878cf6c4 to your computer and use it in GitHub Desktop.
Save Leo40Git/a952b8bf0f2b45a1a6875ded878cf6c4 to your computer and use it in GitHub Desktop.
YouTube ReVanced Build Script
@echo off
setlocal
pushd %~dp0
set DEPLOY=1
set ADB=platform-tools\adb.exe
set DEVICE_NAME=988e9048305953523230
set JAVA=jre\bin\java.exe
set CLI_JAR=revanced-cli-all.jar
set PATCH_BUNDLE_LIST=patch_bundles.txt
set INPUT_APK=youtube.apk
set OUTPUT_APK=revanced.apk
set MERGE_FILE_LIST=merge_files.txt
set PATCH_LIST=patches.txt
call :get_patch_bundle_args
if errorlevel 1 goto end_error
set dry_run=0
set target_root=0
:args_loop
if "%~1"=="" goto args_loop_end
if "%~1"=="/?" goto help
if /i "%~1"=="/help" goto help
if /i "%~1"=="/l" goto list_patches
if /i "%~1"=="/list" goto list_patches
if /i "%~1"=="/d" set dry_run=1
if /i "%~1"=="/dry_run" set dry_run=1
if /i "%~1"=="/r" set target_root=1
if /i "%~1"=="/target_root" set target_root=1
shift /1
goto args_loop
:help
echo %~0 [/help] [/list] [/dry_run] [/target_root]
echo /help or /? - show this help message and exit
echo /list or /l - list available patches
echo /dry_run or /d - don't actually invoke CLI/ADB, echo invocations that would've happened
echo /target_root or /r - build for root (mounting on top of stock YouTube app)
goto end
:list_patches
if not exist %INPUT_APK% goto no_input_apk
%JAVA% -jar %CLI_JAR% -a %INPUT_APK%%patch_bundle_args% --list
goto end
:args_loop_end
if not exist %INPUT_APK% goto no_input_apk
if not exist %PATCH_LIST% goto no_patch_list
if %DEPLOY%==0 goto skip_adb_check
if exist %ADB% goto skip_adb_check
echo ADB executable %ADB% does not exist!
goto end_error
:skip_adb_check
call :get_merge_args
if errorlevel 1 goto end_error
call :get_patch_args
if errorlevel 1 goto end_error
set "deploy_args="
if %DEPLOY%==1 (
echo Starting ADB server!
call :invoke "%ADB% shell exit"
set "deploy_args= -d %DEVICE_NAME%"
)
echo Running ReVanced CLI!
if %target_root%==1 (
call :invoke "%JAVA% -jar %CLI_JAR% -a %INPUT_APK% -o %OUTPUT_APK%%patch_bundle_args%%merge_args%%deploy_args% --mount --exclusive%patch_args%"
) else (
call :invoke "%JAVA% -jar %CLI_JAR% -a %INPUT_APK% -o %OUTPUT_APK%%patch_bundle_args%%merge_args%%deploy_args% --exclusive -i microg-support%patch_args%"
)
if %DEPLOY%==1 (
echo Stopping ADB server!
call :invoke "%ADB% kill-server"
)
pause
goto end
:get_patch_bundle_args
if not exist %PATCH_BUNDLE_LIST% goto no_patch_bundle_list
for /f %%G in (%PATCH_BUNDLE_LIST%) do (
if not exist %%G (
echo Patch bundle %%G does not exist!
exit /b 1
)
call :append patch_bundle_args " -b %%G"
)
exit /b 0
:no_patch_bundle_list
echo Patch bundle list %PATCH_BUNDLE_LIST% does not exist!
echo Please create this file, then list all of your patch bundles in it.
exit /b 1
:no_input_apk
echo Input APK %INPUT_APK% does not exist!
echo Please download a YouTube APK with a supported version to this location.
goto end_error
:no_patch_list
echo Patch list %PATCH_LIST% does not exist!
echo Please create this file, then list all of your desired patches in it.
goto end_error
:get_merge_args
if not exist %MERGE_FILE_LIST% (
set merge_args=""
exit /b 0
)
for /f %%G in (%MERGE_FILE_LIST%) do (
if not exist %%G (
echo Merge file "%%G" does not exist!
echo Either create it or remove it from your merge file list at "%MERGE_FILE_LIST%", then try again.
exit /b 1
)
call :append merge_args " -m %%G"
)
exit /b 0
:get_patch_args
for /f %%G in (%PATCH_LIST%) do (
set _implicit_patch_specified=0
if /i "%%G"=="microg-support" set _implicit_patch_specified=1
if "%_implicit_patch_specified%"=="1" (
echo Patch "%%G" should not be explicitly included!
echo Remove this patch from the patch list at "%PATCH_LIST%", then try again.
exit /b 1
)
call :append patch_args " -i %%G"
)
exit /b 0
:append varname str
call set "%~1=%%%~1%%%~2"
exit /b
:invoke cmd
if %dry_run%==1 (echo ^>%~1) else (%~1)
exit /b
:end
popd
endlocal
exit /b 0
:end_error
pause
popd
endlocal
exit /b 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment