Fix ImportError

This commit is contained in:
tomkat83 2017-01-29 13:58:55 +01:00
parent c17ebf0647
commit bb808213a4

View file

@ -1,11 +1,28 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import xbmc import xbmc
from xbmcaddon import Addon 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_NAME = 'PlexKodiConnect'
ADDON_ID = 'plugin.video.plexkodiconnect' ADDON_ID = 'plugin.video.plexkodiconnect'
ADDON_VERSION = Addon().getAddonInfo('version') ADDON_VERSION = _ADDON.getAddonInfo('version')
KODILANGUAGE = xbmc.getLanguage(xbmc.ISO_639_1) KODILANGUAGE = xbmc.getLanguage(xbmc.ISO_639_1)
KODIVERSION = int(xbmc.getInfoLabel("System.BuildVersion")[:2]) KODIVERSION = int(xbmc.getInfoLabel("System.BuildVersion")[:2])
@ -29,11 +46,11 @@ elif xbmc.getCondVisibility('system.platform.android'):
else: else:
PLATFORM = "Unknown" PLATFORM = "Unknown"
if settings('deviceNameOpt') == "false": if _ADDON.getSetting('deviceNameOpt') == "false":
# Use Kodi's deviceName # Use Kodi's deviceName
DEVICENAME = tryDecode(xbmc.getInfoLabel('System.FriendlyName')) DEVICENAME = tryDecode(xbmc.getInfoLabel('System.FriendlyName'))
else: else:
DEVICENAME = settings('deviceName') DEVICENAME = tryDecode(_ADDON.getSetting('deviceName'))
DEVICENAME = DEVICENAME.replace("\"", "_") DEVICENAME = DEVICENAME.replace("\"", "_")
DEVICENAME = DEVICENAME.replace("/", "_") DEVICENAME = DEVICENAME.replace("/", "_")