From bb808213a47331d5572b3f80bc2d0404c2194547 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Sun, 29 Jan 2017 13:58:55 +0100 Subject: [PATCH] Fix ImportError --- resources/lib/variables.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/resources/lib/variables.py b/resources/lib/variables.py index a78141ee..7904fb20 100644 --- a/resources/lib/variables.py +++ b/resources/lib/variables.py @@ -1,11 +1,28 @@ # -*- coding: utf-8 -*- import xbmc from xbmcaddon import Addon -from utils import settings, tryDecode + +def tryDecode(string, encoding='utf-8'): + """ + Will try to decode string (encoded) using encoding. This possibly + fails with e.g. Android TV's Python, which does not accept arguments for + string.encode() + """ + if isinstance(string, unicode): + # already decoded + return string + try: + string = string.decode(encoding, "ignore") + except TypeError: + string = string.decode() + return string + + +_ADDON = Addon() ADDON_NAME = 'PlexKodiConnect' ADDON_ID = 'plugin.video.plexkodiconnect' -ADDON_VERSION = Addon().getAddonInfo('version') +ADDON_VERSION = _ADDON.getAddonInfo('version') KODILANGUAGE = xbmc.getLanguage(xbmc.ISO_639_1) KODIVERSION = int(xbmc.getInfoLabel("System.BuildVersion")[:2]) @@ -29,11 +46,11 @@ elif xbmc.getCondVisibility('system.platform.android'): else: PLATFORM = "Unknown" -if settings('deviceNameOpt') == "false": +if _ADDON.getSetting('deviceNameOpt') == "false": # Use Kodi's deviceName DEVICENAME = tryDecode(xbmc.getInfoLabel('System.FriendlyName')) else: - DEVICENAME = settings('deviceName') + DEVICENAME = tryDecode(_ADDON.getSetting('deviceName')) DEVICENAME = DEVICENAME.replace("\"", "_") DEVICENAME = DEVICENAME.replace("/", "_")