Improve refreshing of cached Plex images

This commit is contained in:
JonnyWong16 2018-05-03 20:29:23 -07:00
parent 17ab5f05ed
commit ed4722c4ce
2 changed files with 18 additions and 7 deletions

View file

@ -2436,7 +2436,7 @@ class PmsConnect(object):
return labels_list return labels_list
def get_image(self, img=None, width=1000, height=1500, opacity=None, background=None, blur=None, 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. Return image data as array.
Array contains the image content type and image binary Array contains the image content type and image binary
@ -2454,6 +2454,9 @@ class PmsConnect(object):
height = height or 1500 height = height or 1500
if img: if img:
if refresh:
img = '{}/{}'.format(img.rstrip('/'), int(time.time()))
if clip: if clip:
params = {'url': '%s&%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))} params = {'url': '%s&%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))}
else: else:

View file

@ -3962,13 +3962,20 @@ class WebInterface(object):
return return
if rating_key and not img: 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_split = img.split('/')
img_string = '{}{}{}{}{}{}'.format(img_string, width, height, opacity, background, blur) img = '/'.join(img_split[:5])
rating_key = rating_key or img_split[3]
fp = hashlib.md5(img_string).hexdigest() img_string = '{}.{}.{}.{}.{}.{}.{}.{}'.format(
fp += '.%s' % img_format # we want to be able to preview the thumbs 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') c_dir = os.path.join(plexpy.CONFIG.CACHE_DIR, 'images')
ffp = os.path.join(c_dir, fp) ffp = os.path.join(c_dir, fp)
@ -3994,7 +4001,8 @@ class WebInterface(object):
background=background, background=background,
blur=blur, blur=blur,
img_format=img_format, img_format=img_format,
clip=clip) clip=clip,
refresh=refresh)
if result and result[0]: if result and result[0]:
cherrypy.response.headers['Content-type'] = result[1] cherrypy.response.headers['Content-type'] = result[1]