~mdkcore/dotbins

dotbins/mutefy -rwxr-xr-x 2.1 KiB
2559c86bRodrigo Oliveira [power] Use loginctl instead of pm-* 1 year, 9 months ago
                                                                                
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
#!/bin/bash
####################################################################
# This script was created by: MDK - mdk@thecoreme.org              #
# http://projects.thecoreme.org/                                   #
# May 28 2014                                                      #
# Last update on Jun 09 2014                                       #
#                                                                  #
# Simple script/wrapper to "mute" Spotify's ads                    #
# based on https://gist.github.com/pcworld/3198763#comment-1233334 #
#                                                                  #
# Depends on: Spotfy (obviously), libnotify and Alsa               #
#                                                                  #
####################################################################

# run spotify and wait 15 seconds
spotify&
sleep 15

# general configuration
WMTITLE="Spotify - Linux Preview"
ADMUTE=0
PAUSED=0
NOTIFYICON="/opt/spotify/spotify-client/Icons/spotify-linux-128.png"

# die ads!
xprop -spy -name "$WMTITLE" WM_ICON_NAME |
while read -r XPROPOUTPUT; do
    XPROP_TRACKDATA="$(echo "$XPROPOUTPUT" | cut -d \" -f 2 )"
    DBUS_TRACKDATA="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify / \
    org.freedesktop.MediaPlayer2.GetMetadata | grep xesam:title -A 1 | grep variant | cut -d \" -f 2)"

    echo "XPROP:    $XPROP_TRACKDATA"
    echo "DBUS:     $DBUS_TRACKDATA"

    if [[ "$XPROP_TRACKDATA" = "Spotify" ]]
      then
          echo "--PAUSED--"
          PAUSED="1"
      else
          PAUSED=0
          echo "--NOTPAUSED--"
    fi

    if [[ "$PAUSED" = "1" || "$XPROP_TRACKDATA" =~ "$DBUS_TRACKDATA" ]]
      then
          echo "--NOAD--"
          if [[ "$ADMUTE" = "1" ]]
            then
                sleep 0.5
                amixer set Master unmute
          fi
          ADMUTE=0
      else
          echo "--AD--"
          if [[ "$ADMUTE" != "1" ]]
            then
                notify-send "Spotify" -i $NOTIFYICON "Muting ad ;)" -t 500
                amixer set Master mute
          fi
          ADMUTE=1
    fi
done

echo "Spotify not active. Exiting."
exit