Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 229790d

Browse files
committed
add mode to auto-detect player
adds feature request #1 i also fixed dumb pgrep checking in favor of a loop that checks things in $PLAYER
1 parent 78896b1 commit 229790d

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

config.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# which player to get data from (must support mpris), refer to playerctl's github page for more info
44
PLAYER="spotify"
5+
# set PLAYER to auto for PRIOLIST to take effect
6+
# comma-seperated list of players to try getting metadata from, from left to right: highest priority --> lowest priority
7+
PRIOLIST="spotify,mpd,lollypop,amberol,vvave"
58
# final output format (what shows up in ur panel). available values: $STATUSCHAR, $ARTIST, $TRACK, $ALBUM, $SONGLINK
69
OUTFORMAT="[$STATUSCHAR] $ARTIST - $TRACK"
710
# image settings - this stuff requires python, refer to the readme for instructions

xfce-spotify-main.sh

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,36 @@
33
# Script orignally made by macr1408 (https://github.com/macr1408), modified by userbyte (https://github.com/userbyte) to use playerctl instead of the Spotify API because I could't get it to work
44
# Made for non-commercial use
55

6-
if ! pgrep -x spotify >/dev/null && ! pgrep -x chrome >/dev/null && ! pgrep -x firefox >/dev/null && ! pgrep -f lollypop >/dev/null
7-
then
8-
echo "<txt></txt>"
9-
exit 1;
10-
fi
11-
126
CURRENTDIR=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
137
CONFIGFILE="$CURRENTDIR/config.sh"
148
SONGFILE="$CURRENTDIR/current_song.json"
159
source $CONFIGFILE
1610

17-
# PLAYER="spotify" # grabbed from config
11+
if [ "$PLAYER" = "auto" ]; then
12+
#echo "auto-detecting player using prio list: $PRIOLIST"
13+
PLAYER="$PRIOLIST"
14+
fi
15+
16+
IFS=',' read -ra p_array <<< "$PLAYER"
17+
FOUNDONE="0"
18+
for i in "${p_array[@]}"
19+
do
20+
if pgrep -x $i >/dev/null
21+
then
22+
# echo "$i found"
23+
FOUNDONE="1"
24+
: # pass
25+
else
26+
# echo "$i not found"
27+
: # pass
28+
fi
29+
done
30+
31+
if [ "$FOUNDONE" = "0" ]; then
32+
# echo "didnt find any valid players running, returning empty thing and exiting..."
33+
echo "<txt></txt>"
34+
exit 1;
35+
fi
1836

1937
#FORMAT="{{ artist }} - {{ title }}"
2038
FORMAT='{"title": "{{ title }}", "artist": "{{ artist }}", "album": "{{ album }}", "link": "{{ xesam:url }}", "arturl": "{{ mpris:artUrl }}"}'

0 commit comments

Comments
 (0)