Skip to content

Conversation

@aome510
Copy link
Owner

@aome510 aome510 commented Mar 18, 2023

Resolves #111.
Partially #103.

Changes

Added CLI commands and subcommands

  • get:
Get spotify data

Usage: spotify_player get <COMMAND>

Commands:
  key      Get data by key
  context  Get context data
  help     Print this message or the help of the given subcommand(s)

Options:
  -h, --help  Print help
  • get key:
Get data by key

Usage: spotify_player get key <key>

Arguments:
  <key>  [possible values: playback, devices, user-playlists, user-liked-tracks, user-saved-albums, user-followed-artists, user-top-tracks, queue]

Options:
  -h, --help  Print help
  • get context
Get context data

Usage: spotify_player get context <context_type> <context_id>

Arguments:
  <context_type>  [possible values: playlist, album, artist]
  <context_id>

Options:
  -h, --help  Print help
  • playback
Interact with the playback

Usage: spotify_player playback <COMMAND>

Commands:
  play      Start a playback
  resume    Resume the playback
  pause     Pause the playback
  next      Next track
  previous  Previous track
  shuffle   Toggle the shuffle mode
  repeat    Cycle the repeat mode
  volume    Set playback's volume percentage
  seek      Seek the playback by an offset
  help      Print this message or the help of the given subcommand(s)

Options:
  -h, --help  Print help

@aome510
Copy link
Owner Author

aome510 commented Mar 18, 2023

@apprehensions @diegoulloao, sorry for the long delay. I've added several CLI commands to spotify-player. Can you guys try them out? Any suggestions on additional commands to add?

You can run --help for each command/subcommand to see the usage.

@diegoulloao
Copy link

Man this is amazing! Just now I'm tied up with tasks but I'm going study the CLI on the next weekend and I'll quickly test it in the next days. From next weekend I'm going to start coding some little tests from a brand new neovim plugin.

I want to thank you for this, it opens a lot of doors.

Any other missed command or idea I'll let you know of course.
We're in touch 🚀 .

@sewnie
Copy link
Contributor

sewnie commented Mar 19, 2023

  1. play doesn't seem to make sense for me, as it requires 'context' types and ids, when it should just send the 'play' (toggle) command by itself, similar to pause, resume, next, previous.
  2. play and pause should be merged into one seperate command, as a toggle.
  3. the commands are pretty damn slow.
  4. error: invalid value '100' for '<percent>': 100 is not in 0..100
  5. init_get_subcommand or spotify_player playback data should really be implemented
  6. spotify-player via bash/CLI #135 as spotify_player playback play?????? idk, maybe thats what play is for.

misc: solves #77 as spotify_player playback volume

@aome510
Copy link
Owner Author

aome510 commented Mar 19, 2023

  1. play doesn't seem to make sense for me, as it requires 'context' types and ids, when it should just send the 'play' (toggle) command by itself, similar to pause, resume, next, previous.
  2. play and pause should be merged into one seperate command, as a toggle.
  3. the commands are pretty damn slow.
  4. error: invalid value '100' for '<percent>': 100 is not in 0..100
  5. init_get_subcommand or spotify_player playback data should really be implemented
  6. spotify-player via bash/CLI #135 as spotify_player playback play?????? idk, maybe thats what play is for.

misc: solves #77 as spotify_player playback volume

Updated 2 and 4.

1 ....
6 ...

play is intended for playing a new playlist/album or so. The toggle command is now updated to resume-pause, hope that it makes more sense now.

3 ...

Yeah, I'm aware of this problem as the CLI code still shares some startup codes as the normal app. It can be optimized ofc, but I'm not too sure about the improvement. Now, FYI, running spotify_player playback resume-pause took 27ms in my laptop. What commands do you feel slow and how slow?

5 ...

I don't get what you meant here, can you elaborate?

@sewnie
Copy link
Contributor

sewnie commented Mar 19, 2023

play is intended for playing a new playlist/album or so. The toggle command is now updated to resume-pause, hope that it makes more sense now.

i suggest renaming it to play-pause, similar to playerctl.

Updated 2 and 4.

sorry, i think i worded incorrectly; i said as one external command, not to replace them. i think some scripting users might be a little bit upset but this technically doesnt hurt when 5 is implemented

running spotify_player playback resume-pause took 27ms

