From ea4059b6d0f8da4759eccb18b9f53ad5cbda0324 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Mon, 31 Oct 2016 06:30:09 -0500 Subject: [PATCH] Hotfix (#72) * Fix external subtitles * Fix index error * Fix credentials encoding * Fix music var reference --- addon.xml | 2 +- resources/lib/connect/credentials.py | 13 +++++++++---- resources/lib/entrypoint.py | 2 +- resources/lib/objects/music.py | 2 +- resources/lib/playbackutils.py | 5 ++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/addon.xml b/addon.xml index e4b9eae5..e8ffd37a 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/lib/connect/credentials.py b/resources/lib/connect/credentials.py index 5a61512e..41ac6b1e 100644 --- a/resources/lib/connect/credentials.py +++ b/resources/lib/connect/credentials.py @@ -34,12 +34,15 @@ class Credentials(object): if self.credentials is None: try: with open(os.path.join(self.path, 'data.txt')) as infile: - self.credentials = json.load(unicode(infile)) - + self.credentials = json.load(infile) + + if not isinstance(self.credentials, dict): + raise ValueError("invalid credentials format") + except Exception as e: # File is either empty or missing log.warn(e) self.credentials = {} - + log.info("credentials initialized with: %s" % self.credentials) self.credentials['Servers'] = self.credentials.setdefault('Servers', []) @@ -54,7 +57,9 @@ class Credentials(object): self.credentials = data # Set credentials to file with open(os.path.join(self.path, 'data.txt'), 'w') as outfile: - json.dump(unicode(data), outfile, indent=4, ensure_ascii=False) + for server in data['Servers']: + server['Name'] = server['Name'].encode('utf-8') + json.dump(data, outfile, ensure_ascii=False) else: self._clear() diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 9cc3ce0e..488e76f5 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -372,7 +372,7 @@ def addUser(): result = doUtils.downloadUrl(url) try: additionalUsers = result[0]['AdditionalUsers'] - except (KeyError, TypeError) as error: + except (IndexError, KeyError, TypeError) as error: log.error(error) additionaluser = [] diff --git a/resources/lib/objects/music.py b/resources/lib/objects/music.py index 3ee40d4d..fca60236 100644 --- a/resources/lib/objects/music.py +++ b/resources/lib/objects/music.py @@ -490,7 +490,7 @@ class Music(Items): except TypeError: # No album found, create a single's album log.info("Failed to add album. Creating singles.") - album_id = self.kodi_db.create_entry_album() + albumid = self.kodi_db.create_entry_album() if self.kodi_version == 16: self.kodi_db.add_single(albumid, genre, year, "single") diff --git a/resources/lib/playbackutils.py b/resources/lib/playbackutils.py index 24fa9b51..87399d5c 100644 --- a/resources/lib/playbackutils.py +++ b/resources/lib/playbackutils.py @@ -276,7 +276,7 @@ class PlaybackUtils(): externalsubs.append(path) except Exception as e: log.error(e) - continue + externalsubs.append(url) else: externalsubs.append(url) @@ -298,12 +298,11 @@ class PlaybackUtils(): try: response = requests.get(src, stream=True) - response.encoding = 'utf-8' response.raise_for_status() except Exception as e: - del response raise else: + response.encoding = 'utf-8' with open(path, 'wb') as f: f.write(response.content) del response