spotifyd icon indicating copy to clipboard operation
spotifyd copied to clipboard

[Feature Request] Add TRACK_NAME, ARTIST_NAME env vars when calling on_song_change_hook

Open ceuk opened this issue 6 years ago • 7 comments

Hey,

Trying to implement song change notifications currently requires fetching the track info via playerctl or a similar method (unless I'm missing something) - which can be problematic (see: #337 #503).

Spotifyd already sets two env vars (TRACK_ID and PLAYER_EVENT).

Would it be viable to add more information about the track in context? It seems to make sense from a design perspective to provide this when running the hook and would have the advantage of simplifying common uses of the hook (e.g. generating notifications and I imagine many others).

Huge appreciation for all your work and thanks for reading :)

ceuk avatar Feb 25 '20 20:02 ceuk

Had a look at the source code and it looks like the event (and available parameters) are basically just being proxied from Librespot. So I guess the change would have to be made upstream first?

I'll raise an issue there too and reference this issue.

ceuk avatar Feb 27 '20 21:02 ceuk

Quick update on this: looking back at previous discussions over on Librespot, it looks like they're generally against exposing metadata from a design POV to keep the core library uncluttered. As such, they would suggest it should be something that daemons such as Spotifyd handle.

Perhaps we could use the TRACK_ID provided by the subprocess to fetch some song metadata manually?

ceuk avatar Apr 22 '20 11:04 ceuk

Perhaps we could use the TRACK_ID provided by the subprocess to fetch some song metadata manually?

Apparently using Spotify Web API is not ideal as that would require an API key, I figured out a hacky way that uses the spotify player page, by accessing https://open.spotify.com/track/$TRACK_ID, some metadata like title and author can be extracted directly from the meta tags using regex. A short demo:

curl -s https://open.spotify.com/track/$1 > .spotmeta.temp

TITLE=$(grep -o -P "(?<=<meta property=\"twitter:title\" content=\").*?(?=\" \/>)" .spotmeta.temp)
AUTHOR=$(grep -o -P "(?<=<meta property=\"twitter:audio:artist_name\" content=\").*?(?=\" \/>)" .spotmeta.temp)```

dheatovwil avatar Apr 24 '20 17:04 dheatovwil

#452 over on Librespot has been finalized/merged sans Track Name which pretty much puts to bed (for the foreseeable at least) the hope that we can get easy access to the metadata from there.

Given the apparent complexities of fetching the metadata from within Spotifyd, that really leaves the maintainers with the decision of whether or not they feel a fairly opinionated module (that likely requires API keys as @dheatovwil mentions) is appropriate/belongs within the Spoftifyd daemon.

ceuk avatar May 29 '20 22:05 ceuk

It's a workaround but it works quite good. I use mpris to locally fetch metadata in hooked software (it shows notification).

ejiektpobehuk avatar Nov 27 '20 23:11 ejiektpobehuk

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 25 '21 23:02 stale[bot]