Skip to content

Commit

Permalink
Update spotify-adkiller.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
quietoparado committed Feb 27, 2015
1 parent dd10d9f commit 38e2f12
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions spotify-adkiller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,14 @@ get_state(){
debuginfo "DBUS_DEBUG: $DBUSOUTPUT"

# get track data from xprop and the DBUS interface
XPROP_TRACKDATA="$(echo "$XPROPOUTPUT" | cut -d\" -f 2- | rev | cut -d\" -f 2- | rev)"
DBUS_TRACKDATA="$(echo "$DBUSOUTPUT" | grep xesam:title -A 1 | grep variant | \
cut -d\" -f 2- | rev | cut -d\" -f 2- | rev)"
# `cut | rev | cut | rev` gets string between first and last double-quotes
# TODO: find a more elegant way to do this
XPROP_TRACKDATA="$(echo "$XPROPOUTPUT" | cut -d\" -f 2)"
DBUS_TRACKDATA="$(echo "$DBUSOUTPUT" | grep xesam:title -A 1 | grep variant | cut -d\" -f 2)"

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

# check if track paused
if [[ "$XPROP_TRACKDATA" = "Spotify" ]]
if [[ "$XPROP_TRACKDATA" = "Spotify" ]] && [[ ! "${#DBUS_TRACKDATA}" == "0" ]]
then
echo "PAUSED: Yes"
PAUSED="1"
Expand All @@ -221,11 +218,11 @@ get_state(){
fi

# check if track is an ad
if [[ ! "$XPROP_TRACKDATA" == *"$DBUS_TRACKDATA"* && "$PAUSED" = "0" ]]
if ( [[ "${#DBUS_TRACKDATA}" == "0" ]] || [[ ! "$XPROP_TRACKDATA" == *"$DBUS_TRACKDATA"* ]] ) && [[ "$PAUSED" = "0" ]]
then
echo "AD: Yes"
AD="1"
elif [[ ! "$XPROP_TRACKDATA" == *"$DBUS_TRACKDATA"* && "$PAUSED" = "1" ]]
elif ( [[ "${#DBUS_TRACKDATA}" == "0" ]] || [[ ! "$XPROP_TRACKDATA" == *"$DBUS_TRACKDATA"* ]] ) && [[ "$PAUSED" = "1" ]]
then
echo "AD: Can't say"
AD="0"
Expand Down

1 comment on commit 38e2f12

@quietoparado
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detect Spotify Ads whith empty DBUS value and a simple way for XPROP_TRACKDATA and DBUS_TRACKDATA variables.

XPROP: Spotify - Spotify – Spotify
DBUS:
PAUSED: No
AD: No

LOCAL: No

XPROP: Spotify
DBUS:
PAUSED: Yes # FAKE PAUSED IN THE MASTER SCRIPT. IS AN AD, THE DBUS VALUE IS EMPTY.
AD: No
LOCAL: No

Please sign in to comment.