Cache posters with thread id to avoid overwriting images

This commit is contained in:
JonnyWong16 2016-04-27 23:10:54 -07:00
parent 9a650b5cd6
commit 7ebd74a54a

View file

@ -17,6 +17,7 @@
import arrow import arrow
import os import os
import re import re
import threading
import time import time
import urllib import urllib
@ -622,11 +623,15 @@ def build_notify_text(session=None, timeline=None, notify_action=None, agent_id=
# If no previous poster_url # If no previous poster_url
if not poster_url and plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS: if not poster_url and plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS:
try: try:
thread_name = str(threading.current_thread().ident)
# Retrieve the poster from Plex and cache to file # Retrieve the poster from Plex and cache to file
urllib.urlretrieve(plexpy.CONFIG.PMS_URL + thumb + '?X-Plex-Token=' + plexpy.CONFIG.PMS_TOKEN, urllib.urlretrieve(plexpy.CONFIG.PMS_URL + thumb + '?X-Plex-Token=' + plexpy.CONFIG.PMS_TOKEN,
os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-poster.jpg')) os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-poster-'+thread_name+'.jpg'))
# Upload thumb to Imgur and get link # Upload thumb to Imgur and get link
poster_url = helpers.uploadToImgur(os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-poster.jpg'), poster_title) poster_url = helpers.uploadToImgur(os.path.join(plexpy.CONFIG.CACHE_DIR,
'cache-poster-'+thread_name+'.jpg'), poster_title)
# Delete the cached poster
os.remove(os.path.join(plexpy.CONFIG.CACHE_DIR, 'cache-poster-'+thread_name+'.jpg'))
except Exception as e: except Exception as e:
logger.error(u"PlexPy Notifier :: Unable to retrieve poster for rating_key %s: %s." % (str(rating_key), e)) logger.error(u"PlexPy Notifier :: Unable to retrieve poster for rating_key %s: %s." % (str(rating_key), e))