Files
repos_scripts/revanced
2024-05-14 16:45:28 +05:30

109 lines
5.8 KiB
Bash
Executable File

#!/bin/sh
info() {
printf "\033[1;35m=> \033[1;${2:-36}m%s\033[0m\n" "$1"
}
download_apk() {
[ -z "$1" ] && info "[ $app ][ v$version ] Version doesn't Exist!" "31" && exit 1
info "[ $app ][ v$version ] Fetching Download page.."
final_page=$(curl -s "${apk_provider_url}${1}" --tlsv1.3 -A "$agent" | sed -nE 's|.*href="(.*\/download\/[^"]*)".*|\1|p' | sed 's|&|\&|g')
[ -z "$final_page" ] && info "[ $app ][ v$version ] Unable to Fetch Download Page.." "31" && exit 1
info "[ $app ][ v$version ] Fetching Download URL.."
download_url=$(curl -s "${apk_provider_url}${final_page}" --tlsv1.3 -A "$agent" | sed -nE 's|.*href="(.*download.php[^"]*)".*|\1|p' | sed 's|&|\&|g')
[ -z "$download_url" ] && info "[ $app ][ v$version ] Unable to Fetch Download URL.." "31" && exit 1
info "[ $app ][ v$version ] Downloading App.."
aria2c -x16 -s16 "${apk_provider_url}${download_url}" --user-agent="$agent" -d "$tmp_dir" -o "$app-$version.apk" --allow-overwrite=true --check-certificate=false --download-result=hide --summary-interval=0 && info "[ $app ][ v$version ] App Downloaded.." && return 0
info "[ $app ][ v$version ] Unable to Download.." "31" && exit 1
}
download_keystore() {
RV_KEYSTORE_URL="https://raw.githubusercontent.com/CoolnsX/revanced-build/master/yt-revanced.keystore"
RV_KEYSTORE="yt-revanced.keystore"
keystore="--keystore $tmp_dir/$RV_KEYSTORE"
[ ! -f "$tmp_dir/$RV_KEYSTORE" ] && curl -s "$RV_KEYSTORE_URL" -o "$tmp_dir/$RV_KEYSTORE" && info "Downloaded Keystore file in $tmp_dir" "32" && return 0
[ ! -f "$tmp_dir/$RV_KEYSTORE" ] && keystore=""
}
tmp_dir="${TMPDIR:-/tmp}/revanced"
agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
apk_provider_url="https://www.apkmirror.com"
date=$(date +%F)
rv_cli="cli-$date.jar"
rv_patch="patches-$date.jar"
rv_inte="integrations-$date.apk"
keystore=""
#check if directory is there
[ -d "$tmp_dir" ] || mkdir "$tmp_dir"
#pre-requisite
if [ ! -f "$tmp_dir/$rv_cli.aria2" ] && [ ! -f "$tmp_dir/$rv_patch.aria2" ] && [ ! -f "$tmp_dir/$rv_inte.aria2" ] && [ -f "$tmp_dir/$rv_cli" ] && [ -f "$tmp_dir/$rv_patch" ] && [ -f "$tmp_dir/$rv_inte" ]; then
info "revanced-cli,revanced-patches,revanced-integrations already downloaded" "32"
else
rm -f "$tmp_dir"/*.aria2
info "Downloading revanced-cli,revanced-patches,revanced-integrations.."
printf "%s\n%s\n%s" "$(curl -s "https://api.github.com/repos/revanced/revanced-cli/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.jar)\"|\1\n\tout=$rv_cli|p")" "$(curl -s "https://api.github.com/repos/revanced/revanced-patches/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.jar)\"|\1\n\tout=$rv_patch|p")" "$(curl -s "https://api.github.com/repos/revanced/revanced-integrations/releases/latest" -L -A "$agent" | sed -nE "s|.*browser_download_url\": \"([^\"]*.apk)\"|\1\n\tout=$rv_inte|p")" | aria2c -j3 -x16 -s16 -i - --check-certificate=false --download-result=hide --summary-interval=0 --allow-overwrite=true -d "$tmp_dir" && info "Downloaded revanced-cli,revanced-patches,revanced-integrations at $tmp_dir"
fi
download_keystore
#choose your app
[ -z "$1" ] && app=$(printf "youtube\nyoutube-music" | fzf --prompt="Select Application:" --layout=reverse --height=8 --border) || app=$1
[ -z "$app" ] && exit 0
#set variables according to selected app
case $app in
youtube)
arch="universal"
[ -z "$2" ] && version=$(curl -s "https://api.revanced.app/v2/patches/latest" | sed -nE 's|.*youtube","versions":\[[0-9\.",]*,"([^\}]*)"\].*|\1|p') || version=$2
exclude_patch_list="always-repeat,disable-auto-captions,disable-zoom-haptics,enable-debugging,downloads,hide-autoplay-button,hide-captions-button,hide-cast-button,hide-floating-microphone-button,hide-layout-components,hide-player-buttons,custom-player-overlay-opacity,hide-seekbar,hide-timestamp,hide-video-action-buttons,navigation-buttons,player-flyout-menu,remove-player-controls-background,spoof-app-version,swipe-controls"
out="yt-revanced-$version.apk"
;;
youtube-music)
arch="arm64-v8a"
[ -z "$2" ] && version="6.10.53" || version=$2
exclude_patch_list=""
out="yt-music-revanced-$version.apk"
;;
*)
info "Wrong Package Name, please pass either 'youtube' or 'youtube-music'" "31"
exit 1
;;
esac
if [ -f "$tmp_dir/$app-$version.apk" ] && [ ! -f "$tmp_dir/$app-$version.apk.aria2" ]; then
info "Latest Recommended $app v$version already downloaded" "32"
else
info "[ $app ][ v$version ] Fetching App.."
download_apk "$(curl -s "$apk_provider_url/apk/google-inc/$app/$app-$version-release/" -A "$agent" --tlsv1.3 | tr -d '\n' | sed 's|svg class|\n|g' | sed -nE "s|.*$arch.*nodpi.*accent_color\" href=\"([^\"]*)\".*|\1|p")"
fi
info "Checking Patches for excluding.."
patch_list=$(java -jar "$tmp_dir/$rv_cli" list-patches "$tmp_dir/$rv_patch" --with-descriptions=false)
if [ -n "$exclude_patch_list" ]; then
info "Excluding Patches.." "33"
for i in $(printf "%s" "$exclude_patch_list" | tr ',' '\n'); do
if printf "%s" "$patch_list" | grep -iq "$(printf '%s' "$i" | tr '-' ' ')"; then
res="32m ✓"
else
res="31m "
check=1
fi
printf "\033[2K\r\033[1;%s %s\n" "$res" "$i"
done
exclude_patches=$(printf "%s" "$exclude_patch_list" | tr ',' '\n' | sed 's|^|--exclude |g' | tr '\n' ' ')
else
info "Nothing to Exclude.." "32"
fi
[ -n "$check" ] && info "Some of the patches are not Excluded,Check all failed patches using :" "31" && info "java -jar '$tmp_dir/$rv_cli' list-patches '$tmp_dir/$rv_patch' --with-packages" "33" && exit 1
info "All listed Patches Excluded"
info "Patching $app-$version.apk.."
#shellcheck disable=SC2086
java -jar "$tmp_dir/$rv_cli" patch --patch-bundle "$tmp_dir/$rv_patch" --merge "$tmp_dir/$rv_inte" --out "$HOME/$out" $keystore -t "$tmp_dir/revanced-resource-cache" "$tmp_dir/$app-$version.apk" $exclude_patches