-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotify-ad-killer.sh
93 lines (71 loc) · 1.92 KB
/
spotify-ad-killer.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
#!/bin/bash
# Spotify is an amazing music streaming service and worth the premium
# subscription. This script was created out of my curiousity and it is
# intended to be used for testing purposes only! I do not take responsibility
# for any future action taken on your account by Spotify due to abusive
# use of this script.
wait_for_spotify()
{
# $1=1 wait for spotify to start
# $2=0 wait for spotify to close
(pgrep spotify > /dev/null)
running_code=$?
while [[ $(($running_code ^ $1)) == 0 ]]
do
sleep ${2:-1} # sleep for $2 seconds; default: 1s
(pgrep spotify > /dev/null)
running_code=$?
echo -n .
done
}
play()
{
until ( dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play > /dev/null 2>&1 )
do
sleep 0.2
done
}
restart_spotify()
{
start_time="$(date -u +%s.%N)"
echo "closing spotify"
(killall spotify)
wait_for_spotify 0 $1 # close
end_time="$(date -u +%s.%N)"
elapsed="$(bc <<<"$end_time-$start_time")"
echo "closing time: "$elapsed Secs
start_time="$(date -u +%s.%N)"
echo "Starting spotify"
(spotify &>/dev/null &)
wait_for_spotify 1 $1 # start
play
end_time="$(date -u +%s.%N)"
elapsed="$(bc <<<"$end_time-$start_time")"
echo "sarting time: "$elapsed Secs
}
echo "waiting for spotify..."
wait_for_spotify 1 20 # start
echo "spotify started"
while true
do
until dbus_msg=$( dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get \
string:'org.mpris.MediaPlayer2.Player' \
string:'Metadata' 2>&1 )
do
sleep 20
echo -n .
done
if (echo $dbus_msg | grep -q "spotify:ad" )
then
# ad detected; skip ad
echo "Ad detected! restarting..."
start_t="$(date -u +%s.%N)"
restart_spotify 0.5 # delay secs
end_t="$(date -u +%s.%N)"
elapsed="$(bc <<<"$end_t-$start_t")"
echo "Spotify restarted: " $elapsed Secs
fi
sleep 2
done