From 9df7c3615d7db9283630995fc3607fe55364b841 Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Wed, 2 Sep 2020 15:44:05 -0400 Subject: [PATCH] spotifyd configuration --- files/.config/spotifyd/onevent.sh | 77 ++++++++++++++++++++++++++++ files/.config/spotifyd/spotifyd.conf | 6 +++ files/.config/waybar/config | 15 +++++- files/.config/waybar/style.css | 2 +- 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100755 files/.config/spotifyd/onevent.sh create mode 100644 files/.config/spotifyd/spotifyd.conf diff --git a/files/.config/spotifyd/onevent.sh b/files/.config/spotifyd/onevent.sh new file mode 100755 index 0000000..b7dd529 --- /dev/null +++ b/files/.config/spotifyd/onevent.sh @@ -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 + diff --git a/files/.config/spotifyd/spotifyd.conf b/files/.config/spotifyd/spotifyd.conf new file mode 100644 index 0000000..06b018c --- /dev/null +++ b/files/.config/spotifyd/spotifyd.conf @@ -0,0 +1,6 @@ +[global] +username = werhudpj20xndltxqfb95b8dw +password_cmd = pass web/spotify.com | head -n 1 + +backend = pulseaudio +#onevent=~/.config/spotifyd/onevent.sh diff --git a/files/.config/waybar/config b/files/.config/waybar/config index 7eab69f..181e5da 100644 --- a/files/.config/waybar/config +++ b/files/.config/waybar/config @@ -5,7 +5,7 @@ // Choose the order of the modules "modules-left": ["sway/workspaces", "sway/mode"], "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 "sway/workspaces": { @@ -68,12 +68,23 @@ "headset": "", "default": ["", "", ""] }, - "on-click": "pavucontrol" + "on-click-right": "pavucontrol" }, "custom/vpn": { "format": "{}", "interval": 5, "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" } } diff --git a/files/.config/waybar/style.css b/files/.config/waybar/style.css index 94d3c75..4ff4b16 100644 --- a/files/.config/waybar/style.css +++ b/files/.config/waybar/style.css @@ -19,7 +19,7 @@ window#waybar { background: #64727D; } -#clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio { +#custom-spotify, #clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio { padding: 0 10px; border-right: 1px solid #b7bbb7; }