spezifisch / stmps

Subsonic Terminal Music Player S
GNU General Public License v3.0
19 stars 6 forks source link

Feature 48 display cover art #55

Closed xxxserxxx closed 1 month ago

xxxserxxx commented 1 month ago

Note

This must be pulled instead of #25, or after #25 has been merged. It's built on top of #25. I am issuing the PR against main only because #25 isn't available in your repo; if you merge #25 first, this PR is much smaller -- it was forked off #25.

This implements #48 in the most simple way: with tview.Image. The tview dithering algorithm isn't particularly pretty, and it doesn't take advantage of any of the possible special terminal capabilities like kitty or SIXEL, but it does work and is fairly straightforward, and it doesn't pull in any more external dependencies.

There are some things to note:

  1. Atypically for the project, results are cached at the connection level. This is because much of the image parsing logic is there, because how the results are parsed depends on the content-type returned by the server.
  2. Go provides image parsers for GIF, JPEG, and PNG, so these are the only image types handled by this code.
  3. I used a deep learning tool to generate a logo for stmps, mainly so that the app has something to display when the server doesn't have cover art for a song. See docs/logo.md; there's not much to it, and I have no ego invested in this logo, so feel free to replace it with... anything. As long as it's an image.
  4. stmps caches a lot of data, but images are another level. This code works and I think it's fine for release, but if merged I'd like to add a ticket for a change keep some last N most recently used images. This could get much more sophisticated: the rasterized tview.Image results should take far less memory than whatever source images servers return, but this code caches the source. On the upside, if users resize their terminals, the cover art automatically looks better because the rendering quality is dependent on terminal size. On the downside, we're keeping a bunch of bits we will never use if the terminal isn't resized. What we probably ultimately want to do is (1) store the reduced rasterized images, (2) drop all of the cached images if the terminal is resized, which would (3) re-fetch the images when requested. And we'd still probably want to constrain the cached image size, so... it's some work.
  5. When we add LRU-constrained cache sizing, we'll want users to be able to configure it, in case they're using stmps on a Pi or something.

I am not much concerned about the data fetch bandwidth, because we are ultimately streaming far greater amounts of bytes worth of music. The album art is insignificant overhead.

I have merged all of my PRs on top of your current main, in order of PR, and there's only one conflict because I fixed a linting issue in two different branches. It's an easy resolution.

xxxserxxx commented 1 month ago

Teaser: stmps_coverart

spezifisch commented 1 month ago

This must be pulled instead of #25, or after #25 has been merged. It's built on top of #25. I am issuing the PR against main only because #25 isn't available in your repo; if you merge #25 first, this PR is much smaller -- it was forked off #25.

Oops, I messed it up. Sorry, I will clean up after merging the other PRs.