1
0
Fork 0

spotifyd configuration

This commit is contained in:
Massaki Archambault 2020-09-02 15:44:05 -04:00
parent 6e20f19a10
commit 9df7c3615d
4 changed files with 97 additions and 3 deletions

View File

@ -0,0 +1,77 @@
#!/bin/bash
client_id='d9c43c00ff914624a02151e43ab5a16c'
client_secret=''
output="$XDG_RUNTIME_DIR/spotify_status"
token=""
get_token() {
echo -n 'Bearer '
if [[ -z "$token" ]]; then
authorization="$(base64 -w 0 <(echo -n "$client_id:$client_secret"))"
token="$(curl -s -H "Authorization: Basic $authorization" -d 'grant_type=client_credentials' https://accounts.spotify.com/api/token | jq --join-output --raw-output .access_token)"
fi
echo -n "$token"
}
track_data=""
get_track_data() {
if [[ -z "$track_data" ]]; then
track_data="$(curl -s -H "Authorization: $(get_token)" "https://api.spotify.com/v1/tracks/$TRACK_ID")"
fi
echo -n "$track_data"
}
get_artists() {
echo "$(get_track_data)" | jq --join-output --raw-output '[.artists[].name] | join(", ")'
}
get_track() {
echo "$(get_track_data)" | jq --join-output --raw-output '.name'
}
play() {
echo "$(get_track)" >$output
echo "$(get_artists) - $(get_track)" >>$output
}
stop() {
echo "$(get_track)" >$output
echo "$(get_artists) - $(get_track)" >>$output
}
pause() {
echo "$(get_track)" >$output
echo "$(get_artists) - $(get_track)" >>$output
}
case "$PLAYER_EVENT" in
"start")
play
;;
"stop")
pause
;;
"load")
;;
"play")
play
;;
"pause")
pause
;;
"preload")
;;
"endoftrack")
stop
;;
"volumeset")
;;
"change")
play
;;
*)
;;
esac

View File

@ -0,0 +1,6 @@
[global]
username = werhudpj20xndltxqfb95b8dw
password_cmd = pass web/spotify.com | head -n 1
backend = pulseaudio
#onevent=~/.config/spotifyd/onevent.sh

View File

@ -5,7 +5,7 @@
// Choose the order of the modules // Choose the order of the modules
"modules-left": ["sway/workspaces", "sway/mode"], "modules-left": ["sway/workspaces", "sway/mode"],
"modules-center": [], "modules-center": [],
"modules-right": ["clock", "network", "cpu", "memory", "battery", "backlight", "pulseaudio", "custom/vpn", "idle_inhibitor", "tray"], "modules-right": ["custom/spotify", "clock", "network", "cpu", "memory", "battery", "backlight", "pulseaudio", "custom/vpn", "idle_inhibitor", "tray"],
// Modules configuration // Modules configuration
"sway/workspaces": { "sway/workspaces": {
@ -68,12 +68,23 @@
"headset": "", "headset": "",
"default": ["", "", ""] "default": ["", "", ""]
}, },
"on-click": "pavucontrol" "on-click-right": "pavucontrol"
}, },
"custom/vpn": { "custom/vpn": {
"format": "{}", "format": "{}",
"interval": 5, "interval": 5,
"exec": "test -e /proc/sys/net/ipv4/conf/tun0 && echo  || echo " "exec": "test -e /proc/sys/net/ipv4/conf/tun0 && echo  || echo "
},
"custom/spotify": {
"format": " {}",
"interval": 5,
"max-length": 50,
"exec": "playerctl metadata -f '({{duration(position)}}/{{duration(mpris:length)}}) {{status}}: {{title}}\n{{artist}} - {{title}}'",
"exec-if": "pgrep spotify",
"on-scroll-up": "playerctl volume 0.05+",
"on-scroll-down": "playerctl volume 0.05-",
"on-click": "playerctl play-pause",
"on-click-right": "pgrep spotify$ || spotify"
} }
} }

View File

@ -19,7 +19,7 @@ window#waybar {
background: #64727D; background: #64727D;
} }
#clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio { #custom-spotify, #clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio {
padding: 0 10px; padding: 0 10px;
border-right: 1px solid #b7bbb7; border-right: 1px solid #b7bbb7;
} }