From ed4722c4ce08841556f67318e810782cd18c9506 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Thu, 3 May 2018 20:29:23 -0700 Subject: [PATCH] Improve refreshing of cached Plex images --- plexpy/pmsconnect.py | 5 ++++- plexpy/webserve.py | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 98696c51..e900826b 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -2436,7 +2436,7 @@ class PmsConnect(object): return labels_list def get_image(self, img=None, width=1000, height=1500, opacity=None, background=None, blur=None, - img_format='png', clip=False, **kwargs): + img_format='png', clip=False, refresh=False, **kwargs): """ Return image data as array. Array contains the image content type and image binary @@ -2454,6 +2454,9 @@ class PmsConnect(object): height = height or 1500 if img: + if refresh: + img = '{}/{}'.format(img.rstrip('/'), int(time.time())) + if clip: params = {'url': '%s&%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))} else: diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 70cfec93..ab2cdff2 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -3962,13 +3962,20 @@ class WebInterface(object): return if rating_key and not img: - img = '/library/metadata/%s/thumb/1337' % rating_key + if fallback == 'art': + img = '/library/metadata/{}/art'.format(rating_key) + else: + img = '/library/metadata/{}/thumb'.format(rating_key) - img_string = img.rsplit('/', 1)[0] if '/library/metadata' in img else img - img_string = '{}{}{}{}{}{}'.format(img_string, width, height, opacity, background, blur) + img_split = img.split('/') + img = '/'.join(img_split[:5]) + rating_key = rating_key or img_split[3] - fp = hashlib.md5(img_string).hexdigest() - fp += '.%s' % img_format # we want to be able to preview the thumbs + img_string = '{}.{}.{}.{}.{}.{}.{}.{}'.format( + plexpy.CONFIG.PMS_UUID, img, rating_key, width, height, opacity, background, blur, fallback) + img_hash = hashlib.sha256(img_string).hexdigest() + + fp = '{}.{}'.format(img_hash, img_format) # we want to be able to preview the thumbs c_dir = os.path.join(plexpy.CONFIG.CACHE_DIR, 'images') ffp = os.path.join(c_dir, fp) @@ -3994,7 +4001,8 @@ class WebInterface(object): background=background, blur=blur, img_format=img_format, - clip=clip) + clip=clip, + refresh=refresh) if result and result[0]: cherrypy.response.headers['Content-type'] = result[1]