From 224c2667d5d51f130ab0c45157228ebc87209d24 Mon Sep 17 00:00:00 2001 From: Uriziel Date: Sat, 29 Dec 2012 12:37:54 +0100 Subject: [PATCH] All consatnts exported to separate file --- syncplay/client.py | 20 +++++++------- syncplay/constants.py | 43 ++++++++++++++++++++++++++++++ syncplay/players/mpc.py | 31 +++++++++------------ syncplay/players/mplayer.py | 8 +++--- syncplay/server.py | 7 ++--- syncplay/ui/ConfigurationGetter.py | 5 ++-- syncplay/ui/GuiConfiguration.py | 14 ++-------- syncplay/ui/consoleUI.py | 20 +++++++------- syncplay/utils.py | 3 ++- 9 files changed, 92 insertions(+), 59 deletions(-) create mode 100644 syncplay/constants.py diff --git a/syncplay/client.py b/syncplay/client.py index 613b716..04bd22f 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -5,10 +5,10 @@ import time from twisted.internet.protocol import ClientFactory from twisted.internet import reactor, task from syncplay.protocols import SyncClientProtocol -from syncplay import utils +from syncplay import utils, constants class SyncClientFactory(ClientFactory): - def __init__(self, client, retry = 10): + def __init__(self, client, retry = constants.RECONNECT_RETRIES): self._client = client self.retry = retry self._timesTried = 0 @@ -53,7 +53,7 @@ class SyncplayClient(object): self.userlist = SyncplayUserlist(self.ui, self) self._protocol = None if(args.room == None or args.room == ''): - args.room = 'default' + args.room = constants.DEFAULT_ROOM self.defaultRoom = args.room self.playerPositionBeforeLastSeek = 0.0 self.setUsername(args.name) @@ -94,7 +94,7 @@ class SyncplayClient(object): self._player = player self.scheduleAskPlayer() - def scheduleAskPlayer(self, when=0.1): + def scheduleAskPlayer(self, when=constants.PLAYER_ASK_DELAY): self._askPlayerTimer = task.LoopingCall(self.askPlayer) self._askPlayerTimer.start(when) @@ -106,7 +106,7 @@ class SyncplayClient(object): self.checkIfConnected() def checkIfConnected(self): - if(self._lastGlobalUpdate and self._protocol and time.time() - self._lastGlobalUpdate > 4.1): + if(self._lastGlobalUpdate and self._protocol and time.time() - self._lastGlobalUpdate > constants.PROTOCOL_TIMEOUT): self._lastGlobalUpdate = None self.ui.showErrorMessage("Connection with server timed out") self._protocol.drop() @@ -117,7 +117,7 @@ class SyncplayClient(object): pauseChange = self.getPlayerPaused() != paused and self.getGlobalPaused() != paused _playerDiff = abs(self.getPlayerPosition() - position) _globalDiff = abs(self.getGlobalPosition() - position) - seeked = _playerDiff > 1 and _globalDiff > 1 + seeked = _playerDiff > constants.SEEK_BOUNDARY and _globalDiff > constants.SEEK_BOUNDARY return pauseChange, seeked def updatePlayerStatus(self, paused, position): @@ -182,12 +182,12 @@ class SyncplayClient(object): return madeChangeOnPlayer def _slowDownToCoverTimeDifference(self, diff, setBy): - if(1.5 < diff and not self._speedChanged): - self._player.setSpeed(0.95) + if(constants.SLOWDOWN_KICKIN_BOUNDARY < diff and not self._speedChanged): + self._player.setSpeed(constants.SLOWDOWN_RATE) self._speedChanged = True message = "Slowing down due to time difference with <{}>".format(setBy) self.ui.showMessage(message) - elif(self._speedChanged and diff < 0.1 ): + elif(self._speedChanged and diff < constants.SLOWDOWN_RESET_BOUNDARY): self._player.setSpeed(1.00) self._speedChanged = False message = "Reverting speed back to normal" @@ -363,7 +363,7 @@ class SyncplayUser(object): return False sameName = self.file['name'] == file_['name'] sameSize = self.file['size'] == file_['size'] - sameDuration = int(self.file['duration']) - int(file_['duration']) < 1 + sameDuration = int(self.file['duration']) - int(file_['duration']) < constants.DIFFFERENT_DURATION_BOUNDARY return sameName and sameSize and sameDuration def __lt__(self, other): diff --git a/syncplay/constants.py b/syncplay/constants.py new file mode 100644 index 0000000..5efcd3c --- /dev/null +++ b/syncplay/constants.py @@ -0,0 +1,43 @@ +DEFAULT_PORT = 8999 +MPC_OPEN_MAX_WAIT_TIME = 10 +MPC_LOCK_WAIT_TIME = 0.2 +OSD_DURATION = 3000 +MPC_OSD_POSITION = 2 #Right corner, 1 for left +MPC_RETRY_WAIT_TIME = 0.01 +MPC_MAX_RETRIES = 30 +MPC_PAUSE_TOGGLE_DELAY = 0.05 +MPLAYER_OSD_LEVEL = 1 +MPLAYER_ANSWER_REGEX = "^ANS_([a-zA-Z_]+)=(.+)$" +MPLAYER_SLAVE_ARGS = [ '-slave', '-msglevel', 'all=1:global=4'] +UI_COMMAND_REGEX = r"^(?P[^\ ]+)(?:\ (?P.+))?" +UI_OFFSET_REGEX = r"^(?:o|offset)\ ?(?P[/+-])?(?P