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.
This commit is contained in:
parent
533652e383
commit
d6c4888fe1
|
@ -13,87 +13,87 @@ with lib;
|
||||||
|
|
||||||
config = mkIf config.modules.media.spotify.enable {
|
config = mkIf config.modules.media.spotify.enable {
|
||||||
my.packages = with pkgs; [
|
my.packages = with pkgs; [
|
||||||
# services.spotifyd doesn't work so we'll have to roll our own spotifyd +
|
# # 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
|
# # spotify-tui solution. The dbus interface doesn't work, though, so we
|
||||||
# have to wait for spotify-tui to implement CLI command for controlling
|
# # have to wait for spotify-tui to implement CLI command for controlling
|
||||||
# spotify playback. See
|
# # spotify playback. See
|
||||||
# https://github.com/Rigellute/spotify-tui/issues/147 or for spotifyd to
|
# # https://github.com/Rigellute/spotify-tui/issues/147 or for spotifyd to
|
||||||
# get fixed.
|
# # get fixed.
|
||||||
unstable.spotifyd
|
# unstable.spotifyd
|
||||||
(writeScriptBin "spt" ''
|
# (writeScriptBin "spt" ''
|
||||||
#!${stdenv.shell}
|
# #!${stdenv.shell}
|
||||||
if ! systemctl --user is-active spotifyd >/dev/null; then
|
# if ! systemctl --user is-active spotifyd >/dev/null; then
|
||||||
systemctl --user start spotifyd
|
# systemctl --user start spotifyd
|
||||||
fi
|
# fi
|
||||||
echo $TMUX >/tmp/spt.tmux
|
# echo $TMUX >/tmp/spt.tmux
|
||||||
exec ${unstable.spotify-tui}/bin/spt
|
# exec ${unstable.spotify-tui}/bin/spt
|
||||||
'')
|
# '')
|
||||||
|
|
||||||
# spotify-tui is fine for selecting and playing music, but incomplete. We
|
# spotify-tui is fine for selecting and playing music, but incomplete. We
|
||||||
# still occasionally need the official client for more sophisticated
|
# still occasionally need the official client for more sophisticated
|
||||||
# search and the "made for you" playlists.
|
# search and the "made for you" playlists.
|
||||||
spotify
|
spotify
|
||||||
|
|
||||||
# Since dbus doesn't work with Nix's spotifyd/spotify-tui, and I always
|
# # 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.
|
# # use tmux for my terminal, may as well exploit tmux to control spotify.
|
||||||
playerctl
|
# playerctl
|
||||||
(writeScriptBin "spt-send" ''
|
# (writeScriptBin "spt-send" ''
|
||||||
#!${stdenv.shell}
|
# #!${stdenv.shell}
|
||||||
dbus_cmd='playerctl -p spotify'
|
# dbus_cmd='playerctl -p spotify'
|
||||||
tmux_cmd="tmux send-keys -t $(cat /tmp/spt.tmux | cut -d, -f3)"
|
# tmux_cmd="tmux send-keys -t $(cat /tmp/spt.tmux | cut -d, -f3)"
|
||||||
case "$1" in
|
# case "$1" in
|
||||||
toggle) $dbus_cmd play-pause 2>/dev/null || $tmux_cmd " " ;;
|
# toggle) $dbus_cmd play-pause 2>/dev/null || $tmux_cmd " " ;;
|
||||||
next) $dbus_cmd next 2>/dev/null || $tmux_cmd n ;;
|
# next) $dbus_cmd next 2>/dev/null || $tmux_cmd n ;;
|
||||||
prev) $dbus_cmd previous 2>/dev/null || $tmux_cmd p ;;
|
# prev) $dbus_cmd previous 2>/dev/null || $tmux_cmd p ;;
|
||||||
esac
|
# esac
|
||||||
'')
|
# '')
|
||||||
|
|
||||||
(writeScriptBin "spt-send-notify" ''
|
# (writeScriptBin "spt-send-notify" ''
|
||||||
#!${stdenv.shell}
|
# #!${stdenv.shell}
|
||||||
client_id=$(pass www/spotify.com | grep -E '^client_id:' | awk '{print $2}')
|
# 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}')
|
# client_secretd=$(pass www/spotify.com | grep -E '^client_secret:' | awk '{print $2}')
|
||||||
jq="${pkgs.jq}/bin/jq"
|
# 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)
|
# 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=$?
|
# result=$?
|
||||||
if [[ $result != 0 ]]; then
|
# if [[ $result != 0 ]]; then
|
||||||
notify-send "spt-send failure" "Could not acquire token"
|
# notify-send "spt-send failure" "Could not acquire token"
|
||||||
exit 1
|
# exit 1
|
||||||
fi
|
# fi
|
||||||
case "$PLAYER_EVENT" in
|
# case "$PLAYER_EVENT" in
|
||||||
start)
|
# 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
|
# 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)
|
# 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
|
# 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)
|
# 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
|
# 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."
|
# *) 2>&1 echo "Unkown event."
|
||||||
exit 2
|
# exit 2
|
||||||
;;
|
# ;;
|
||||||
esac
|
# esac
|
||||||
'')
|
# '')
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.user.services.spotifyd.serviceConfig =
|
# systemd.user.services.spotifyd.serviceConfig =
|
||||||
let spotifydConf = pkgs.writeText "spotifyd.conf" ''
|
# let spotifydConf = pkgs.writeText "spotifyd.conf" ''
|
||||||
[global]
|
# [global]
|
||||||
username = g2qwjcs6334oacg1zg9wrihnn
|
# username = g2qwjcs6334oacg1zg9wrihnn
|
||||||
password_cmd = ${pkgs.pass}/bin/pass www/spotify.com | head -n1
|
# password_cmd = ${pkgs.pass}/bin/pass www/spotify.com | head -n1
|
||||||
backend = pulseaudio
|
# backend = pulseaudio
|
||||||
on_song_change_hook = spt-send-notify
|
# on_song_change_hook = spt-send-notify
|
||||||
cache_path = /home/${config.my.username}/.cache/spotifyd
|
# cache_path = /home/${config.my.username}/.cache/spotifyd
|
||||||
'';
|
# '';
|
||||||
in {
|
# in {
|
||||||
ExecStart = ''
|
# ExecStart = ''
|
||||||
${pkgs.unstable.spotifyd}/bin/spotifyd --no-daemon \
|
# ${pkgs.unstable.spotifyd}/bin/spotifyd --no-daemon \
|
||||||
--cache-path /tmp/spotifyd \
|
# --cache-path /tmp/spotifyd \
|
||||||
--config-path ${spotifydConf}
|
# --config-path ${spotifydConf}
|
||||||
'';
|
# '';
|
||||||
Restart = "always";
|
# Restart = "always";
|
||||||
RestartSec = 6;
|
# RestartSec = 6;
|
||||||
};
|
# };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue