Photo Transcoder Cache Generation Script

Someone please correct me if I’ve got this wrong.
When browsing a section, season, episode, etc., the Plex client requests from PMS size limited thumbnails for cover art, background art, etc., as required by its display layout.  If PMS finds a thumbnail file matching the requested size in the PhotoTranscoder cache directory then PMS will send that file to the client. If thumbnail file of the requested size is not in the cache directory PMS will generate the resized file, store it in cache for next time, and return it to the client. Subsequent requests for the same resized image are faster since the resizing operation is not required. 

 

The requested dimensions vary by client application and selected display. For example the web interface might request thumbnails of size w180, h200 when viewing a section, while the Samsung TV app may request the same image at w123, h456 when viewing the same section sometimes requiring a diffrent cache file be generated.  Also, once an individual show or movie is selected the same image may be requested again in a larger size.  As the Plex client is used the PhotoTranscoder cache directory grows and fewer and fewer resizing operations are required and the client ‘feels faster’.

 

I have a very slow NAS that can take over a second to resize some large images, especialy if it is busy doing somthing else.  When browsing a large directory on a new device/client it can take ages to load the images making for a very frustrating experience.  Since the clients typically only load a few items at a time, the only way I could figure to get the caching out of the way was to manually scroll through each section until all images are cached, then select each item in the section so that resizing caching could be triggered again.  I don’t have the patience to do that, nor do I want to wait when I add new media or update art or thumbnails.

 

After work last night I wrote a quick app to loop through all sections, all movies, all shows and all seasons and retrieve the urls for thumbs and art.  For each thumb or art item the application requests a resized version from the PMS photo transcoder using the format shown in the URL* below. The image request is repeated for all of the dimensions of the given image type used by the clients I use (Android, SamsungTV, Web). I used the PlexMediaServer.log file with Debug logging enabled to determine which widths and heights are used by the clients and weather the client requested up scaling or not.  The hope is that when I browse using a client no photo transcending has to take place on the server and the client always feels fast.

 

So here’s where I ran into a snag… The images of the correct size were generated and stored in the PhotoTranscoder cache directory when my app was run. Subsequent runs of the app were much quicker and the log showed the cached image was being picked up. However when the actual client requested the same size image PMS did not identify that the image already existed in its cache and regenerated the resized image again! I think PMS might be storing duplicate images under a different file name (hash?) depending on if the request was originating from my app or from the client (I'm not home to verify). What is used to generate the file name; I’m guessing it’s just the url, width, and height in the request? What might I be doing wrong (probably something obvious)?

 

This is my first non-plugin Python project and first time working with XML in Python, I have very little

XML experiance.
Thanks

 

* http://server:32400/photo/:/transcode?width=&height=&upscale=<0,1>&url=
 

Nevermind I worked it out, I wasnt passing anything to a black string as safe parameter of urllib.quote(). I can now precache all the resized artwork and thumbnails ahead of time making my experiance much more pleasent on new devices and when adding media to the library.

Attached is a copy of the script. Dont expect it to work for you.

.py files get rejected. Reattach as tar

I have the same problem. haven't tried to modify your script. Seeing this is over a year old, have you seen / heard whether the Plex folks are considering a service that will perform these updates automatically. I have issues that when a single file changes in a directory, it has to recreate the entire cache for some reason. Doesn't make sense that an entire cache needs to be updated when one file changes - but seems to happen. Any thoughts?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.