-
Notifications
You must be signed in to change notification settings - Fork 87
/
spotify-wrapper.sh
executable file
·158 lines (130 loc) · 5.28 KB
/
spotify-wrapper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
# Official Spotify-AdKiller Repository: https://github.com/SecUpwN/Spotify-AdKiller/
# CHANGELOG: https://github.com/SecUpwN/Spotify-AdKiller/blob/master/CHANGELOG.md
# Feel free to contribute improvements and suggestions to this funky script!
# Wrapper script to automatically start Spotify-AdKiller when Spotify starts
# Please make sure to consult the attached README file before using this script
# IMPORTANT REMINDER! CAREFULLY READ AND UNDERSTAND THIS PART. THANK YOU.
# -----------------------------------------------------------------------
# Spotify is a fantastic service and worth every penny.
# This script is *NOT* meant to circumvent buying premium.
# Please do consider switching to premium to support Spotify!
# -----------------------------------------------------------------------
# This product is not endorsed, certified or otherwise approved in any way
# by Spotify. Spotify is the registered trade mark of the Spotify Group.
# -----------------------------------------------------------------------
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------
# WARNING: If you use this wrapper please make sure to ALWAYS use it
# If you start Spotify without it, there's a chance that Spotify will
# stay muted and will have to be manually be unmuted through pactl
## VARIABLES
# settings
ADKILLER="spotify-adkiller.sh"
WMCLASS="Spotify"
LOGFILE="$HOME/.Spotify-AdKiller.log"
# DNS-BLOCK
# experimental support for blocking ad banners
# Instructions:
# 1. download and compile dns-block.c from the experimental branch
# (https://github.com/SecUpwN/Spotify-AdKiller/tree/dns-block/experimental)
# 2. create a dns-block directory in your Spotify AdKiller installation path
# 3. Move the compiled dns-block.so library there
SCRIPTEXEC="$(readlink -f "$0")"
SCRIPTDIR="${SCRIPTEXEC%/*}"
PRELOAD_LIB="$SCRIPTDIR/dns-block/dns-block.so"
[[ ! -f "$PRELOAD_LIB" ]] && PRELOAD_LIB=""
# initialization
COUNTER="0"
# config
CONFIG_PATH="${XDG_CONFIG_HOME:-$HOME/.config}/Spotify-AdKiller"
CONFIG_FILE="$CONFIG_PATH/Spotify-AdKiller.cfg"
CONFIG_DEFAULT=\
'## ##
## Configuration file for Spotify-AdKiller ##
## Please make sure to double-quote all custom values ##
## ##
CUSTOM_MODE=""
# ad block mode. possible values:
# - simple — mute Spotify, unmute when ad is over
# - interstitial — mute Spotify, play random local track, stop and unmute when ad is over
# - continuous — mute Spotify, play random local track, stop and unmute when track is over
# -> set to continuous by default
CUSTOM_PLAYER=""
CUSTOM_LOOPOPT=""
# local music player to use
# you can define a loop option (if available) in case you want
# to use a music track shorter than the average ad duration (only applicable to interstitial mode)
# -> chosen automatically by default
CUSTOM_VOLUME=""
# volume of local playback
# -> set to 100 by default
CUSTOM_MUSIC=""
# local music directory / track
# -> set to XDG standard music directory by default
DEBUG="0"
# control debug mode
# - "1" to enable
# - "0" to disable
# -> Will make the CLI output more verbose and write a logfile
# to "$HOME/.Spotify-AdKiller.log"'
## CLI MESSAGES
ERRORMSG1="Error: Spotify not found."
INFOMSG1="DEBUG mode active"
## FUNCTIONS
notify_send(){
notify-send -i spotify-client "Spotify-AdKiller" "$1"
}
read_write_config(){
mkdir -p "$CONFIG_PATH"
if [[ ! -f "$CONFIG_FILE" ]]; then
echo "$CONFIG_DEFAULT" > "$CONFIG_FILE"
fi
source "$CONFIG_FILE"
}
spotify_launch(){
LD_PRELOAD="$PRELOAD_LIB" spotify "$@" > /dev/null 2>&1 &
# wait for spotify to launch
# if spotify not launched after 50 seconds exit script
while true; do
if [[ "$COUNTER" = "10" ]]
then
notify_send "$ERRORMSG1"
echo "$ERRORMSG1"
exit 1
fi
echo "## Waiting for Spotify ##"
xdotool search --classname "$WMCLASS" > /dev/null 2>&1
if [[ "$?" == "0" ]]; then
break
fi
COUNTER=$(( COUNTER + 1 ))
sleep 5
done
}
adkiller_launch(){
# only launch script if it isn't active already
# we need to truncate script name to make pgrep work
if [[ -z "$(pgrep "${ADKILLER:0:14}")" ]]; then
if [[ "$DEBUG" = "1" ]]; then
echo "$INFOMSG1"
notify_send "$INFOMSG1"
$ADKILLER > "$LOGFILE" 2> /dev/null &
else
$ADKILLER > /dev/null 2>&1 &
fi
fi
}
## MAIN
read_write_config
spotify_launch "$@"
adkiller_launch