~/.local/src/spotify-player/target/release $ time ./spotify_player playback next
real    0m 3.35s
user    0m 0.03s
sys     0m 0.00s
~/.local/src/spotify-player/target/release $ time ./spotify_player playback previous
real    0m 3.52s
user    0m 0.03s
sys     0m 0.01s
~/.local/src/spotify-player/target/release $ time ./spotify_player playback shuffle
real    0m 3.38s
user    0m 0.02s
sys     0m 0.01s
~/.local/src/spotify-player/target/release $ time ./spotify_player playback seek +10
real    0m 3.28s
user    0m 0.03s
sys     0m 0.01s
~/.local/src/spotify-player/target/release $ time ./spotify_player playback resume-pause
real    0m 3.19s
user    0m 0.03s
sys     0m 0.00s

5 ...

I don't get what you meant here, can you elaborate?

λ spt playback
🔀 ▶ Warakumbla - Hypothermia

via the function (or similar) init_get_subcommand

@aome510
Copy link
Owner Author

aome510 commented Mar 19, 2023

i suggest renaming it to play-pause, similar to playerctl.

updated. Also change play command to start.

λ spt playback
🔀 ▶ Warakumbla - Hypothermia

via the function (or similar) init_get_subcommand

By writing a script, you can get the same thing with spotify_player get key playback. For example, one way to print very basic playback information using jq:

spotify_player get key playback \ 
| jq '[.repeat_state, .shuffle_state, .item.name, .item.album.name, ([.item.artists[].name] | join(", "))] | join("-")'

@aome510
Copy link
Owner Author

aome510 commented Mar 19, 2023

~/.local/src/spotify-player/target/release $ time ./spotify_player playback next
real    0m 3.35s
user    0m 0.03s
sys     0m 0.00s
~/.local/src/spotify-player/target/release $ time ./spotify_player playback previous
real    0m 3.52s
user    0m 0.03s
sys     0m 0.01s
~/.local/src/spotify-player/target/release $ time ./spotify_player playback shuffle
real    0m 3.38s
user    0m 0.02s
sys     0m 0.01s
~/.local/src/spotify-player/target/release $ time ./spotify_player playback seek +10
real    0m 3.28s
user    0m 0.03s
sys     0m 0.01s
~/.local/src/spotify-player/target/release $ time ./spotify_player playback resume-pause
real    0m 3.19s
user    0m 0.03s
sys     0m 0.00s

Look like a big time difference between yours and mine, I'll try to run it on my older machine to see if I have the same result.

@sewnie
Copy link
Contributor

sewnie commented Mar 19, 2023

I'll try to run it on my older machine

i have a 20 thread cpu................

@aome510
Copy link
Owner Author

aome510 commented Mar 19, 2023

I'll try to run it on my older machine

i have a 20 thread cpu................

Okay, so something must be wrong here xD. Will try to figure it out.

@sewnie
Copy link
Contributor

sewnie commented Mar 23, 2023

is it possible, that spotify-player, if it is already running, to access its own MPRIS data? this can give a significant speed boost when querying its metadata; since spotify_player (presumably) will request spotify api.

this is equivalent to querying its data with playerctl.

@aome510
Copy link
Owner Author

aome510 commented Mar 26, 2023

Look like a big time difference between yours and mine, I'll try to run it on my older machine to see if I have the same result.

Actually, not much of a difference. I just overlooked the real time and looked at usr and sys instead. Here are the results running playback shuffle 5 times on my machine.

________________________________________________________
Executed in    1.61 secs      fish           external
   usr time   26.65 millis    0.11 millis   26.54 millis
   sys time   20.89 millis    3.30 millis   17.59 millis


________________________________________________________
Executed in    1.05 secs      fish           external
   usr time   24.91 millis    0.07 millis   24.84 millis
   sys time   16.85 millis    1.47 millis   15.38 millis


________________________________________________________
Executed in    1.50 secs      fish           external
   usr time   26.36 millis    0.11 millis   26.25 millis
   sys time   20.27 millis    2.22 millis   18.05 millis


________________________________________________________
Executed in    1.68 secs      fish           external
   usr time   27.78 millis    0.10 millis   27.68 millis
   sys time   19.86 millis    2.06 millis   17.80 millis


________________________________________________________
Executed in    1.44 secs      fish           external
   usr time   24.93 millis    0.08 millis   24.84 millis
   sys time   17.96 millis    1.71 millis   16.25 millis

I took a deeper look, it seemed the bottleneck is session initialization (~1s on each run). This session is required to send a spotify API and cannot be optimized as far as I understand.

Another approach is setting IPC between the CLI program and a running spotify_player, which is more complicated but probably faster as it doesn't involve session initialization.

@sewnie
Copy link
Contributor

