cfangmeier / tuijam

A fancy TUI client for Google Play Music
MIT License
129 stars 9 forks source link

MPRIS integration #12

Closed rosshadden closed 6 years ago

rosshadden commented 6 years ago

Do you have any plans to make tuijam work with the MPRIS D-Bus spec, which would let us use playerctl and similar programs?

Not only would this let users control playback externally, but it would allow for showing track, artist, state, etc. externally as well (such as in polybar or i3bar).

cfangmeier commented 6 years ago

I didn't have plans for this (nor did I know anything about MPRIS), but it sounds like a very useful feature!

I found a python wrapper for D-Bus, pydbus, which should reduce the problem to just rigging up the appropriate D-Bus paths to call a few functions in TUIJam.

I have a bit of time today so I'll give it a shot and see if I can get it working with playerctl and push what I have into a dev branch.

Would you be willing to test out the result on your machine?

rosshadden commented 6 years ago

Yeah of course. Thank you.

cfangmeier commented 6 years ago

Alright, I believe I've got it working. Checkout the mpris branch to try it out. On my machine, I am able to query the status, set play/pause, and get some metadata for the current song using playerctl. For example,

caleb@narsil ~
> $ playerctl -p tuijam metadata
{'mpris:trackid': <'Tbgjybvtdkktneyurpnpztidcby'>, 'xesam:title': <'Salt + Charcoal'>, 'xesam:artist': <'Plini'>, 'xesam:album': <'Sunhead'>}

Let me know what does/doesn't work for you and if there are any missing features you would like to see.

rosshadden commented 6 years ago

It works!

I did find a couple weird things:

  1. Switching to the next track works, but previous doesn't
  2. Pausing works, but playing afterward doesn't (not sure if that's in your control, and it also doesn't matter to me since play-pause works great)
  3. Same thing with stopping. It works, but playing afterward doesn't start the song over. It errors instead.

But everything you mentioned is working as well. Actually on a related note to 1., I just realized there is no default shortcut for previous track. I'll probably make a separate issue for this and maybe add it myself if I get a chance.

rosshadden commented 6 years ago

Thank you so much for working on this, by the way. I have tried many Google Music CLI clients. My favorite workflow was mopidy+gmusicproxy+ncmpcpp, but it stopped working after a year of using it, and despite many hours and days of troubleshooting (often while bored at work) I never figured it out. This project is definitely far better than any others I have tried (with the exception of the aforementioned now nonworking one, if only because ncmpcpp is such a popular and powerful music client), and I am excited to be able to play Google Music through the terminal again.

And thanks for your quick response and work on the MPRIS stuff.

cfangmeier commented 6 years ago
  1. Switching to the next track works, but previous doesn't

This is an artifact of how the playlist is implemented. After a song is played, it is discarded from the playlist. You can see visually how this works in the UI. Although this isn't quite true as I also keep a separate list of recently played songs viewable via the ctrl-r shortcut. So one could implement a "previous" feature by grabbing the last song from the recently played list.

  1. Pausing works, but playing afterward doesn't (not sure if that's in your control, and it also doesn't matter to me since play-pause works great)

The play command in MPRIS is a bit weird in that it appears to really mean "start playing song X", and not "continue playing the current song" so you would supply the play command some sort of song id and it would play that song. Since I'm not supporting the MPRIS playlist feature (yet), this feature doesn't really make much sense so I just rigged it up to ignore the supplied song id and do the same thing as play-pause.

  1. Same thing with stopping. It works, but playing afterward doesn't start the song over. It errors instead.

This should be fixed now with my last commit.

Thank you so much for working on this, by the way. I have tried many Google Music CLI clients. My favorite workflow was mopidy+gmusicproxy+ncmpcpp, but it stopped working after a year of using it, and despite many hours and days of troubleshooting (often while bored at work) I never figured it out. This project is definitely far better than any others I have tried (with the exception of the aforementioned now nonworking one, if only because ncmpcpp is such a popular and powerful music client), and I am excited to be able to play Google Music through the terminal again.

And thanks for your quick response and work on the MPRIS stuff.

Thanks! Before TUIJam, I went through a bunch of setups, motivated mostly by the web player being super resource hungry on my crappy laptop. My favorite was gpymusic, but it lacked some features I wanted (nicer UI mostly) and all of the other solutions (like the setup you mention) had too much manual tinkering for my taste.

Try out the latest version when you have time, and if everything appears to work good enough, I'll merge this into master and update the README.

rosshadden commented 6 years ago

Your changes work great, thank you.

cfangmeier commented 6 years ago

merged!