sensor.plex_recently_added icon indicating copy to clipboard operation
sensor.plex_recently_added copied to clipboard

Corrupted thumbnail images

Open HDebeuf opened this issue 3 years ago • 0 comments

Describe the Bug I've got corrupted (empty) images being displayed in the media cards.

The Error No error in the front end since the image files exist and they are retrieved with a HTTP 200 code.

Indicate if you followed all steps in the troubleshooting doc Yes, I followed the steps.

What data does the sensor display if any? All correct data.

What displays when visiting the API URL from the troubleshooting guide? Correct paths to the images.

Does the default Home Assistant Plex component work for you? Yes, this issue concerns only the Plex integration.

Home Assistant Version HA 2021.9.7

Additional Context My use case is a Plex media server remotely setup with a Let'sEncrypt enabled reverse proxy on port 443. Due to this if I call manually my photo transcoder with the domain name I set encoded, I get a 404 error. Still, the module will download an empty image without throwing the error.

More detailed analysis It appears the image_url() function encodes a full url to send to the transcoder. Someone who has setup Plex locally won't encounter the issue since the transcoder works with a local ip as url parameter. Someone who has it remotely setup, won't be able to transcode with a remote host encoded as url parameter. Someone who has it remotely setup, will be able to transcode if the local ip address is encoded as url parameter.

+ http(s)://local_host:local_port/photo/:/transcode?width=XX&height=XX&minSize=1&url=local_host:local_port%2Flibrary%2Fmetadata%2F1234%2Fthumb%1234567890&X-Plex-Token=XXXXXXXX
- http(s)://remote_host:remote_port/photo/:/transcode?width=XX&height=XX&minSize=1&url=remote_host:remote_port%2Flibrary%2Fmetadata%2F1234%2Fthumb%1234567890&X-Plex-Token=XXXXXXXX
+ http(s)://remote_host:remote_port/photo/:/transcode?width=XX&height=XX&minSize=1&url=local_host:local_port%2Flibrary%2Fmetadata%2F1234%2Fthumb%1234567890&X-Plex-Token=XXXXXXXX

How I sorted the issue in my HA instance By inspecting what the actual plex.tv dashboard does, it appears the encoded url parameter a relative path to the image file is. So the following works perfectly.

+ http(s)://remote_host:remote_port/photo/:/transcode?width=XX&height=XX&minSize=1&url=%2Flibrary%2Fmetadata%2F1234%2Fthumb%1234567890&X-Plex-Token=XXXXXXXX

So, I've replaced in the image_url() function of the sensor.py file: encoded = quote('http{0}://{1}:{2}{3}?X-Plex-Token={4}'.format(ssl, local, port, img,token), safe='') with encoded = quote(img), safe='') and it worked like a charm. I don't know if it could work with a locally setup Plex Server, but it might make the job easier.

Best regards,

hdebeuf

HDebeuf avatar Oct 02 '21 20:10 HDebeuf