From aad15b6f5fafcdb568874874d3ddc1904088f695 Mon Sep 17 00:00:00 2001 From: Uriziel Date: Sat, 22 Sep 2012 03:15:05 +0200 Subject: [PATCH] Added checking file's size and duration --- syncplay/__init__.py | 2 +- syncplay/client.py | 40 ++++++++++++++++++---------------------- syncplay/server.py | 24 ++++++++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/syncplay/__init__.py b/syncplay/__init__.py index 969d0f3..5245fb8 100644 --- a/syncplay/__init__.py +++ b/syncplay/__init__.py @@ -1,3 +1,3 @@ -version = '0.5.0' +version = '0.6.0' milestone = 'Clara' projectURL = 'http://droptable.co.cc' \ No newline at end of file diff --git a/syncplay/client.py b/syncplay/client.py index 0bf4dfa..731ea33 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -55,17 +55,17 @@ class SyncClientProtocol(CommandProtocol): self.__syncplayClient.protocol.sender.send_list() self.__syncplayClient.scheduleSendStatus() if(self.__syncplayClient.users.currentUser.filename <> None): - self.__protocol.sendMessage('playing', self.__syncplayClient.users.currentUser.filename) + self.__syncplayClient.sendPlaying() - @argumentCount(2, 3) + @argumentCount(2, 5) def present(self, args): - if len(args) == 3: - who, where, what = args + if len(args) == 5: + who, where, what, duration, size = args else: - who, where, what = args[0], args[1], None - self.__syncplayClient.users.addUser(SyncplayClientManager.SyncplayUser(who, what, where)) + who, where, what, duration, size = args[0], args[1], None, None, None + self.__syncplayClient.users.addUser(SyncplayClientManager.SyncplayUser(who, what, where, duration, size)) if what: - message = '%s is present and is playing \'%s\' in the room: \'%s\'' % (who, what, where) + message = '%s is present and is playing \'%s\' in the room: \'%s\'' % (who, what, where) #TODO: add duration to message self.__syncplayClient.ui.showMessage(message) self.__syncplayClient.checkIfFileMatchesOthers() else: @@ -105,12 +105,12 @@ class SyncClientProtocol(CommandProtocol): self.__syncplayClient.ui.showMessage("Your version is %s against server's %s" % (syncplay.version, args[0])) self.__syncplayClient.ui.showMessage("Please use latest version of client and server") - @argumentCount(3) + @argumentCount(5) def playing(self, args): - who, where, what = args - message = '%s is playing \'%s\' in the room: \'%s\'' % (who, what, where) + who, where, what, duration, size = args + message = '%s is playing \'%s\' in the room: \'%s\'' % (who, what, where) #TODO: add duration to message self.__syncplayClient.ui.showMessage(message) - self.__syncplayClient.users.addUser(SyncplayClientManager.SyncplayUser(who, what, where)) + self.__syncplayClient.users.addUser(SyncplayClientManager.SyncplayUser(who, what, where, duration, size)) self.__syncplayClient.checkIfFileMatchesOthers() @argumentCount(1) @@ -139,19 +139,15 @@ class SyncClientProtocol(CommandProtocol): counter, ctime, state, position, who_changed_state = args else: return - if not state in ('paused', 'playing'): return - paused = state == 'paused' - try: counter = int(counter) ctime = int(ctime) position = int(position) except ValueError: return - ctime /= 1000.0 position /= 1000.0 @@ -173,13 +169,13 @@ class SyncClientProtocol(CommandProtocol): def send_room(self, where): self._protocol.sendMessage('room', where) - def send_playing(self, filename): - self._protocol.sendMessage('playing', filename) + def send_playing(self, filename, duration, size): + self._protocol.sendMessage('playing', filename, duration, size) class SyncClientFactory(ClientFactory): def __init__(self, manager, retry = 10): self.__syncplayClient = manager - self.retry = retry + self.retry = retry #add incremental wait def buildProtocol(self, addr): return SyncClientProtocol(self.__syncplayClient) @@ -348,7 +344,7 @@ class SyncplayClientManager(object): def sendPlaying(self): if self.protocol and self.users.currentUser.filename: - self.protocol.sender.send_playing(self.users.currentUser.filename) + self.protocol.sender.send_playing(self.users.currentUser.filename, self.users.currentUser.fileduration, self.users.currentUser.filesize) def updatePlayerStatus(self, paused, position): self.status_ask_received += 1 @@ -391,8 +387,8 @@ class SyncplayClientManager(object): def updateFile(self, filename, duration, path): filename = unicode(filename, errors='replace') self.users.currentUser.filename = filename.encode('ascii','replace') - self.users.currentUser.fileduration = duration - self.users.currentUser.filesize = os.path.getsize(path) + self.users.currentUser.fileduration = unicode(duration) + self.users.currentUser.filesize = unicode(os.path.getsize(path)) self.sendPlaying() def updateGlobalState(self, counter, ctime, paused, position, name): @@ -485,7 +481,7 @@ class SyncplayClientManager(object): self.__ui.showErrorMessage(message) class SyncplayUser(object): - def __init__(self, name = None, filename = None, room = None, filesize = None, fileduration = None): + def __init__(self, name = None, filename = None, room = None, fileduration = None, filesize = None): self.name = name self.room = room self.filename = filename diff --git a/syncplay/server.py b/syncplay/server.py index c1b69b9..eca98b1 100644 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -119,9 +119,9 @@ class SyncServerProtocol(CommandProtocol): self.factory.pong_received(self.__protocol, value, ctime) @state('connected') - @argumentCount(1) + @argumentCount(3) def playing(self, args): - self.factory.playing_received(self.__protocol, args[0]) + self.factory.playing_received(self.__protocol, args[0], args[1], args[2]) @state('connected') @@ -142,7 +142,7 @@ class SyncServerProtocol(CommandProtocol): for w in self.factory.watchers.itervalues(): if w == watcher: continue - self.__protocol.sender.send_present(w.name, w.room, w.filename) + self.__protocol.sender.send_present(w.name, w.room, w.filename, w.duration, w.size) @state('connected') @argumentCount(4) @@ -194,15 +194,15 @@ class SyncServerProtocol(CommandProtocol): def send_ping(self, value): self.__protocol.sendMessage('ping', value) - def send_playing(self, who, where, what): - self.__protocol.sendMessage('playing', who, where, what) + def send_playing(self, who, where, what, duration, size): + self.__protocol.sendMessage('playing', who, where, what, duration, size) def send_room(self, who, where): self.__protocol.sendMessage('room', who, where) - def send_present(self, who, where, what): + def send_present(self, who, where, what, duration, size): if what: - self.__protocol.sendMessage('present', who, where, what) + self.__protocol.sendMessage('present', who, where, what, duration, size) else: self.__protocol.sendMessage('present', who, where) @@ -222,7 +222,9 @@ class WatcherInfo(object): self.watcher_proto = watcher_proto self.name = name self.active = True - + self.duration = None + self.size = None + self.paused = True self.position = 0 self.filename = None @@ -429,12 +431,14 @@ class SyncFactory(Factory): def schedule_send_ping(self, watcher, when=1): reactor.callLater(when, self.send_ping_to, watcher) - def playing_received(self, watcher_proto, filename): + def playing_received(self, watcher_proto, filename, duration, size): watcher = self.watchers.get(watcher_proto) if not watcher: return watcher.filename = filename - self.broadcast(watcher, lambda receiver: receiver.watcher_proto.sender.send_playing(watcher.name, watcher.room, filename)) + watcher.duration = duration + watcher.size = size + self.broadcast(watcher, lambda receiver: receiver.watcher_proto.sender.send_playing(watcher.name, watcher.room, filename, duration, size)) def broadcast_room(self, sender, what): for receiver in self.watchers.itervalues():