Fix Cloudinary upload for non-ASCII characters on Python 2

This commit is contained in:
JonnyWong16 2020-07-10 21:57:53 -07:00
parent b4a10adec2
commit 40ecf56904
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -112,7 +112,7 @@ def radio(variable, pos):
return ''
def latinToAscii(unicrap):
def latinToAscii(unicrap, replace=False):
"""
From couch potato
"""
@ -150,7 +150,8 @@ def latinToAscii(unicrap):
if ord(i) in xlate:
r += xlate[ord(i)]
elif ord(i) >= 0x80:
pass
if replace:
r += '?'
else:
r += str(i)
@ -736,11 +737,17 @@ def upload_to_cloudinary(img_data, img_title='', rating_key='', fallback=''):
api_secret=plexpy.CONFIG.CLOUDINARY_API_SECRET
)
# Cloudinary library has very poor support for non-ASCII characters on Python 2
if plexpy.PYTHON2:
_img_title = latinToAscii(img_title, replace=True)
else:
_img_title = img_title
try:
response = upload((img_title, img_data),
public_id='{}_{}'.format(fallback, rating_key),
tags=['tautulli', fallback, str(rating_key)],
context={'title': img_title, 'rating_key': str(rating_key), 'fallback': fallback})
context={'title': _img_title, 'rating_key': str(rating_key), 'fallback': fallback})
logger.debug("Tautulli Helpers :: Image '{}' ({}) uploaded to Cloudinary.".format(img_title, fallback))
img_url = response.get('url', '')
except Exception as e: