-
-
Save carlos22/6881863 to your computer and use it in GitHub Desktop.
works with 0.9.1.55.gbdd3b79f (ubuntu 12.04 german locale)
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 | |
# Updated from https://gist.github.com/pcworld/3198763/#comment-857143 | |
# added launch of spotify and made it working on non-english envs (2013-10-08) | |
# works with 0.9.1.55.gbdd3b79f (ubuntu 12.04 german locale) | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # http://stackoverflow.com/a/246128 | |
was_paused=0 # if last state was paused | |
ad=0 # if an ad is probably playing right now | |
while true; do | |
num=$(LC_ALL=C pactl list | grep -E '(^Sink Input)|(media.name = \"Spotify\"$)' | awk '/Spotify/ {print a} {a = $0}' | cut -c 13-) | |
#icon_name=$(xprop -name 'Spotify - Linux Preview' _NET_WM_ICON_NAME | cut -d \" -f 2) | |
icon_name=$(xprop -name 'Spotify - Linux Preview' WM_ICON_NAME | awk -F"– " '{print $2}' | cut -d \" -f 1) | |
song_name=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify / org.freedesktop.MediaPlayer2.GetMetadata | 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 | |
if [ -z "$icon_name" ]; then | |
was_paused=1 | |
else | |
was_paused=0 | |
fi | |
sleep 0.5 | |
done & | |
$DIR/spotify "$@" & | |
wait $! && | |
test -z "`jobs -p`" || kill `jobs -p` # http://stackoverflow.com/a/2618497 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment