Add patch remove ad placeholder and upgrade button.

I suck at sed and grep so python time (this script embed a python script to do that lol)
This commit is contained in:
darkelaina 2021-12-22 09:49:39 +00:00
parent 461abd25b8
commit 988f1436a4

View File

@ -1,20 +1,38 @@
#!/bin/bash #!/bin/bash
declare -a deps=("curl" "unzip" "rm") declare -a deps=("curl" "unzip" "rm" "7z" "python3")
declare -a patchfiles=("chrome_elf.dll" "config.ini") declare -a patchfiles=("chrome_elf.dll" "config.ini")
SPOTIFY="$WINEPREFIX/drive_c/users/$(whoami)/AppData/Roaming/Spotify/"
TMPDIR=$(mktemp -d)
if (( $EUID == 0 )); then if (( $EUID == 0 )); then
echo "Do not run this script as root." echo "Do not run this script as root."
exit exit
fi fi
adPatchScript=$(cat << EOF
#!/usr/bin/python3
import re
from pathlib import Path
print("Patching xpui.js...")
xpui = Path("./xpui/xpui.js")
xpui_content = xpui.read_text(encoding="utf-8")
replace_ad = re.sub(r"(\.ads\.leaderboard\.isEnabled)(}|\))", r"\1&&false\2", xpui_content)
replace_upgrade = re.sub(r"\.createElement\([^.,{]+,{onClick:[^.,]+,className:[^.]+\.[^.]+\.UpgradeButton}\),[^.(]+\(\)", "", replace_ad)
xpui.write_text(replace_upgrade, encoding="utf-8")
EOF
)
[[ -z "${WINEPREFIX}" ]] && WINEPREFIX="$HOME/.wine" || WINEPREFIX="${WINEPREFIX}" [[ -z "${WINEPREFIX}" ]] && WINEPREFIX="$HOME/.wine" || WINEPREFIX="${WINEPREFIX}"
echo "BlockTheSpot install script for Wine" SPOTIFY="$WINEPREFIX/drive_c/users/$(whoami)/AppData/Roaming/Spotify/"
SPOTIFY_APPS="$SPOTIFY/Apps/"
xpuiBundlePath="$SPOTIFY_APPS/xpui.spa"
xpuiUnpackedPath="$SPOTIFY_APPS/xpui/xpui.js"
echo "BlockTheSpot install script for Spotify (Wine version)"
echo "BlockTheSpot: https://github.com/mrpond/BlockTheSpot/" echo "BlockTheSpot: https://github.com/mrpond/BlockTheSpot/"
echo "Current Wineprefix: $WINEPREFIX" echo "Current Wineprefix: $WINEPREFIX"
TMPDIR=$(mktemp -d)
cd $TMPDIR cd $TMPDIR
for v in "${deps[@]}" for v in "${deps[@]}"
@ -38,10 +56,10 @@ if [ "$1" == "uninstall" ]; then
rm "$SPOTIFY/$v" rm "$SPOTIFY/$v"
done done
mv "$SPOTIFY/chrome_elf_bak.dll" "$SPOTIFY/chrome_elf.dll" mv "$SPOTIFY/chrome_elf_bak.dll" "$SPOTIFY/chrome_elf.dll"
echo "Uninstalling completed." echo "Uninstalling xpui patch if found..."
else mv "$xpuiBundlePath.bak" "$xpuiBundlePath"
echo "Nothing to uninstall."
fi fi
echo "Uninstalling BlockTheSpot (IF INSTALLED) completed."
exit exit
fi fi
@ -51,7 +69,7 @@ curl -OL "https://github.com/mrpond/BlockTheSpot/releases/latest/download/chrome
echo "Extracting BlockTheSpot..." echo "Extracting BlockTheSpot..."
unzip -d chrome_elf chrome_elf.zip unzip -d chrome_elf chrome_elf.zip
if [ -f "$SPOTIFY/chrome_elf.dll" ]; then if [ -f "$SPOTIFY/chrome_elf.dll" ] && ! [ -f "$SPOTIFY/chrome_elf_bak.dll" ]; then
echo "Backuping files..." echo "Backuping files..."
mv "$SPOTIFY/chrome_elf.dll" "$SPOTIFY/chrome_elf_bak.dll" mv "$SPOTIFY/chrome_elf.dll" "$SPOTIFY/chrome_elf_bak.dll"
fi fi
@ -64,4 +82,22 @@ do
cp "./chrome_elf/$v" "$SPOTIFY/$v" cp "./chrome_elf/$v" "$SPOTIFY/$v"
done done
echo "Patching completed." read -p "Do you want to remove ad placeholder and upgrade button? (y/n) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
if [ -f "$xpuiBundlePath" ]; then
echo "Patching xpui.spa..."
if ! [ -f "$xpuiBundlePath.bak" ]; then
mv "$xpuiBundlePath" "$xpuiBundlePath.bak"
fi
unzip -d xpui "$xpuiBundlePath.bak"
fi
echo "$adPatchScript" > "./patch.py"
python3 ./patch.py
7z a xpui.zip "./xpui/*"
mv xpui.zip $xpuiBundlePath
fi
echo "Patching completed, open Spotify and enjoy :D"
echo "Temporary directory used $TMPDIR"