Spotifyd / spotifyd

A spotify daemon
https://spotifyd.rs
GNU General Public License v3.0
9.68k stars 444 forks source link

Notify with Dunst #1239

Closed sownteedev closed 7 months ago

sownteedev commented 7 months ago

Description Notified Dunst but it repeated 3 times when opening a song or there was a new song

Expected behavior I want it just notify 1 time

Compilation flags

Versions (please complete the following information):

This is demo video

https://github.com/Spotifyd/spotifyd/assets/90148193/74ee1b40-0470-4f74-ac5f-a0f6d5ed65c9

This script for spotifyd

[global]
username = "d06xrmq7881id2956cuzz1"
password = "ignore"

# password_cmd = "command_that_writes_password_to_stdout"
# use_keyring = true

# use_mpris = true

# dbus_type = "session"

backend = "pulseaudio"

# device = "alsa_audio_device"  # omit for macOS

audio_format = "S16"

# control = "alsa_audio_device"  # omit for macOS

# mixer = "PCM"  # omit for macOS

# volume_controller = "alsa"  # use softvol for macOS

on_song_change_hook = "~/.config/scripts/songnotify"

device_name = "Spotifyd"
bitrate = 160
cache_path = "/home/sowntee/.cache/spotifyd/"
max_cache_size = 1000000000
no_audio_cache = true
initial_volume = "100"
volume_normalisation = true
normalisation_pregain = -10
# autoplay = true

# zeroconf_port = 1234

# proxy = "http://proxy.example.org:8080"

device_type = "computer"

This is script for notify with Dunst

#!/usr/bin/env bash

songimage=$(playerctl metadata --format "{{ mpris:artUrl }}")
songname=$(playerctl metadata --format "{{ title }}")
song=$(playerctl metadata --format "Artist: {{ artist }}\nAlbum: {{ album }}")

wget -O /tmp/songimage.png $songimage

notify-send -i /tmp/songimage.png "$songname" "$song"

rm /tmp/songimage.png
eladyn commented 7 months ago

Thanks for the report. Your problem is, that the on_song_change_hook isn't only used for sending song change notifications (admittedly a bit counterintuitive). Instead, it fires on a bunch of different events and passes event metadata through via environment variables. So in your case, you should probably do a [ "$PLAYER_EVENT" == "changed" ]. But you can find an unfortunately not very readable list of available envvars here or just play around with env in your hook script yourself.

sownteedev commented 7 months ago

i can't get it. Can u explain ?

sownteedev commented 7 months ago

U mean, it cant solve ?

eladyn commented 7 months ago

No, what I meant is:

To fix your problem, you can just do:

#!/usr/bin/env bash

[ "$PLAYER_EVENT" = "change" ] || [ "$PLAYER_EVENT" = "start" ] || exit 0

songimage=$(playerctl metadata --format "{{ mpris:artUrl }}")
songname=$(playerctl metadata --format "{{ title }}")
song=$(playerctl metadata --format "Artist: {{ artist }}\nAlbum: {{ album }}")

wget -O /tmp/songimage.png $songimage

notify-send -i /tmp/songimage.png "$songname" "$song"

rm /tmp/songimage.png
sownteedev commented 7 months ago

Oh no, it dont notify anything.

eladyn commented 7 months ago

Oh, sorry, should've tested the script before posting it. I edited the message and now it should be working correctly.

I also noticed that there are messages like:

Running "/tmp/tmp.jq4v1DtCuW/notify.sh" using "/usr/bin/fish" with environment variables {"OLD_TRACK_ID": "5viFjDGTnrApmUY5c8qkfw", "PLAYER_EVENT": "change", "TRACK_ID": "61HVbcNeRACZpyvHrc3AnD"}

So you check, how your hook script is being executed.

sownteedev commented 7 months ago

oh cool, thanks for support <3