[GH-ISSUE #190] Player hooks with data arguments #1034

Closed
opened 2026-03-14 13:05:57 +03:00 by kerem · 26 comments
Owner

Originally created by @sewnie on GitHub (May 5, 2023).
Original GitHub issue: https://github.com/aome510/spotify-player/issues/190

Is your feature request related to a problem? Please describe.
Recently, I have stopped using spotify-player simply because libreapot does not has support for external connections such as last.fm, and can not do notifications without Dbus.

Describe the solution you'd like
A hook system that launches a program with arguments set in the configuration for events such as pre, post, during (second interval) for sub-events for playing, pausing, skipping, etc..

I can use these to pass to notification or lastfm scrobller clients.

Describe alternatives you've considered
Using librespot or spotifyd directly, I believe librespot has direct support for this feature, so I don't think it would be trivial to implement it here.

Originally created by @sewnie on GitHub (May 5, 2023). Original GitHub issue: https://github.com/aome510/spotify-player/issues/190 **Is your feature request related to a problem? Please describe.** Recently, I have stopped using spotify-player simply because libreapot does not has support for external connections such as last.fm, and can not do notifications without Dbus. **Describe the solution you'd like** A hook system that launches a program with arguments set in the configuration for events such as pre, post, during (second interval) for sub-events for playing, pausing, skipping, etc.. I can use these to pass to notification or lastfm scrobller clients. **Describe alternatives you've considered** Using librespot or spotifyd directly, I believe librespot has direct support for this feature, so I don't think it would be trivial to implement it here.
kerem 2026-03-14 13:05:57 +03:00
Author
Owner

@sewnie commented on GitHub (Jul 21, 2023):

@aome510 i would like to hear from this.

i am tired of the propietary spotify client.

<!-- gh-comment-id:1644856092 --> @sewnie commented on GitHub (Jul 21, 2023): @aome510 i would like to hear from this. i am tired of the propietary spotify client.
Author
Owner

@aome510 commented on GitHub (Jul 21, 2023):

I've been quite busy lately, so I won't be able to implement this soon. However, will put this up in my TODO list and see look into ways to integrate the last.fm APIs, if any.

<!-- gh-comment-id:1644885021 --> @aome510 commented on GitHub (Jul 21, 2023): I've been quite busy lately, so I won't be able to implement this soon. However, will put this up in my TODO list and see look into ways to integrate the last.fm APIs, if any.
Author
Owner

@sewnie commented on GitHub (Jul 21, 2023):

well, this feature request is for hooks, which is alot simpler than implementing the last.fm API, since that can be handled by another program making the stack simpler.

<!-- gh-comment-id:1645776056 --> @sewnie commented on GitHub (Jul 21, 2023): well, this feature request is for hooks, which is alot simpler than implementing the last.fm API, since that can be handled by another program making the stack simpler.
Author
Owner

@aome510 commented on GitHub (Aug 26, 2023):

Plan to implement this next week or so. Does writing player events in a cache file work? You can write a script to watch for changes in that file every second or so, and port that to last.fm client. Lmk if I need to include any fields other than the event data (I plan to include the timestamp).

<!-- gh-comment-id:1694490988 --> @aome510 commented on GitHub (Aug 26, 2023): Plan to implement this next week or so. Does writing player events in a cache file work? You can write a script to watch for changes in that file every second or so, and port that to last.fm client. Lmk if I need to include any fields other than the event data (I plan to include the timestamp).
Author
Owner

@sewnie commented on GitHub (Aug 26, 2023):

honestly been using the propietary spotify client for a long while now, i'd much rather have librespot itself actually supporting this shit rather than me having to send last.fm api requests constantly

<!-- gh-comment-id:1694495498 --> @sewnie commented on GitHub (Aug 26, 2023): honestly been using the propietary spotify client for a long while now, i'd much rather have librespot itself actually supporting this shit rather than me having to send last.fm api requests constantly
Author
Owner

@aome510 commented on GitHub (Aug 26, 2023):

Just saw this issue: https://github.com/jpochyla/psst/issues/424. Look like lastfm scrobbling is supported via Spotify connect, so it should work by default with spotify_player. I just double check on last.fm website and it shows all the scrobbles when I use spotify_player. Can you confirm? If that's the case, I'll close this issue.

Screenshot 2023-08-26 at 4 32 40 PM
<!-- gh-comment-id:1694496699 --> @aome510 commented on GitHub (Aug 26, 2023): Just saw this issue: https://github.com/jpochyla/psst/issues/424. Look like `lastfm` scrobbling is supported via Spotify connect, so it should work by default with `spotify_player`. I just double check on last.fm website and it shows all the scrobbles when I use `spotify_player`. Can you confirm? If that's the case, I'll close this issue. <img width="1279" alt="Screenshot 2023-08-26 at 4 32 40 PM" src="https://github.com/aome510/spotify-player/assets/40011582/eb4da994-33fd-4d7d-9480-ee0d5bf50a1b">
Author
Owner

@sewnie commented on GitHub (Aug 26, 2023):

Wow, okay!!!! I'll check tommorow!!

I will be very happy if this is true.

<!-- gh-comment-id:1694500425 --> @sewnie commented on GitHub (Aug 26, 2023): Wow, okay!!!! I'll check tommorow!! I will be very happy if this is true.
Author
Owner

@sewnie commented on GitHub (Aug 27, 2023):

image
SEEMS TO WORK!!
although, spotify cant quite see what i'm playing, so that spotify yearly thing wont quite work

<!-- gh-comment-id:1694706617 --> @sewnie commented on GitHub (Aug 27, 2023): ![image](https://github.com/aome510/spotify-player/assets/47404953/792e26b7-5fe6-44ad-81cf-be1bc6ec6afc) SEEMS TO WORK!! although, spotify cant quite see what i'm playing, so that spotify yearly thing wont quite work
Author
Owner

@sewnie commented on GitHub (Aug 27, 2023):

thank u

<!-- gh-comment-id:1694706656 --> @sewnie commented on GitHub (Aug 27, 2023): thank u
Author
Owner

@aome510 commented on GitHub (Aug 27, 2023):

although, spotify cant quite see what i'm playing, so that spotify yearly thing wont quite work

Related https://github.com/librespot-org/librespot/issues/913. That's one thing I miss from the official app and wish that librespot figure out ways to reverse-engineer the feature.

<!-- gh-comment-id:1694726068 --> @aome510 commented on GitHub (Aug 27, 2023): > although, spotify cant quite see what i'm playing, so that spotify yearly thing wont quite work Related https://github.com/librespot-org/librespot/issues/913. That's one thing I miss from the official app and wish that `librespot` figure out ways to reverse-engineer the feature.
Author
Owner

@sewnie commented on GitHub (Aug 27, 2023):

It is a bit infuriating to be honest, considering its been a problem for 4 years and no one had stepped up and reversed engineered it :(

<!-- gh-comment-id:1694729058 --> @sewnie commented on GitHub (Aug 27, 2023): ~~It is a bit infuriating to be honest, considering its been a problem for 4 years and no one had stepped up and reversed engineered it :(~~
Author
Owner

@sewnie commented on GitHub (Aug 31, 2023):

Wait, this issue still remains.

<!-- gh-comment-id:1700951138 --> @sewnie commented on GitHub (Aug 31, 2023): Wait, this issue still remains.
Author
Owner

@sewnie commented on GitHub (Aug 31, 2023):

I do want to have some form of player hooks to be honest; my use case being to avoid constant D-Bus requests.

<!-- gh-comment-id:1700951946 --> @sewnie commented on GitHub (Aug 31, 2023): I do want to have some form of player hooks to be honest; my use case being to avoid constant D-Bus requests.
Author
Owner

@aome510 commented on GitHub (Sep 2, 2023):

I do want to have some form of player hooks to be honest; my use case being to avoid constant D-Bus requests.

Does writing player events into a file work? I'm not too familiar with the player hook concept and how to implement one.

<!-- gh-comment-id:1703956216 --> @aome510 commented on GitHub (Sep 2, 2023): > I do want to have some form of player hooks to be honest; my use case being to avoid constant D-Bus requests. Does writing player events into a file work? I'm not too familiar with the player hook concept and how to implement one.
Author
Owner

@sewnie commented on GitHub (Sep 3, 2023):

Player hooks is to launch a program with certain metadata (such as song, album, title) as arguments, on certain events (such as play, new song, pause, etc)

<!-- gh-comment-id:1703993647 --> @sewnie commented on GitHub (Sep 3, 2023): Player hooks is to launch a program with certain metadata (such as song, album, title) as arguments, on certain events (such as play, new song, pause, etc)
Author
Owner

@aome510 commented on GitHub (Sep 3, 2023):

Implemented in #244. Refer to https://github.com/aome510/spotify-player/blob/add-player-hook/docs/config.md#player-event-hook-command for how to use the command.

<!-- gh-comment-id:1704406014 --> @aome510 commented on GitHub (Sep 3, 2023): Implemented in #244. Refer to https://github.com/aome510/spotify-player/blob/add-player-hook/docs/config.md#player-event-hook-command for how to use the command.
Author
Owner

@sewnie commented on GitHub (Sep 4, 2023):

why json? :(

<!-- gh-comment-id:1704546428 --> @sewnie commented on GitHub (Sep 4, 2023): why json? :(
Author
Owner

@aome510 commented on GitHub (Sep 4, 2023):

why json? :(

for consistency with CLI commands' output and because the app already supports exporting Spotify data in JSON format.

<!-- gh-comment-id:1705149411 --> @aome510 commented on GitHub (Sep 4, 2023): > why json? :( for consistency with CLI commands' output and because the app already supports exporting Spotify data in JSON format.
Author
Owner

@sewnie commented on GitHub (Sep 4, 2023):

Why not ususe JSON for big Spotify data? For example for simple data it should simply be it in plain text, and the arguments to be passed as the arguments themselves:

script "Playing" "Artist" "Album" "Song", this ensures that scripting is very easy. I'd appreciate it if you did this as this is what I had expected..

<!-- gh-comment-id:1705206532 --> @sewnie commented on GitHub (Sep 4, 2023): Why not ususe JSON for big Spotify data? For example for simple data it should simply be it in plain text, and the arguments to be passed as the arguments themselves: `script "Playing" "Artist" "Album" "Song"`, this ensures that scripting is very easy. I'd appreciate it if you did this as this is what I had expected..
Author
Owner

@sewnie commented on GitHub (Sep 7, 2023):

I can't use this feature; setting player_event_hook_command to a valid binary path gives: player_event_hook_command: None.

player_event_hook_command = "spotify_player-hook"
2023-09-07T16:28:20.475855Z  INFO spotify_player: General configurations: AppConfig { theme: "sewn", client_id: "XXXXXXXXXXXXXXXXXXXXX", client_port: 8080, copy_command: Command { command: "xclip", args: ["-sel", "c"] }, player_event_hook_command: None, playback_format: "{track}\n{artists} - {album}\n{metadata}"...
<!-- gh-comment-id:1710456424 --> @sewnie commented on GitHub (Sep 7, 2023): I can't use this feature; setting `player_event_hook_command` to a valid binary path gives: `player_event_hook_command: None`. ```toml player_event_hook_command = "spotify_player-hook" ``` ``` 2023-09-07T16:28:20.475855Z INFO spotify_player: General configurations: AppConfig { theme: "sewn", client_id: "XXXXXXXXXXXXXXXXXXXXX", client_port: 8080, copy_command: Command { command: "xclip", args: ["-sel", "c"] }, player_event_hook_command: None, playback_format: "{track}\n{artists} - {album}\n{metadata}"... ```
Author
Owner

@aome510 commented on GitHub (Sep 7, 2023):

Please refer to the linked document to use a correct format. It should be player_event_hook_command = { command = "spotify_player-hook", args = [] }

Regarding why JSON but not plain text with arguments,

  1. different events have different fields, passing the fields as command's arguments simply does not scale.
  2. script can be arbitrarily complexed as user wants, the passing data to the script logic from spotify_player side is not. As a result, the passing data logic should be simple (e.g passing the event as a single input).
<!-- gh-comment-id:1710521745 --> @aome510 commented on GitHub (Sep 7, 2023): Please refer to the linked document to use a correct format. It should be `player_event_hook_command = { command = "spotify_player-hook", args = [] }` Regarding why JSON but not plain text with arguments, 1. different events have different fields, passing the fields as command's arguments simply does not scale. 2. script can be arbitrarily complexed as user wants, the passing data to the script logic from `spotify_player` side is not. As a result, the passing data logic should be simple (e.g passing the event as a **single** input).
Author
Owner

@sewnie commented on GitHub (Sep 7, 2023):

different events have different fields, passing the fields as command's arguments simply does not scale.

#!/bin/sh

echo "command: $1"

case "$1" in
        Changed) echo "old_track_id: $3, new_track_id: $3" ;;
        Playing) echo "track_id: $2, position_ms: $3, duration_ms: $4" ;;
        Paused) echo "track_id: $2, position_ms: $3, duration_ms: $4" ;;
        EndOfTrack) echo "track_id: $2" ;;
esac

I hightly suggest to you to please use a arguement system, as it makes my life and others much easier when scripting for spotify-player.

<!-- gh-comment-id:1710526498 --> @sewnie commented on GitHub (Sep 7, 2023): > different events have different fields, passing the fields as command's arguments simply does not scale. ```sh #!/bin/sh echo "command: $1" case "$1" in Changed) echo "old_track_id: $3, new_track_id: $3" ;; Playing) echo "track_id: $2, position_ms: $3, duration_ms: $4" ;; Paused) echo "track_id: $2, position_ms: $3, duration_ms: $4" ;; EndOfTrack) echo "track_id: $2" ;; esac ``` I hightly suggest to you to please use a arguement system, as it makes my life and others much easier when scripting for spotify-player.
Author
Owner

@aome510 commented on GitHub (Sep 7, 2023):

I hightly suggest to you to please use a arguement system, as it makes my life and others much easier when scripting for spotify-player.

Ok, I'll think about it.

<!-- gh-comment-id:1710535095 --> @aome510 commented on GitHub (Sep 7, 2023): > I hightly suggest to you to please use a arguement system, as it makes my life and others much easier when scripting for spotify-player. Ok, I'll think about it.
Author
Owner

@aome510 commented on GitHub (Sep 7, 2023):

Just a note that with the arguments approach, new user will be confused between the arguments, e.g is it Changed old_track_id new_track_id or Changed new_track_id old_track_id? Then they are required to actually read the document, which many don't usually.

<!-- gh-comment-id:1710538814 --> @aome510 commented on GitHub (Sep 7, 2023): Just a note that with the arguments approach, new user will be confused between the arguments, e.g is it `Changed old_track_id new_track_id` or `Changed new_track_id old_track_id`? Then they are required to actually read the document, which many don't usually.
Author
Owner

@sewnie commented on GitHub (Sep 7, 2023):

Well? They need to read the docs to understand what the hooks do, their arguments and commands to begin with.

<!-- gh-comment-id:1710549757 --> @sewnie commented on GitHub (Sep 7, 2023): Well? They need to read the docs to understand what the hooks do, their arguments and commands to begin with.
Author
Owner

@aome510 commented on GitHub (Sep 10, 2023):

Should be updated with https://github.com/aome510/spotify-player/pull/251.

<!-- gh-comment-id:1712705338 --> @aome510 commented on GitHub (Sep 10, 2023): Should be updated with https://github.com/aome510/spotify-player/pull/251.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-player#1034
No description provided.