sewnie commented Mar 26, 2023

Another approach is setting IPC between the CLI program and a running spotify_player, which is more complicated but probably faster as it doesn't involve session initialization.

I still suggest having to self-request MPRIS data, as it's very simple and isn't over-engineered as MPRIS is going to be equivalent of what the IPC would provide, mainly because D-Bus is a huge IPC lol.

I still suggest having to self-request MPRIS data

About this, i suggest having the old method of needing session initialization when there is no D-Bus feature built with spotify-player, or when there is no device of spotify-player running already.

@aome510
Copy link
Owner Author

aome510 commented Mar 26, 2023

I still suggest having to self-request MPRIS data, as it's very simple and isn't over-engineered as MPRIS is going to be equivalent of what the IPC would provide, mainly because D-Bus is a huge IPC lol.

The problem is that not all spotify data is encoded in MPRIS data and MPRIS only works on Linux.

About this, i suggest having the old method of needing session initialization when there is no D-Bus feature built with spotify-player, or when there is no device of spotify-player running already.

Feels too hacky to me tbh.

@sewnie
Copy link
Contributor

sewnie commented Mar 26, 2023

The problem is that not all spotify data is encoded in MPRIS data and

The MPRIS from spotify-player is enough.

MPRIS only works on Linux.

You would still have to implement a way to use them on other operating systems? unless there is a library of course.

Feels too hacky to me tbh.

Meh.

@sewnie
Copy link
Contributor

sewnie commented Apr 9, 2023

hi is there anything new about this or is it still being developed?

@aome510
Copy link
Owner Author

aome510 commented Apr 9, 2023

@apprehensions I’m quite busy recently because of school. Will get back to this later this month

@cheyngoodman
Copy link

I'm new to spotify_player, I've recently suggested these commands for spotify-tui:

  • Play "Like Songs" without knowing or looking up the ID: spotify_player play --liked
  • Increase or decrease volume by a percentage, instead of exact value: spotify_player playback --volume +5

By default I usually listen to my liked songs on shuffle so the first command is useful. For volume, the feature is on Android allowing the volume rocker to increase/decrease the volume of other devices Spotify playback. It would allow me to bind scroll wheel + button to turn up or down Spotfy volume.

@cheyngoodman
Copy link

I'm also realizing the ability to "like" and "unlike" a track are missing from the cli. Something similar to these commands might be helpful:

  • Add current song to Liked Songs: spotify_player playback like
  • Add or remove current song from Liked Songs: spotify_player playback like --toggle
  • Remove current song from Liked Songs: spotify_player playback like --remove

This would allow me to add a new song to my Liked Songs with a window manager key bind.

Another feature that would be nice but might be asking a lot would be to start playing a Artist / Album / Track Radio using a CLI command.

An example command could be: spotify_player playback play --radio=<artist_album_or_track_uri>

This might help to explore new music and pair with the like command to accumulate new liked tracks.

@aome510
Copy link
Owner Author

aome510 commented Apr 21, 2023

@apprehensions updated the codes to use socket programming for IPCs. Running the commands should be much faster now.

@aome510
Copy link
Owner Author

aome510 commented Apr 23, 2023

@apprehensions can you confirm if the new changes improve the CLI performance?

@cheyngoodman cheyngoodman mentioned this pull request Apr 23, 2023
@aome510 aome510 merged commit 9b6dcc9 into master Apr 26, 2023
@aome510
Copy link
Owner Author

aome510 commented Apr 26, 2023

I'm new to spotify_player, I've recently suggested these commands for spotify-tui:

  • Play "Like Songs" without knowing or looking up the ID: spotify_player play --liked
  • Increase or decrease volume by a percentage, instead of exact value: spotify_player playback --volume +5

By default I usually listen to my liked songs on shuffle so the first command is useful. For volume, the feature is on Android allowing the volume rocker to increase/decrease the volume of other devices Spotify playback. It would allow me to bind scroll wheel + button to turn up or down Spotfy volume.

I'll merge the PR for now as it's first iteration of the app's CLI commands. Additional commands/features can be implemented in a follow-up PR.

@aome510 aome510 deleted the implement-app-api branch April 26, 2023 18:12
@sewnie
Copy link
Contributor

sewnie commented Aug 31, 2023

@aome510 i noticed you're using network sockets for requests? i don't know what exactly this is, but retrieving playback data takes a while:

real    0m 0.41s

i sort of expected it to be somewhat instant, maybe try using a FIFO? or IPC?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API for consume/dispatch actions from third-party applications

5 participants