From 1b3e370d6d8e3c2b8d0c9cd827eebb00d034de88 Mon Sep 17 00:00:00 2001 From: Et0h Date: Fri, 10 Oct 2014 19:39:43 +0100 Subject: [PATCH] Add debug messages for VLC/mpv/Client-Server comms --- syncplay/client.py | 5 +++++ syncplay/constants.py | 1 + syncplay/players/mplayer.py | 3 +++ syncplay/players/vlc.py | 4 ++-- syncplay/protocols.py | 2 ++ syncplay/ui/gui.py | 3 --- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/syncplay/client.py b/syncplay/client.py index 026c4b7..bd84a42 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -61,6 +61,7 @@ class SyncplayClient(object): constants.SHOW_DIFFERENT_ROOM_OSD = config['showDifferentRoomOSD'] constants.SHOW_SAME_ROOM_OSD = config['showSameRoomOSD'] constants.SHOW_DURATION_NOTIFICATION = config['showDurationNotification'] + constants.DEBUG_MODE = config['debug'] self.lastLeftTime = 0 self.lastLeftUser = u"" self.protocolFactory = SyncClientFactory(self) @@ -637,6 +638,10 @@ class UiManager(object): self.__ui = ui self.lastError = "" + def showDebugMessage(self, message): + if constants.DEBUG_MODE and message.rstrip(): + print "{}{}".format(time.strftime(constants.UI_TIME_FORMAT, time.localtime()),message.rstrip()) + def showMessage(self, message, noPlayer=False, noTimestamp=False): if not noPlayer: self.showOSDMessage(message) self.__ui.showMessage(message, noTimestamp) diff --git a/syncplay/constants.py b/syncplay/constants.py index 91218a6..98c2743 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -22,6 +22,7 @@ SHOW_SLOWDOWN_OSD = True # Show notifications of slowing down / reverting on ti SHOW_SAME_ROOM_OSD = True # Show OSD notifications for events relating to room user is in SHOW_DIFFERENT_ROOM_OSD = False # Show OSD notifications for events relating to room user is not in SHOW_DURATION_NOTIFICATION = True +DEBUG_MODE = False #Changing these might be ok DEFAULT_REWIND_THRESHOLD = 4 diff --git a/syncplay/players/mplayer.py b/syncplay/players/mplayer.py index d79c048..8a89e9b 100644 --- a/syncplay/players/mplayer.py +++ b/syncplay/players/mplayer.py @@ -148,6 +148,8 @@ class MplayerPlayer(BasePlayer): self._paused = value def lineReceived(self, line): + if line: + self._client.ui.showDebugMessage("player << {}".format(line)) match = self.RE_ANSWER.match(line) if not match: self._handleUnknownLine(line) @@ -290,6 +292,7 @@ class MplayerPlayer(BasePlayer): def sendLine(self, line): try: line = (line.decode('utf8') + u"\n").encode('utf8') + self.__playerController._client.ui.showDebugMessage("player >> {}".format(line)) self.__process.stdin.write(line) except IOError: pass diff --git a/syncplay/players/vlc.py b/syncplay/players/vlc.py index fe6f79a..18a77a6 100644 --- a/syncplay/players/vlc.py +++ b/syncplay/players/vlc.py @@ -130,6 +130,7 @@ class VlcPlayer(BasePlayer): self._listener.sendLine("get-filename") def lineReceived(self, line): + self._client.ui.showDebugMessage("player >> {}".format(line)) match, name, value = self.RE_ANSWER.match(line), "", "" if match: name, value = match.group('command'), match.group('argument') @@ -327,15 +328,14 @@ class VlcPlayer(BasePlayer): self.__playerController.drop() def found_terminator(self): -# print "received: {}".format("".join(self._ibuffer)) self.__playerController.lineReceived("".join(self._ibuffer)) self._ibuffer = [] def sendLine(self, line): if self.connected: -# print "send: {}".format(line) try: self.push(line + "\n") + self._client.ui.showDebugMessage("player >> {}".format(line)) except: pass if line == "close-vlc": diff --git a/syncplay/protocols.py b/syncplay/protocols.py index 8e4e14a..750d212 100644 --- a/syncplay/protocols.py +++ b/syncplay/protocols.py @@ -30,6 +30,7 @@ class JSONCommandProtocol(LineReceiver): if not line: return try: + self._client.ui.showDebugMessage("client/server << {}".format(line)) messages = json.loads(line) except: self.dropWithError(getMessage("not-json-server-error").format(line)) @@ -39,6 +40,7 @@ class JSONCommandProtocol(LineReceiver): def sendMessage(self, dict_): line = json.dumps(dict_) self.sendLine(line) + self._client.ui.showDebugMessage("client/server >> {}".format(line)) def drop(self): self.transport.loseConnection() diff --git a/syncplay/ui/gui.py b/syncplay/ui/gui.py index 134841a..402a0c2 100644 --- a/syncplay/ui/gui.py +++ b/syncplay/ui/gui.py @@ -117,9 +117,6 @@ class MainWindow(QtGui.QMainWindow): def userListChange(self): self._syncplayClient.showUserList() - - def showDebugMessage(self, message): - print(message) def showErrorMessage(self, message, criticalerror = False): message = unicode(message)