bexem / PlexCache

Automate Plex media management: Efficiently transfer media from the On Deck/Watchlist to the cache, and seamlessly move watched media back to their respective locations.
88 stars 7 forks source link

Monitor "Now playing" and move to cache? #20

Open TheLinuxGuy opened 1 year ago

TheLinuxGuy commented 1 year ago

Could you consider adding a feature that monitors whatever media a user starts playing and have the script execute a copy to the unraid cache drive (effectively a copy)? then later purge the clone present in cache mount?

bexem commented 1 year ago

Thank you for your suggestion. Let me make sure I understand your request:

  1. You'd like the script to detect when a user starts playing a specific media, say "movie1."
  2. If "movie1" isn't on the cache drive, the script should copy it there.
  3. Once playback ends, "movie1" should be removed from the cache.

If I've got that right, I have a few thoughts:

While I hope to implement active monitoring of the Plex server in the future, I'm not sure if this specific functionality would yield the desired improvements. When a media starts playing, Plex reads it from the array. If we initiate a copy to the cache at this point, Plex is unlikely to switch its read source midway. Moreover, copying might strain the disk performance, especially during playback.

The potential benefits might be more noticeable for larger files, like high-quality blue-ray rips, but for most content, I don't believe there'd be a significant improvement.

If I've misunderstood your request, please let me know!

TheLinuxGuy commented 1 year ago

Hey @bexem - you have summarized the request well.

if we initiate a copy to the cache at this point, Plex is unlikely to switch its read source midway.

I vaguely recall some discussion on reddit mentioning the FUSE filesystem on unraid if configured as primary tier = cache, secondary = array - that fs reads get redirected to array but if the cache suddenly sees the same file with the same data that file operations may move to the cache seamlessly. I wish I had bookmarked it.

Consider playing a 3 hour movie only present in the array; an array hard drive spun-down would need to be active for the entire 3 hours plus some change. Where-as if this activity would work as noted above and FUSE did some invisible magic - the hdd could be spun down shortly after the copy to nvme cache is complete. Yielding 2.5+ hours of "hd idle"

bexem commented 1 year ago

If it works like you said then it make absolutely sense implementing that, it would save some energy. Good idea!

I'll put it in my pipeline, if you don't mind looking for the source of your information or anything that could put me in the right direction I will appreciate it.

TheLinuxGuy commented 1 year ago

If it works like you said then it make absolutely sense implementing that, it would save some energy. Good idea!

I think I found where I read about it... "Because of shfs mechanism accessing a file from /mnt/user will read/write fro cache if it exists, then from array. Duplicate data are not a problem and globally speed up things."

Also "Edit 13-02-2020: yes, after checking with File Activity plugin, that's the case and its plex/transmission take the file on cache as soon as it is available!"

see https://forums.unraid.net/topic/92126-smart-caching-script/

bexem commented 1 year ago

That is great news, thanks for the update! I will hopefully manage to implement this ☺️

rozza591 commented 11 months ago

This would be a great addition if it ends up working on plex's end.