-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxfce-spotify-main.sh
45 lines (39 loc) · 1.35 KB
/
xfce-spotify-main.sh
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
#!/bin/bash
# Script made by macr1408 (https://github.com/macr1408)
# Made for non Commercial use
if ! pgrep -x spotify >/dev/null && ! pgrep -x chrome >/dev/null && ! pgrep -x firefox >/dev/null
then
echo "<txt></txt>"
exit 1;
fi
CURRENTDIR=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
CONFIGFILE="$CURRENTDIR/config.sh"
REFRESHFILE="$CURRENTDIR/refresh_accesstoken.sh"
SONGFILE="$CURRENTDIR/current_song.json"
source $CONFIGFILE
curl -s https://api.spotify.com/v1/me/player/currently-playing \
-H "Authorization: Bearer $ACCESSTOKEN" \
-o $SONGFILE
ERRORCODE=$(jq -r '.error.status' $SONGFILE)
ERRORMSG=$(jq -r '.error.message' $SONGFILE)
if [ $ERRORCODE == 401 ] && [ "$ERRORMSG" == "The access token expired" ]
then
source $REFRESHFILE
fi
ARTIST=$(jq -r '.item.artists[0].name' $SONGFILE)
TRACK=$(jq -r '.item.name' $SONGFILE)
ALBUM=$(jq -r '.item.album.name' $SONGFILE)
SONGLINK=$(jq -r '.item.external_urls.spotify' $SONGFILE)
CURRENTPROGRESS=$(jq -r '.progress_ms' $SONGFILE)
CURRENTPROGRESS=$(expr $CURRENTPROGRESS \* 100)
TOTALPROGRESS=$(jq -r '.item.duration_ms' $SONGFILE)
TOTALPROGRESS=$(expr $CURRENTPROGRESS / $TOTALPROGRESS )
if [ -n "$TRACK" ]
then
echo "<txt>$ARTIST - $TRACK </txt>"
echo "<tool>$ALBUM</tool>"
echo "<bar>$TOTALPROGRESS</bar>"
echo "<txtclick>exo-open $SONGLINK</txtclick>"
else
echo "<txt></txt>"
fi