Added checking file's size and duration
This commit is contained in:
parent
9013bff016
commit
aad15b6f5f
@ -1,3 +1,3 @@
|
|||||||
version = '0.5.0'
|
version = '0.6.0'
|
||||||
milestone = 'Clara'
|
milestone = 'Clara'
|
||||||
projectURL = 'http://droptable.co.cc'
|
projectURL = 'http://droptable.co.cc'
|
||||||
@ -55,17 +55,17 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
self.__syncplayClient.protocol.sender.send_list()
|
self.__syncplayClient.protocol.sender.send_list()
|
||||||
self.__syncplayClient.scheduleSendStatus()
|
self.__syncplayClient.scheduleSendStatus()
|
||||||
if(self.__syncplayClient.users.currentUser.filename <> None):
|
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):
|
def present(self, args):
|
||||||
if len(args) == 3:
|
if len(args) == 5:
|
||||||
who, where, what = args
|
who, where, what, duration, size = args
|
||||||
else:
|
else:
|
||||||
who, where, what = args[0], args[1], None
|
who, where, what, duration, size = args[0], args[1], None, None, None
|
||||||
self.__syncplayClient.users.addUser(SyncplayClientManager.SyncplayUser(who, what, where))
|
self.__syncplayClient.users.addUser(SyncplayClientManager.SyncplayUser(who, what, where, duration, size))
|
||||||
if what:
|
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.ui.showMessage(message)
|
||||||
self.__syncplayClient.checkIfFileMatchesOthers()
|
self.__syncplayClient.checkIfFileMatchesOthers()
|
||||||
else:
|
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("Your version is %s against server's %s" % (syncplay.version, args[0]))
|
||||||
self.__syncplayClient.ui.showMessage("Please use latest version of client and server")
|
self.__syncplayClient.ui.showMessage("Please use latest version of client and server")
|
||||||
|
|
||||||
@argumentCount(3)
|
@argumentCount(5)
|
||||||
def playing(self, args):
|
def playing(self, args):
|
||||||
who, where, what = args
|
who, where, what, duration, size = args
|
||||||
message = '%s is playing \'%s\' in the room: \'%s\'' % (who, what, where)
|
message = '%s is playing \'%s\' in the room: \'%s\'' % (who, what, where) #TODO: add duration to message
|
||||||
self.__syncplayClient.ui.showMessage(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()
|
self.__syncplayClient.checkIfFileMatchesOthers()
|
||||||
|
|
||||||
@argumentCount(1)
|
@argumentCount(1)
|
||||||
@ -139,19 +139,15 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
counter, ctime, state, position, who_changed_state = args
|
counter, ctime, state, position, who_changed_state = args
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not state in ('paused', 'playing'):
|
if not state in ('paused', 'playing'):
|
||||||
return
|
return
|
||||||
|
|
||||||
paused = state == 'paused'
|
paused = state == 'paused'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
counter = int(counter)
|
counter = int(counter)
|
||||||
ctime = int(ctime)
|
ctime = int(ctime)
|
||||||
position = int(position)
|
position = int(position)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return
|
return
|
||||||
|
|
||||||
ctime /= 1000.0
|
ctime /= 1000.0
|
||||||
position /= 1000.0
|
position /= 1000.0
|
||||||
|
|
||||||
@ -173,13 +169,13 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
def send_room(self, where):
|
def send_room(self, where):
|
||||||
self._protocol.sendMessage('room', where)
|
self._protocol.sendMessage('room', where)
|
||||||
|
|
||||||
def send_playing(self, filename):
|
def send_playing(self, filename, duration, size):
|
||||||
self._protocol.sendMessage('playing', filename)
|
self._protocol.sendMessage('playing', filename, duration, size)
|
||||||
|
|
||||||
class SyncClientFactory(ClientFactory):
|
class SyncClientFactory(ClientFactory):
|
||||||
def __init__(self, manager, retry = 10):
|
def __init__(self, manager, retry = 10):
|
||||||
self.__syncplayClient = manager
|
self.__syncplayClient = manager
|
||||||
self.retry = retry
|
self.retry = retry #add incremental wait
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
return SyncClientProtocol(self.__syncplayClient)
|
return SyncClientProtocol(self.__syncplayClient)
|
||||||
@ -348,7 +344,7 @@ class SyncplayClientManager(object):
|
|||||||
|
|
||||||
def sendPlaying(self):
|
def sendPlaying(self):
|
||||||
if self.protocol and self.users.currentUser.filename:
|
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):
|
def updatePlayerStatus(self, paused, position):
|
||||||
self.status_ask_received += 1
|
self.status_ask_received += 1
|
||||||
@ -391,8 +387,8 @@ class SyncplayClientManager(object):
|
|||||||
def updateFile(self, filename, duration, path):
|
def updateFile(self, filename, duration, path):
|
||||||
filename = unicode(filename, errors='replace')
|
filename = unicode(filename, errors='replace')
|
||||||
self.users.currentUser.filename = filename.encode('ascii','replace')
|
self.users.currentUser.filename = filename.encode('ascii','replace')
|
||||||
self.users.currentUser.fileduration = duration
|
self.users.currentUser.fileduration = unicode(duration)
|
||||||
self.users.currentUser.filesize = os.path.getsize(path)
|
self.users.currentUser.filesize = unicode(os.path.getsize(path))
|
||||||
self.sendPlaying()
|
self.sendPlaying()
|
||||||
|
|
||||||
def updateGlobalState(self, counter, ctime, paused, position, name):
|
def updateGlobalState(self, counter, ctime, paused, position, name):
|
||||||
@ -485,7 +481,7 @@ class SyncplayClientManager(object):
|
|||||||
self.__ui.showErrorMessage(message)
|
self.__ui.showErrorMessage(message)
|
||||||
|
|
||||||
class SyncplayUser(object):
|
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.name = name
|
||||||
self.room = room
|
self.room = room
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|||||||
@ -119,9 +119,9 @@ class SyncServerProtocol(CommandProtocol):
|
|||||||
self.factory.pong_received(self.__protocol, value, ctime)
|
self.factory.pong_received(self.__protocol, value, ctime)
|
||||||
|
|
||||||
@state('connected')
|
@state('connected')
|
||||||
@argumentCount(1)
|
@argumentCount(3)
|
||||||
def playing(self, args):
|
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')
|
@state('connected')
|
||||||
@ -142,7 +142,7 @@ class SyncServerProtocol(CommandProtocol):
|
|||||||
for w in self.factory.watchers.itervalues():
|
for w in self.factory.watchers.itervalues():
|
||||||
if w == watcher:
|
if w == watcher:
|
||||||
continue
|
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')
|
@state('connected')
|
||||||
@argumentCount(4)
|
@argumentCount(4)
|
||||||
@ -194,15 +194,15 @@ class SyncServerProtocol(CommandProtocol):
|
|||||||
def send_ping(self, value):
|
def send_ping(self, value):
|
||||||
self.__protocol.sendMessage('ping', value)
|
self.__protocol.sendMessage('ping', value)
|
||||||
|
|
||||||
def send_playing(self, who, where, what):
|
def send_playing(self, who, where, what, duration, size):
|
||||||
self.__protocol.sendMessage('playing', who, where, what)
|
self.__protocol.sendMessage('playing', who, where, what, duration, size)
|
||||||
|
|
||||||
def send_room(self, who, where):
|
def send_room(self, who, where):
|
||||||
self.__protocol.sendMessage('room', 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:
|
if what:
|
||||||
self.__protocol.sendMessage('present', who, where, what)
|
self.__protocol.sendMessage('present', who, where, what, duration, size)
|
||||||
else:
|
else:
|
||||||
self.__protocol.sendMessage('present', who, where)
|
self.__protocol.sendMessage('present', who, where)
|
||||||
|
|
||||||
@ -222,6 +222,8 @@ class WatcherInfo(object):
|
|||||||
self.watcher_proto = watcher_proto
|
self.watcher_proto = watcher_proto
|
||||||
self.name = name
|
self.name = name
|
||||||
self.active = True
|
self.active = True
|
||||||
|
self.duration = None
|
||||||
|
self.size = None
|
||||||
|
|
||||||
self.paused = True
|
self.paused = True
|
||||||
self.position = 0
|
self.position = 0
|
||||||
@ -429,12 +431,14 @@ class SyncFactory(Factory):
|
|||||||
def schedule_send_ping(self, watcher, when=1):
|
def schedule_send_ping(self, watcher, when=1):
|
||||||
reactor.callLater(when, self.send_ping_to, watcher)
|
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)
|
watcher = self.watchers.get(watcher_proto)
|
||||||
if not watcher:
|
if not watcher:
|
||||||
return
|
return
|
||||||
watcher.filename = filename
|
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):
|
def broadcast_room(self, sender, what):
|
||||||
for receiver in self.watchers.itervalues():
|
for receiver in self.watchers.itervalues():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user