diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index a3d68ea8..719e10cb 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -131,17 +131,14 @@ class PlexAPI(): dialog = xbmcgui.Dialog() while retrievedPlexLogin == '' and plexLogin != '': # Enter plex.tv username. Or nothing to cancel. - plexLogin = dialog.input( - self.addonName.encode('utf-8') + string(39300).encode('utf-8'), - type=xbmcgui.INPUT_ALPHANUM, - ) + plexLogin = dialog.input(self.addonName + string(39300), + type=xbmcgui.INPUT_ALPHANUM) if plexLogin != "": # Enter password for plex.tv user plexPassword = dialog.input( - string(39301).encode('utf-8') + plexLogin.encode('utf-8'), + string(39301) + plexLogin, type=xbmcgui.INPUT_ALPHANUM, - option=xbmcgui.ALPHANUM_HIDE_INPUT - ) + option=xbmcgui.ALPHANUM_HIDE_INPUT) retrievedPlexLogin, authtoken = self.MyPlexSignIn( plexLogin, plexPassword, @@ -151,8 +148,7 @@ class PlexAPI(): if plexLogin == '': # Could not sign in user dialog.ok(self.addonName, - string(39302).encode('utf-8') - + plexLogin.encode('utf-8')) + string(39302) + plexLogin) # Write to Kodi settings file utils.settings('plexLogin', value=retrievedPlexLogin) utils.settings('plexToken', value=authtoken) @@ -177,12 +173,12 @@ class PlexAPI(): dialog = xbmcgui.Dialog() if not code: # Problems trying to contact plex.tv. Try again later - dialog.ok(self.addonName, string(39303).encode('utf-8')) + dialog.ok(self.addonName, string(39303)) return False # Go to https://plex.tv/pin and enter the code: answer = dialog.yesno(self.addonName, - (string(39304) + "\n\n").encode('utf-8'), - code.encode('utf-8')) + string(39304) + "\n\n", + code) if not answer: return False count = 0 @@ -196,7 +192,7 @@ class PlexAPI(): count += 1 if not xml: # Could not sign in to plex.tv Try again later - dialog.ok(self.addonName, string(39305).encode('utf-8')) + dialog.ok(self.addonName, string(39305)) return False # Parse xml userid = xml.attrib.get('id') @@ -1089,7 +1085,7 @@ class PlexAPI(): if usernumber > 1: # Select user user_select = dialog.select( - (self.addonName + string(39306)).encode('utf-8'), + self.addonName + string(39306), userlistCoded) if user_select == -1: self.logMsg("No user selected.", 1) @@ -1108,7 +1104,7 @@ class PlexAPI(): # Please enter pin for user self.logMsg('Asking for users PIN', 1) pin = dialog.input( - (string(39307) + selected_user).encode('utf-8'), + string(39307) + selected_user, type=xbmcgui.INPUT_NUMERIC, option=xbmcgui.ALPHANUM_HIDE_INPUT) # User chose to cancel @@ -1129,11 +1125,9 @@ class PlexAPI(): # Couldn't get user auth if not username: # Could not login user, please try again - if not dialog.yesno( - self.addonName, - (string(39308) + selected_user).encode('utf-8'), - string(39309).encode('utf-8') - ): + if not dialog.yesno(self.addonName, + string(39308) + selected_user, + string(39309)): # User chose to cancel break # Successfully retrieved: break out of while loop diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 8f0c6703..901b8def 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -98,7 +98,7 @@ def reConnect(): if counter > 20: dialog.ok( heading=addonName, - message=string(39208).encode('utf-8'), + message=string(39208), ) # Resuming threads, just in case utils.window('suspend_LibraryThread', clear=True) @@ -185,7 +185,7 @@ def resetAuth(): string = xbmcaddon.Addon().getLocalizedString resp = xbmcgui.Dialog().yesno( heading="Warning", - line1=string(39206).encode('utf-8')) + line1=string(39206)) if resp == 1: utils.logMsg("PLEX", "Reset login attempts.", 1) utils.window('emby_serverStatus', value="Auth") @@ -255,14 +255,14 @@ def resetDeviceId(): "Failed to generate a new device Id: %s" % e, 1) dialog.ok( heading=addonName, - line1=language(33032).encode('utf-8')) + line1=language(33032)) else: utils.logMsg(addonName, "Successfully removed old deviceId: %s New deviceId: %s" % (deviceId_old, deviceId), 1) dialog.ok( heading=addonName, - line1=language(33033).encode('utf-8')) + line1=language(33033)) xbmc.executebuiltin('RestartApp') ##### ADD ADDITIONAL USERS ##### @@ -1189,6 +1189,6 @@ def RunLibScan(mode): # Server is not online, do not run the sync string = xbmcaddon.Addon().getLocalizedString xbmcgui.Dialog().ok(heading=addonName, - line1=string(39205).encode('utf-8')) + line1=string(39205)) else: utils.window('plex_runLibScan', value='full') diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 1853695c..5d69464ce 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -57,10 +57,8 @@ class InitialSetup(): # Delete token in the settings utils.settings('plexToken', value='') # Could not login, please try again - dialog.ok( - self.addonName, - string(39009).encode('utf-8') - ) + dialog.ok(self.addonName, + string(39009)) result = self.plx.PlexTvSignInWithPin() if result: plexLogin = result['username'] @@ -68,10 +66,8 @@ class InitialSetup(): plexid = result['plexid'] elif chk is False or chk >= 400: # Problems connecting to plex.tv. Network or internet issue? - dialog.ok( - self.addonName, - string(39010).encode('utf-8') - ) + dialog.ok(self.addonName, + string(39010)) # If a Plex server IP has already been set, return. if server and forcePlexTV is False: self.logMsg("Server is already set.", 0) @@ -100,8 +96,8 @@ class InitialSetup(): self.logMsg("Result of setting g_PMS variable: %s" % self.plx.g_PMS, 1) isconnected = False - serverlist = self.plx.returnServerList( - clientId, self.plx.g_PMS) + serverlist = self.plx.returnServerList(clientId, + self.plx.g_PMS) self.logMsg('PMS serverlist: %s' % serverlist) # Let user pick server from a list # Get a nicer list @@ -110,18 +106,18 @@ class InitialSetup(): if len(serverlist) == 0: dialog.ok( self.addonName, - string(39011).encode('utf-8') + string(39011) ) break for server in serverlist: if server['local'] == '1': # server is in the same network as client. Add "local" dialoglist.append( - server['name'].encode('utf-8') - + string(39022).encode('utf-8')) + server['name'] + + string(39022)) else: - dialoglist.append(server['name'].encode('utf-8')) - resp = dialog.select(string(39012).encode('utf-8'), dialoglist) + dialoglist.append(server['name']) + resp = dialog.select(string(39012), dialoglist) server = serverlist[resp] activeServer = server['machineIdentifier'] url = server['scheme'] + '://' + server['ip'] + ':' + \ @@ -146,9 +142,8 @@ class InitialSetup(): # Not yet authorized for Plex server # Please sign in to plex.tv dialog.ok(self.addonName, - string(39013).encode('utf-8') - + server['name'].encode('utf-8'), - string(39014).encode('utf-8')) + string(39013) + server['name'], + string(39014)) result = self.plx.PlexTvSignInWithPin() if result: plexLogin = result['username'] @@ -161,7 +156,7 @@ class InitialSetup(): elif chk >= 400 or chk is False: # Problems connecting to server. Pick another server? resp = dialog.yesno(self.addonName, - string(39015).encode('utf-8')) + string(39015)) # Exit while loop if user chooses No if not resp: break @@ -173,7 +168,7 @@ class InitialSetup(): # Enter Kodi settings instead if dialog.yesno( heading=self.addonName, - line1=string(39016).encode('utf-8')): + line1=string(39016)): self.logMsg("User opted to disable Plex music library.", 1) utils.settings('enableMusic', value="false") xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId) @@ -207,14 +202,14 @@ class InitialSetup(): if forcePlexTV: return - if dialog.yesno( - heading=self.addonName, - line1=string(39016).encode('utf-8')): + # Disable Plex music? + if dialog.yesno(heading=self.addonName, + line1=string(39016)): self.logMsg("User opted to disable Plex music library.", 1) utils.settings('enableMusic', value="false") - if dialog.yesno( - heading=self.addonName, - line1=string(39017).encode('utf-8')): + # Open Settings page now? + if dialog.yesno(heading=self.addonName, + line1=string(39017)): xbmc.executebuiltin( 'Addon.OpenSettings(plugin.video.plexkodiconnect)') diff --git a/resources/lib/player.py b/resources/lib/player.py index 24a5a037..a29ab512 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -524,8 +524,8 @@ class Player(xbmc.Player): offerDelete = False if percentComplete >= markPlayedAt and offerDelete: resp = xbmcgui.Dialog().yesno( - lang(30091).encode('utf-8'), - lang(33015).encode('utf-8'), + lang(30091), + lang(33015), autoclose=120000) if not resp: log("User skipped deletion.", 1) diff --git a/resources/lib/playutils.py b/resources/lib/playutils.py index 8a382f1a..019d7614 100644 --- a/resources/lib/playutils.py +++ b/resources/lib/playutils.py @@ -34,6 +34,8 @@ class PlayUtils(): """ Returns the playurl for the part with number partNumber (movie might consist of several files) + + playurl is utf-8 encoded! """ log = self.logMsg window = utils.window @@ -64,6 +66,7 @@ class PlayUtils(): } playurl = self.API.getTranscodeVideoPath('Transcode', quality=quality) + playurl = playurl.encode('utf-8') # Set playmethod property window('emby_%s.playmethod' % playurl, value="Transcode") @@ -371,7 +374,7 @@ class PlayUtils(): subNum += 1 if audioNum > 1: - resp = dialog.select(lang(33013).encode('utf-8'), audioStreams) + resp = dialog.select(lang(33013), audioStreams) if resp > -1: # User selected audio playurlprefs['audioStreamID'] = audioStreamsList[resp] @@ -384,7 +387,7 @@ class PlayUtils(): playurlprefs['audioBoost'] = utils.settings('audioBoost') if subNum > 1: - resp = dialog.select(lang(33014).encode('utf-8'), subtitleStreams) + resp = dialog.select(lang(33014), subtitleStreams) if resp == 0: # User selected no subtitles playurlprefs["skipSubtitles"] = 1 diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index bc671acd..4246654e 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -46,23 +46,16 @@ class UserClient(threading.Thread): threading.Thread.__init__(self) - def getAdditionalUsers(self): - - additionalUsers = utils.settings('additionalUsers') - - if additionalUsers: - self.AdditionalUser = additionalUsers.split(',') - def getUsername(self): """ Returns username as unicode """ - username = utils.settings('username').decode('utf-8') + username = utils.settings('username') if not username: self.logMsg("No username saved, trying to get Plex username", 0) - username = utils.settings('plexLogin').decode('utf-8') + username = utils.settings('plexLogin') if not username: self.logMsg("Also no Plex username found", 0) return "" @@ -245,9 +238,8 @@ class UserClient(threading.Thread): log("Access is granted.", 1) self.HasAccess = True window('emby_serverStatus', clear=True) - xbmcgui.Dialog().notification( - self.addonName, - utils.language(33007).encode('utf-8')) + xbmcgui.Dialog().notification(self.addonName, + utils.language(33007)) def loadCurrUser(self, authenticated=False): self.logMsg('Loading current user', 0) @@ -318,7 +310,8 @@ class UserClient(threading.Thread): dialog = xbmcgui.Dialog() # Get /profile/addon_data - addondir = xbmc.translatePath(self.addon.getAddonInfo('profile')).decode('utf-8') + addondir = xbmc.translatePath( + self.addon.getAddonInfo('profile')).decode('utf-8') hasSettings = xbmcvfs.exists("%ssettings.xml" % addondir) # If there's no settings.xml @@ -373,7 +366,7 @@ class UserClient(threading.Thread): if username: dialog.notification( heading=self.addonName, - message=("Welcome " + username).encode('utf-8'), + message="Welcome " + username, icon="special://home/addons/plugin.video.plexkodiconnect/icon.png") else: dialog.notification( @@ -391,8 +384,8 @@ class UserClient(threading.Thread): if self.retry >= 5: log("Too many retries.", 1) window('emby_serverStatus', value="Stop") - dialog.ok(lang(33001).encode('utf-8'), - lang(39023).encode('utf-8')) + dialog.ok(lang(33001), + lang(39023)) xbmc.executebuiltin( 'Addon.OpenSettings(plugin.video.plexkodiconnect)') diff --git a/resources/lib/utils.py b/resources/lib/utils.py index f2859c1b..1a636a12 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -217,7 +217,13 @@ def logMsg(title, msg, level=1): def window(property, value=None, clear=False, windowid=10000): - # Get or set window property + """ + Get or set window property - thread safe! + + Returns unicode. + + Property needs to be string; value may be string or unicode + """ WINDOW = xbmcgui.Window(windowid) #setproperty accepts both string and unicode but utf-8 strings are adviced by kodi devs because some unicode can give issues @@ -228,14 +234,13 @@ def window(property, value=None, clear=False, windowid=10000): if clear: WINDOW.clearProperty(property) elif value is not None: - # Takes unicode or string by default! - WINDOW.setProperty(property, value) - else: #getproperty returns string so convert to unicode - return WINDOW.getProperty(property) + WINDOW.setProperty(property, value.encode('utf-8')) + else: + return WINDOW.getProperty(property).decode('utf-8') def settings(setting, value=None): """ - Get or add addon setting. + Get or add addon setting. Returns unicode Settings needs to be string Value can either be unicode or string @@ -244,10 +249,10 @@ def settings(setting, value=None): if value is not None: # Takes string or unicode by default! - addon.setSetting(setting, value) + addon.setSetting(setting, value.encode('utf-8')) else: - # Returns unicode by default! - return addon.getSetting(setting) + # Should return unicode by default, but just in case + return addon.getSetting(setting).decode('utf-8') def language(stringid): # Central string retrieval diff --git a/resources/lib/videonodes.py b/resources/lib/videonodes.py index 12768ad1..6e99f3bd 100644 --- a/resources/lib/videonodes.py +++ b/resources/lib/videonodes.py @@ -4,7 +4,6 @@ import shutil import xml.etree.ElementTree as etree -from os import path as ospath import xbmc import xbmcvfs