From b54f4d54e19173003acc88c536edcbd39cf7e4e5 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Tue, 2 Feb 2016 19:13:42 -0600 Subject: [PATCH] Convert to string Prep for translation --- resources/language/English/strings.xml | 3 ++ resources/lib/websocket_client.py | 53 +++++++++++++++----------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index 7cd1b8a0..727f4019 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -283,5 +283,8 @@ Error connecting Server is unreachable Server is online + items added to playlist + items queued to playlist + Server is restarting diff --git a/resources/lib/websocket_client.py b/resources/lib/websocket_client.py index f99c5212..0da3f4a6 100644 --- a/resources/lib/websocket_client.py +++ b/resources/lib/websocket_client.py @@ -50,7 +50,10 @@ class WebSocket_Client(threading.Thread): def sendProgressUpdate(self, data): - self.logMsg("sendProgressUpdate", 2) + + log = self.logMsg + + log("sendProgressUpdate", 2) try: messageData = { @@ -59,20 +62,24 @@ class WebSocket_Client(threading.Thread): } messageString = json.dumps(messageData) self.client.send(messageString) - self.logMsg("Message data: %s" % messageString, 2) + log("Message data: %s" % messageString, 2) except Exception as e: - self.logMsg("Exception: %s" % e, 1) + log("Exception: %s" % e, 1) def on_message(self, ws, message): + log = self.logMsg + window = utils.window + lang = utils.language + result = json.loads(message) messageType = result['MessageType'] data = result['Data'] if messageType not in ('SessionEnded'): # Mute certain events - self.logMsg("Message: %s" % message, 1) + log("Message: %s" % message, 1) if messageType == "Play": # A remote control play command has been sent from the server. @@ -81,12 +88,11 @@ class WebSocket_Client(threading.Thread): pl = playlist.Playlist() dialog = xbmcgui.Dialog() - dialog.notification("Emby for Kodi", "Adding %s items to playlist." % len(itemIds)) if command == "PlayNow": dialog.notification( heading="Emby for Kodi", - message="Adding %s items to playlist." % len(itemIds), + message="%s %s" % (len(itemIds), lang(33004)), icon="special://home/addons/plugin.video.emby/icon.png", sound=False) startat = data.get('StartPositionTicks', 0) @@ -95,7 +101,7 @@ class WebSocket_Client(threading.Thread): elif command == "PlayNext": dialog.notification( heading="Emby for Kodi", - message="Queueing %s items to playlist." % len(itemIds), + message="%s %s" % (len(itemIds), lang(33005)), icon="special://home/addons/plugin.video.emby/icon.png", sound=False) newplaylist = pl.modifyPlaylist(itemIds) @@ -123,12 +129,12 @@ class WebSocket_Client(threading.Thread): seekto = data['SeekPositionTicks'] seektime = seekto / 10000000.0 action(seektime) - self.logMsg("Seek to %s." % seektime, 1) + log("Seek to %s." % seektime, 1) else: action() - self.logMsg("Command: %s completed." % command, 1) + log("Command: %s completed." % command, 1) - utils.window('emby_command', value="true") + window('emby_command', value="true") elif messageType == "UserDataChanged": # A user changed their personal rating for an item, or their playstate was updated @@ -171,7 +177,7 @@ class WebSocket_Client(threading.Thread): embyindex = int(arguments['Index']) currentFile = player.getPlayingFile() - mapping = utils.window('emby_%s.indexMapping' % currentFile) + mapping = window('emby_%s.indexMapping' % currentFile) if mapping: externalIndex = json.loads(mapping) # If there's external subtitles added via playbackutils @@ -190,7 +196,7 @@ class WebSocket_Client(threading.Thread): player.setSubtitleStream(index - audioTracks - 1) # Let service know - utils.window('emby_command', value="true") + window('emby_command', value="true") elif command == "DisplayMessage": @@ -249,8 +255,8 @@ class WebSocket_Client(threading.Thread): elif messageType == "ServerRestarting": if utils.settings('supressRestartMsg') == "true": xbmcgui.Dialog().notification( - heading="Emby server", - message="Server is restarting.", + heading="Emby for Kodi", + message=lang(33006), icon="special://home/addons/plugin.video.emby/icon.png") elif messageType == "UserConfigurationUpdated": @@ -273,13 +279,16 @@ class WebSocket_Client(threading.Thread): def run(self): + log = self.logMsg + window = utils.window monitor = self.monitor - loglevel = int(utils.window('emby_logLevel')) + + loglevel = int(window('emby_logLevel')) # websocket.enableTrace(True) - userId = utils.window('emby_currUser') - server = utils.window('emby_server%s' % userId) - token = utils.window('emby_accessToken%s' % userId) + userId = window('emby_currUser') + server = window('emby_server%s' % userId) + token = window('emby_accessToken%s' % userId) deviceId = self.deviceId # Get the appropriate prefix for the websocket @@ -289,7 +298,7 @@ class WebSocket_Client(threading.Thread): server = server.replace('http', "ws") websocket_url = "%s?api_key=%s&deviceId=%s" % (server, token, deviceId) - self.logMsg("websocket url: %s" % websocket_url, 1) + log("websocket url: %s" % websocket_url, 1) self.client = websocket.WebSocketApp(websocket_url, on_message=self.on_message, @@ -297,11 +306,11 @@ class WebSocket_Client(threading.Thread): on_close=self.on_close) self.client.on_open = self.on_open - self.logMsg("----===## Starting WebSocketClient ##===----", 0) + log("----===## Starting WebSocketClient ##===----", 0) while not monitor.abortRequested(): - self.client.run_forever(ping_interval = 10) + self.client.run_forever(ping_interval=10) if self.stopWebsocket: break @@ -309,7 +318,7 @@ class WebSocket_Client(threading.Thread): # Abort was requested, exit break - self.logMsg("##===---- WebSocketClient Stopped ----===##", 0) + log("##===---- WebSocketClient Stopped ----===##", 0) def stopClient(self):