From 661f3e0911bc86b11157d73114a2eb32375faab4 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 4 Apr 2024 12:16:48 +0200 Subject: [PATCH] add np-subsonic --- .config/zsh/functions/np-subsonic | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 .config/zsh/functions/np-subsonic diff --git a/.config/zsh/functions/np-subsonic b/.config/zsh/functions/np-subsonic new file mode 100755 index 0000000..e6273a2 --- /dev/null +++ b/.config/zsh/functions/np-subsonic @@ -0,0 +1,26 @@ +#!/usr/bin/env zsh +# get now playing from subsonic compatible API +# cfg file: host\nuser\password + +setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL + +local -a cfg +while IFS=\n read -r line; do + cfg+=${line} +done < ${XDG_CONFIG_HOME:-~/.config}/nc-subsonic.cfg + +local host=${cfg[1]} +local api_version=1.16.1 +local useragent=np-hack +local user=${cfg[2]} +local password=${cfg[3]} +local salt=$(pwgen 20 1) +local token=$(print -n "${password}${salt}" | md5sum | cut -d' ' -f1) + +local response=$(curl --silent \ + "${host}/rest/getNowPlaying?v=${api_version}&c=${useragent}&u=${user}&s=${salt}&t=${token}&f=json") +local entry=$(jq '."subsonic-response".nowPlaying.entry[0]' <<<${response}) +local title=$(jq --raw-output .title <<< ${entry}) +local artist=$(jq --raw-output .artist <<< ${entry}) + +print ${title} – ${artist}