From d6c4888fe19190671959afba8ae4c4f02ebb901b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 27 Apr 2020 19:19:58 -0400 Subject: [PATCH] Disable spotifyd + spt hackery spt will drop connection randomly; it's so disruptive that it makes the whole setup unusable. Until a better solution appears, I'll stick to the official client. --- modules/media/spotify.nix | 144 +++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/modules/media/spotify.nix b/modules/media/spotify.nix index 74b76aac..44b297f8 100644 --- a/modules/media/spotify.nix +++ b/modules/media/spotify.nix @@ -13,87 +13,87 @@ with lib; config = mkIf config.modules.media.spotify.enable { my.packages = with pkgs; [ - # services.spotifyd doesn't work so we'll have to roll our own spotifyd + - # spotify-tui solution. The dbus interface doesn't work, though, so we - # have to wait for spotify-tui to implement CLI command for controlling - # spotify playback. See - # https://github.com/Rigellute/spotify-tui/issues/147 or for spotifyd to - # get fixed. - unstable.spotifyd - (writeScriptBin "spt" '' - #!${stdenv.shell} - if ! systemctl --user is-active spotifyd >/dev/null; then - systemctl --user start spotifyd - fi - echo $TMUX >/tmp/spt.tmux - exec ${unstable.spotify-tui}/bin/spt - '') + # # services.spotifyd doesn't work so we'll have to roll our own spotifyd + + # # spotify-tui solution. The dbus interface doesn't work, though, so we + # # have to wait for spotify-tui to implement CLI command for controlling + # # spotify playback. See + # # https://github.com/Rigellute/spotify-tui/issues/147 or for spotifyd to + # # get fixed. + # unstable.spotifyd + # (writeScriptBin "spt" '' + # #!${stdenv.shell} + # if ! systemctl --user is-active spotifyd >/dev/null; then + # systemctl --user start spotifyd + # fi + # echo $TMUX >/tmp/spt.tmux + # exec ${unstable.spotify-tui}/bin/spt + # '') # spotify-tui is fine for selecting and playing music, but incomplete. We # still occasionally need the official client for more sophisticated # search and the "made for you" playlists. spotify - # Since dbus doesn't work with Nix's spotifyd/spotify-tui, and I always - # use tmux for my terminal, may as well exploit tmux to control spotify. - playerctl - (writeScriptBin "spt-send" '' - #!${stdenv.shell} - dbus_cmd='playerctl -p spotify' - tmux_cmd="tmux send-keys -t $(cat /tmp/spt.tmux | cut -d, -f3)" - case "$1" in - toggle) $dbus_cmd play-pause 2>/dev/null || $tmux_cmd " " ;; - next) $dbus_cmd next 2>/dev/null || $tmux_cmd n ;; - prev) $dbus_cmd previous 2>/dev/null || $tmux_cmd p ;; - esac - '') + # # Since dbus doesn't work with Nix's spotifyd/spotify-tui, and I always + # # use tmux for my terminal, may as well exploit tmux to control spotify. + # playerctl + # (writeScriptBin "spt-send" '' + # #!${stdenv.shell} + # dbus_cmd='playerctl -p spotify' + # tmux_cmd="tmux send-keys -t $(cat /tmp/spt.tmux | cut -d, -f3)" + # case "$1" in + # toggle) $dbus_cmd play-pause 2>/dev/null || $tmux_cmd " " ;; + # next) $dbus_cmd next 2>/dev/null || $tmux_cmd n ;; + # prev) $dbus_cmd previous 2>/dev/null || $tmux_cmd p ;; + # esac + # '') - (writeScriptBin "spt-send-notify" '' - #!${stdenv.shell} - client_id=$(pass www/spotify.com | grep -E '^client_id:' | awk '{print $2}') - client_secretd=$(pass www/spotify.com | grep -E '^client_secret:' | awk '{print $2}') - jq="${pkgs.jq}/bin/jq" + # (writeScriptBin "spt-send-notify" '' + # #!${stdenv.shell} + # client_id=$(pass www/spotify.com | grep -E '^client_id:' | awk '{print $2}') + # client_secretd=$(pass www/spotify.com | grep -E '^client_secret:' | awk '{print $2}') + # jq="${pkgs.jq}/bin/jq" - token=$(curl -s -X 'POST' -u $client_id:$client_secretd -d grant_type=client_credentials https://accounts.spotify.com/api/token | $jq '.access_token' | cut -d\" -f2) - result=$? - if [[ $result != 0 ]]; then - notify-send "spt-send failure" "Could not acquire token" - exit 1 - fi - case "$PLAYER_EVENT" in - start) - curl -s -X 'GET' https://api.spotify.com/v1/tracks/$TRACK_ID -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization:\"Bearer $token\"" | $jq '.name, .artists[].name, .album.name, .album.release_date, .track_number, .album.total_tracks' | xargs printf "\"Playing '%s' from '%s' (album: '%s' in %s (%s/%s))\"" | xargs notify-send --urgency=low --expire-time=3000 --icon=/usr/share/icons/gnome/32x32/actions/player_play.png --app-name=spotifyd spotifyd - ;; - stop) - curl -s -X 'GET' https://api.spotify.com/v1/tracks/$TRACK_ID -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization:\"Bearer $token\"" | $jq '.name, .artists[].name, .album.name, .album.release_date, .track_number, .album.total_tracks' | xargs printf "Stoping music (Last song: '%s' from '%s' (album: '%s' in %s (%s/%s)))\"" | xargs notify-send --urgency=low --expire-time=3000 --icon=/usr/share/icons/gnome/32x32/actions/player_stop.png --app-name=spotifyd spotifyd - ;; - change) - curl -s -X 'GET' https://api.spotify.com/v1/tracks/$TRACK_ID -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization:\"Bearer $token\"" | $jq '.name, .artists[].name, .album.name, .album.release_date, .track_number, .album.total_tracks' | xargs printf "\"Music changed to '%s' from '%s' (album: '%s' in %s (%s/%s))\"" | xargs notify-send --urgency=low --expire-time=3000 --icon=/usr/share/icons/gnome/32x32/actions/player_fwd.png --app-name=spotifyd spotifyd - ;; - *) 2>&1 echo "Unkown event." - exit 2 - ;; - esac - '') + # token=$(curl -s -X 'POST' -u $client_id:$client_secretd -d grant_type=client_credentials https://accounts.spotify.com/api/token | $jq '.access_token' | cut -d\" -f2) + # result=$? + # if [[ $result != 0 ]]; then + # notify-send "spt-send failure" "Could not acquire token" + # exit 1 + # fi + # case "$PLAYER_EVENT" in + # start) + # curl -s -X 'GET' https://api.spotify.com/v1/tracks/$TRACK_ID -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization:\"Bearer $token\"" | $jq '.name, .artists[].name, .album.name, .album.release_date, .track_number, .album.total_tracks' | xargs printf "\"Playing '%s' from '%s' (album: '%s' in %s (%s/%s))\"" | xargs notify-send --urgency=low --expire-time=3000 --icon=/usr/share/icons/gnome/32x32/actions/player_play.png --app-name=spotifyd spotifyd + # ;; + # stop) + # curl -s -X 'GET' https://api.spotify.com/v1/tracks/$TRACK_ID -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization:\"Bearer $token\"" | $jq '.name, .artists[].name, .album.name, .album.release_date, .track_number, .album.total_tracks' | xargs printf "Stoping music (Last song: '%s' from '%s' (album: '%s' in %s (%s/%s)))\"" | xargs notify-send --urgency=low --expire-time=3000 --icon=/usr/share/icons/gnome/32x32/actions/player_stop.png --app-name=spotifyd spotifyd + # ;; + # change) + # curl -s -X 'GET' https://api.spotify.com/v1/tracks/$TRACK_ID -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization:\"Bearer $token\"" | $jq '.name, .artists[].name, .album.name, .album.release_date, .track_number, .album.total_tracks' | xargs printf "\"Music changed to '%s' from '%s' (album: '%s' in %s (%s/%s))\"" | xargs notify-send --urgency=low --expire-time=3000 --icon=/usr/share/icons/gnome/32x32/actions/player_fwd.png --app-name=spotifyd spotifyd + # ;; + # *) 2>&1 echo "Unkown event." + # exit 2 + # ;; + # esac + # '') ]; - systemd.user.services.spotifyd.serviceConfig = - let spotifydConf = pkgs.writeText "spotifyd.conf" '' - [global] - username = g2qwjcs6334oacg1zg9wrihnn - password_cmd = ${pkgs.pass}/bin/pass www/spotify.com | head -n1 - backend = pulseaudio - on_song_change_hook = spt-send-notify - cache_path = /home/${config.my.username}/.cache/spotifyd - ''; - in { - ExecStart = '' - ${pkgs.unstable.spotifyd}/bin/spotifyd --no-daemon \ - --cache-path /tmp/spotifyd \ - --config-path ${spotifydConf} - ''; - Restart = "always"; - RestartSec = 6; - }; + # systemd.user.services.spotifyd.serviceConfig = + # let spotifydConf = pkgs.writeText "spotifyd.conf" '' + # [global] + # username = g2qwjcs6334oacg1zg9wrihnn + # password_cmd = ${pkgs.pass}/bin/pass www/spotify.com | head -n1 + # backend = pulseaudio + # on_song_change_hook = spt-send-notify + # cache_path = /home/${config.my.username}/.cache/spotifyd + # ''; + # in { + # ExecStart = '' + # ${pkgs.unstable.spotifyd}/bin/spotifyd --no-daemon \ + # --cache-path /tmp/spotifyd \ + # --config-path ${spotifydConf} + # ''; + # Restart = "always"; + # RestartSec = 6; + # }; }; }