dhonus / jellyfin-tui

🪼 Jellyfin music streaming client for the terminal.
GNU General Public License v3.0
16 stars 2 forks source link

Offline cache #5

Open j6k4m8 opened 1 month ago

j6k4m8 commented 1 month ago

Would be a game-changer if we supported an offline cache of media. TOTALLY AMAZING if we also allow the user to decide how/when to add/evict.

I appreciate that this is a huge undertaking ("hardest thing in computer science is cache eviction"!) but wanted to put it on the radar as possibly a multi-PR epic.

Particularly thinking about it now because I'm flying a lot in the next few days :) but I'd love to help get this working!

If you're willing, I'd love to start chatting about how to implement this or where to start poking around in the codebase to start adding support for this.

dhonus commented 1 month ago

Initially I wanted this to be a thin client, but I recently changed my mind and probably do want to add caching. I was originally thinking about doing some automatic thing that would cache your N most listened songs, but I think that would only be annoying.

So to actually add caching we'd have to first keep a local copy of the library in JSON. Then there is a choice of: a) keep the downloaded/streamed libraries separate (i don't like this) b) add a task that would poll the server and check if any downloaded content was removed/changed c) a hybrid approach: if the IDs match we just stream the cached files, keep a JSON of what is cached (i'd go for this option)

If you were offline it would only list cached content, if you were online it would save bandwidth by using cached files if available. I think this is pretty easily doable with a basic directory structure using jellyfin IDs.

If you have any ideas or disagree with me feel free to continue this thread.

But, I would prefer to wait until jellyfin-tui reaches a stable release. I want to do a bit of a refactor to make caching easier.

j6k4m8 commented 1 month ago

That makes a lot of sense! I think your option C is how I would have thought of implementing as well; then we can add explicit "offline-mode" cache additions totally independently from the cache manager itself (i.e., by downloading and populating the cache in the background or something).

Totally makes sense to wait for after-refactor; let me know if you want me to jump in on refactor stuff :)

dhonus commented 1 month ago

As far as the refactor goes I would like to at the very least (before 1.0) split tui.rs into a few files (let's say at least separate tabs). Then go through the main render loop and extract/precompute heavy values (like all the artist/track list generation chains "let items = self.artists.filter.map......" etc) to make it less CPU intensive.

Then I'll release v1.0, write a PKGBUILD for the AUR and start work on offline caching.

If any of this sounds interesting to you or anyone else feel free to submit a PR and we can continue the discussion there.

Also, the libmpv-rs dependency in this repo should be updated at some point. It's abandoned hence why I included the source in this repo. It's generated by bindgen (I would love to regenerate it soon to keep up to date with the current libmpv version). Maybe incorporate some of the bugfix PRs from the libmpv-rs repo too.