Created
January 29, 2019 07:55
-
-
Save hosseinm1997/ae26fdb8c318c7ee383a87e7cae82a23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
was_paused=0 # if last state was paused | |
ad=0 # if an ad is probably playing right now | |
while true; do | |
num=$(pactl list | grep -E '(^Sink Input)|(media.name = \"Spotify\"$)' | awk '/Spotify/ {print a} {a = $0}' | cut -c 13-) | |
icon_name=$(xprop -name 'spotify' _NET_WM_ICON_NAME | cut -d \" -f 2) | |
song_name=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | grep xesam:title -A 1 | grep variant | cut -d \" -f 2) | |
if [[ "$song_name" && "$icon_name" =~ "$song_name" ]]; then | |
if [ "$was_paused" -eq 0 -a "$ad" -ne 0 ]; then | |
# wait 1 second after a commercial | |
sleep 1 | |
fi | |
ad=0 | |
pactl set-sink-input-mute $num no | |
else | |
ad=1 | |
pactl set-sink-input-mute $num yes | |
fi | |
if [ "$icon_name" = "Spotify" ]; then | |
was_paused=1 | |
else | |
was_paused=0 | |
fi | |
sleep 0.5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment