Merge pull request #789 from croneter/fix-unicode

Fix UnicodeDecodeError for libraries with non-ASCII paths
This commit is contained in:
croneter 2019-03-26 18:48:14 +01:00 committed by GitHub
commit 83660310bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,24 +57,28 @@ def process_method_on_list(method_to_run, items):
def get_clean_image(image): def get_clean_image(image):
'''helper to strip all kodi tags/formatting of an image path/url''' '''
helper to strip all kodi tags/formatting of an image path/url
Pass in either unicode or str; returns unicode
'''
if not image: if not image:
return "" return ""
if "music@" in image: if not isinstance(image, str):
image = image.encode('utf-8')
if b"music@" in image:
# fix for embedded images # fix for embedded images
thumbcache = xbmc.getCacheThumbName(image).replace(".tbn", ".jpg") thumbcache = xbmc.getCacheThumbName(image)
thumbcache = "special://thumbnails/%s/%s" % (thumbcache[0], thumbcache) thumbcache = thumbcache.replace(b".tbn", b".jpg")
thumbcache = b"special://thumbnails/%s/%s" % (thumbcache[0], thumbcache)
if not xbmcvfs.exists(thumbcache): if not xbmcvfs.exists(thumbcache):
xbmcvfs.copy(image, thumbcache) xbmcvfs.copy(image, thumbcache)
image = thumbcache image = thumbcache
if image and "image://" in image: if image and b"image://" in image:
image = image.replace("image://", "") image = image.replace(b"image://", b"")
image = urllib.unquote(image.encode("utf-8")) image = urllib.unquote(image)
if image.endswith("/"): if image.endswith(b"/"):
image = image[:-1] image = image[:-1]
if not isinstance(image, unicode): return image.decode('utf-8')
image = image.decode("utf8")
return image
def generate_item(xml_element): def generate_item(xml_element):