Dla mpc dodana obsuga config file
refaktoryzacja kodu
This commit is contained in:
parent
3a25110adf
commit
575c30bbe9
26
sync_mpc.py
26
sync_mpc.py
@ -1,32 +1,16 @@
|
||||
#coding:utf8
|
||||
import thread
|
||||
import sys, os
|
||||
import sys
|
||||
|
||||
from twisted.internet import reactor
|
||||
|
||||
from syncplay import client
|
||||
from syncplay.players import mpc
|
||||
|
||||
def stdin_thread(sock):
|
||||
try:
|
||||
fd = sys.stdin.fileno()
|
||||
while True:
|
||||
data = os.read(fd, 1024)
|
||||
if not data:
|
||||
break
|
||||
sock.execute_command(data.rstrip('\n\r'))
|
||||
except:
|
||||
pass
|
||||
|
||||
import common_functions
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv[1:]
|
||||
host = args.pop(0)
|
||||
name = args.pop(0)
|
||||
if ':' in host:
|
||||
host, port = host.split(':', 1)
|
||||
port = int(port)
|
||||
else:
|
||||
port = 8999
|
||||
host,port, name = common_functions.get_configuration()
|
||||
manager = client.Manager(host, port, name, lambda m: mpc.run_mpc(m))
|
||||
thread.start_new_thread(stdin_thread, (manager,))
|
||||
thread.start_new_thread(common_functions.stdin_thread, (manager,))
|
||||
manager.start()
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
#coding:utf8
|
||||
|
||||
import thread
|
||||
import sys
|
||||
|
||||
from twisted.internet import reactor
|
||||
|
||||
from syncplay import client
|
||||
from syncplay.players import mplayer
|
||||
|
||||
|
||||
import common_functions
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv[1:]
|
||||
host = args.pop(0)
|
||||
@ -20,5 +22,6 @@ if __name__ == '__main__':
|
||||
args.extend(('-slave', '-msglevel', 'all=1:global=4'))
|
||||
|
||||
manager = client.Manager(host, port, name, lambda m: mplayer.run_mplayer(m, 'mplayer', args))
|
||||
thread.start_new_thread(common_functions.stdin_thread, (manager,))
|
||||
manager.start()
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ from .utils import (
|
||||
class SyncClientProtocol(CommandProtocol):
|
||||
def __init__(self, manager):
|
||||
CommandProtocol.__init__(self)
|
||||
|
||||
self.manager = manager
|
||||
|
||||
def connectionMade(self):
|
||||
@ -101,7 +100,6 @@ class SyncClientProtocol(CommandProtocol):
|
||||
def send_playing(self, filename):
|
||||
self.send_message('playing', filename)
|
||||
|
||||
|
||||
states = dict(
|
||||
init = dict(
|
||||
present = 'handle_init_present',
|
||||
@ -280,22 +278,33 @@ class Manager(object):
|
||||
if self.protocol and self.player_filename:
|
||||
self.protocol.send_playing(self.player_filename)
|
||||
|
||||
def execute_command(self, data):
|
||||
RE_SEEK = re.compile("^s ?(\d+)?(:(\d{1,2}))?$")
|
||||
m = RE_SEEK.match(data)
|
||||
if m :
|
||||
minutes, seconds = m.group(1), m.group(3)
|
||||
if minutes <> None:
|
||||
minutes = int(minutes) * 60
|
||||
else:
|
||||
minutes = 0
|
||||
def exectue_seek_cmd(self, seek_type, minutes, seconds):
|
||||
self.player_position_before_last_seek = self.player_position
|
||||
if seek_type == 's':
|
||||
self.counter += 1
|
||||
if seconds <> None:
|
||||
seconds = int(seconds)
|
||||
else:
|
||||
seconds = 0
|
||||
self.player_position_before_last_seek = self.player_position
|
||||
self.counter += 1
|
||||
self.protocol.send_seek(self.counter, time.time(), minutes+seconds)
|
||||
if minutes <> None:
|
||||
seconds += int(minutes) * 60
|
||||
self.protocol.send_seek(self.counter, time.time(), seconds)
|
||||
else: #seek_type s+
|
||||
if seconds <> None:
|
||||
seconds = int(seconds)
|
||||
else:
|
||||
seconds = 20
|
||||
if minutes <> None:
|
||||
seconds += int(minutes) * 60
|
||||
else:
|
||||
seconds += 60
|
||||
self.protocol.send_seek(self.counter, time.time(), self.player_position+seconds)
|
||||
|
||||
def execute_command(self, data):
|
||||
RE_SEEK = re.compile("^(s[+s]?) ?(-?\d+)?([^0-9](\d+))?$")
|
||||
matched_seek = RE_SEEK.match(data)
|
||||
if matched_seek :
|
||||
self.exectue_seek_cmd(matched_seek.group(1), matched_seek.group(2), matched_seek.group(4))
|
||||
elif data == "r":
|
||||
self.counter += 1
|
||||
tmp_pos = self.player_position
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user