[GH-ISSUE #294] Print Artist - Song after using CLI to control playback #1090

Closed
opened 2026-03-14 13:25:20 +03:00 by kerem · 4 comments
Owner

Originally created by @catgoose on GitHub (Nov 16, 2023).
Original GitHub issue: https://github.com/aome510/spotify-player/issues/294

Related to #279

When using spotify_player playback next|previous I would like it if spotify_player would output the song that was switched to. This should only print if there is no active spotify_player instance.

For example:

❯ spotify_player playback next
Artist - Song
Originally created by @catgoose on GitHub (Nov 16, 2023). Original GitHub issue: https://github.com/aome510/spotify-player/issues/294 Related to #279 When using `spotify_player playback next|previous` I would like it if `spotify_player` would output the song that was switched to. This should only print if there is no active `spotify_player` instance. For example: ``` ❯ spotify_player playback next Artist - Song ```
kerem 2026-03-14 13:25:20 +03:00
Author
Owner

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

This is difficult to do because it takes time for Spotify API to show up the changed playback. In other words, calling current_playback API after next API can give you the previous track. I would suggest you use a separate command (e.g get key playback to get the playback instead.

<!-- gh-comment-id:1820087129 --> @aome510 commented on GitHub (Nov 21, 2023): This is difficult to do because it takes time for Spotify API to show up the changed playback. In other words, calling `current_playback` API after `next` API can give you the previous track. I would suggest you use a separate command (e.g `get key playback` to get the playback instead.
Author
Owner

@ed9w2in6 commented on GitHub (Nov 29, 2023):

@catgoose This is how you can do it with get key playback:

spotify_player get key playback \
  | python3 -c 'import sys; import json; detail=json.loads(sys.stdin.read())["item"]; track=detail["name"]; album=detail["album"]["name"]; artists=", ".join([a["name"] for a in detail["artists"]]); link=detail["external_urls"]["spotify"]; print(f"\n{track} ∈ {album}\nby {artists}\n{link}")'

For future reference:
spotify-tui implemented this here, I believe it does not avoid the issue @aome510 mentioned as there is a short lag (few ms) when using this:
https://github.com/Rigellute/spotify-tui/blob/master/src/cli/cli_app.rs#L393

It also shows if current playback is liked or not using current_user_saved_tracks_contains, in which we used for add to library function:

github.com/aome510/spotify-player@e25c701f21/spotify_player/src/client/mod.rs (L959)

<!-- gh-comment-id:1831581074 --> @ed9w2in6 commented on GitHub (Nov 29, 2023): @catgoose This is how you can do it with `get key playback`: ``` spotify_player get key playback \ | python3 -c 'import sys; import json; detail=json.loads(sys.stdin.read())["item"]; track=detail["name"]; album=detail["album"]["name"]; artists=", ".join([a["name"] for a in detail["artists"]]); link=detail["external_urls"]["spotify"]; print(f"\n{track} ∈ {album}\nby {artists}\n{link}")' ``` For future reference: `spotify-tui` implemented this here, I believe it does not avoid the issue @aome510 mentioned as there is a short lag (few ms) when using this: https://github.com/Rigellute/spotify-tui/blob/master/src/cli/cli_app.rs#L393 It also shows if current playback is liked or not using `current_user_saved_tracks_contains`, in which we used for add to library function: https://github.com/aome510/spotify-player/blob/e25c701f218a1057ea0e1c996cf20af06f7891e5/spotify_player/src/client/mod.rs#L959
Author
Owner

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

or:

spotify_player get key playback | jq -r '.item | "\(.artists | map(.name) | join(", ")) - \(.name)"'
<!-- gh-comment-id:1837478915 --> @sewnie commented on GitHub (Dec 3, 2023): or: ``` spotify_player get key playback | jq -r '.item | "\(.artists | map(.name) | join(", ")) - \(.name)"' ```
Author
Owner

@catgoose commented on GitHub (Dec 6, 2023):

or:

spotify_player get key playback | jq -r '.item | "\(.artists | map(.name) | join(", ")) - \(.name)"'

Thanks this works for me. I can do:

spotify_player playback previous && spotify_player get key playback | jq -r '.item | "\(.artists | map(.name) | join(", ")) - \(.name)"'
<!-- gh-comment-id:1842966175 --> @catgoose commented on GitHub (Dec 6, 2023): > or: > > ``` > spotify_player get key playback | jq -r '.item | "\(.artists | map(.name) | join(", ")) - \(.name)"' > ``` Thanks this works for me. I can do: ``` spotify_player playback previous && spotify_player get key playback | jq -r '.item | "\(.artists | map(.name) | join(", ")) - \(.name)"' ```
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#1090
No description provided.