Open patrickbolle opened 2 years ago
@patrickbolle This feature is actually included already, but it's kind of experimental and I don't really call it out in the documentation. But if you start the script with -f, it will dump all of the song titles to the file /tmp/somafm_tracks.txt (or wherever temporary files are on your OS). If you're pulling the script from Git (rather than downloading it via pip), you can change the location of this file on line 68.
I used this to show track info from within the i3 window manager with a simple script, but if it's something other people would find useful, it could certainly be polished up a bit.
P.S. Sorry for the delay in responding, for some reason I never get email notifications for new Issues of my own repos, still trying to figure out what the problem is.
I was also interested in the specific functionality OP is looking for. I think the key bit is the "push a button to save the current song". It's akin to the "love/thumbsup" functionality found on streaming services.
My use case is that sometimes I hear some great new artist that I want to look into later more deeply. Having a list of every song is not all that helpful for this as I probably won't remember specifically which songs I liked. A text or json or whatever file with just the liked ones though would be ideal.
I did look briefly into doing this but it would be invasive on a technical level, we would need to add an additional thread or multiprocessing to handle UI inputs. I'm happy to do it but it's such an big change I imagine I'll architect it in a different way to how you would - if you would like to me to anyway, let me know and if you've got some thoughts on how.
I was thinking of keeping something similar to what is there now, but the display functionality of streamInfo is moved into it's own thread. The "main" thread now pumps the line info through a queue into streamInfo. Still need to solve keypress handling though, so possibly it would be easier using something like Textualize (heavy dependency though).
Yeah, it would be tricky to capture key presses with the way things work now. Anything that seems like interactivity (such as changing the volume or quitting the player) aren't actually being done by the script, but it's the background player reacting to the input.
I wouldn't be against trying to implement something like this, but it would have to be optional. I don't want to get into a situation where a UI framework is a required dependency just for one feature.
So I actually had a bit of inspiration last night, and figured out how to implement this in a fairly straightforward way, although as of right now it only works when using MPlayer as the backend.
Basically, going on the idea that all the key presses are being passed to MPlayer invisibly and the script is just looking for strings in the output, I started pressing keys and looking to see if there was something we could latch onto for a feature like this. As luck would have it MPlayer has a capture option that's triggered by pressing C, but since it's not configured on the command line, it just prints something like "Capture not configured" in the output.
Long story short, by listening for this line in the output, we can detect when C is being pressed and it doesn't impact playback!
Here you can see a quick demo of what I'm working on right now: when you press C, a little floppy icon shows up next to the currently playing song and the track info is written to "favorites.txt" in the current directory:
I'll push the changes I've made shortly, would appreciate any testing/feedback.
Some other SomaFM CLI clients have an option to hit a keyboard shortcut, which would then save the song name to a saved_songs.txt file, for example.
If I find some time I will try to dig in and learn some more Python to see if I could do this myself; but figured would add it in case you wanted any ideas.
Thanks a bunch for the library!