aome510 / spotify-player

A Spotify player in the terminal with full feature parity
MIT License
3.41k stars 149 forks source link

Print `Artist - Song` after using CLI to control playback #294

Closed catgoose closed 9 months ago

catgoose commented 10 months ago

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
aome510 commented 10 months ago

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.

ed9w2in6 commented 9 months ago

@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

apprehensions commented 9 months ago

or:

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

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)"'