diff --git a/.gitignore b/.gitignore index d5f94ab..f4ed728 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,4 @@ nvim/plugin alacritty/themes myzsh +ncspot/userstate.cbor diff --git a/ncspot/config.toml b/ncspot/config.toml new file mode 100644 index 0000000..23d6dcd --- /dev/null +++ b/ncspot/config.toml @@ -0,0 +1,4 @@ +notify=false + +[notification_format] +body = "%album\n%artists" diff --git a/ncspot/playerctl_notifier.sh b/ncspot/playerctl_notifier.sh new file mode 100755 index 0000000..8438385 --- /dev/null +++ b/ncspot/playerctl_notifier.sh @@ -0,0 +1,27 @@ +killall -q playerctl +# delete all the copied image files first +find "$HOME/.cache/ncspot/" -type f -exec sh -c 'file -b --mime-type "$0" | grep -q "^image/" && rm "$0"' {} \; +playerctl metadata --follow --format '{{ mpris:trackid }}' | while read -r line; do + title=$(playerctl metadata title) + album=$(playerctl metadata album) + artist=$(playerctl metadata artist) + art_url=$(playerctl metadata mpris:artUrl) + ap="${art_url##*/}" + + if [[ -n $ap ]]; then + cfp="$HOME/.cache/ncspot/covers/$ap" + + until [ -e $cfp ]; do + sleep 1 + done + MIME_TYPE=$(file -b --mime-type "$cfp") + SUB_TYPE=$(echo "$MIME_TYPE" | cut -d'/' -f2) + curr_dir="$HOME/.cache/ncspot" + nfp="$curr_dir/$ap.$SUB_TYPE" + cp $cfp $nfp + + # Extract the subtype (e.g., "jpeg", "plain") + SUB_TYPE=$(echo "$MIME_TYPE" | cut -d'/' -f2) + notify-send -a ncspot "$title" "$album\n$artist" --hint=string:image-path:$nfp --icon "/usr/share/icons/Papirus-Dark/24x24/devices/audio-speakers.svg" + fi +done diff --git a/zshrc b/zshrc index 9360c56..a2504b2 100644 --- a/zshrc +++ b/zshrc @@ -16,9 +16,10 @@ source $ZSH/oh-my-zsh.sh export LANG=en_US.UTF-8 export EDITOR='nvim' -export VISUAL='nvim' +export VISUAL='nvim-qt' alias vim='nvim' alias ws='web_search' +alias ncspot='~/.config/ncspot/playerctl_notifier.sh & ncspot' zstyle ':completion:*' completer _complete _approximate zstyle ':completion:*' group-name ''