本文整理汇总了Python中mpd.MPDClient.enableoutput方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.enableoutput方法的具体用法?Python MPDClient.enableoutput怎么用?Python MPDClient.enableoutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.enableoutput方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import enableoutput [as 别名]
#.........这里部分代码省略.........
self.status = {}
self.outputs = {}
self.client = MPDClient()
self.connected = self.mpd_connect()
if self.connected:
if self.list_mode:
if 'shared' in self.list_mode:
playlists = self.client.lsinfo(self.playlist_folder)
for pls in playlists:
plsid = pls.get("playlist","")
if len(plsid) > 0:
try:
self.playlists['shared'].append((plsid,
'shd'+plsid))
except KeyError:
self.playlists['shared'] = []
self.playlists['shared'].append((plsid,
'shd_'+plsid))
if 'server' in self.list_mode:
playlists = self.client.lsinfo(self.playlist_folder)
for pls in playlists:
plsid = pls.get("playlist","")
if len(plsid) > 0:
try:
self.playlists['server'].append((plsid,
'srv_'+plsid))
except KeyError:
self.playlists['server'] = []
self.playlists['server'].append((plsid,
'srv_'+plsid))
self.update_data()
def mpd_connect(self):
"""connect to mpd service"""
try:
self.client.connect(self.host, self.port)
except socket.error:
return False
return True
def mpd_reconnect(self):
"""reconnect to mpd service"""
self.client.disconnect()
self.connected = self.mpd_connect()
def update_data(self):
"""update data from mpd service"""
if self.connected:
try:
status = self.client.status()
self.status = dict([
('state',status.get('state','stop')),
('time',status.get('time', '0:000')),
('volume',status.get('volume', 0))
])
self.current = self.client.currentsong()
next_song_id = status.get('nextsong', -1)
try:
self.next_song = self.client.playlistinfo(next_song_id)[0]
except (CommandError, IndexError):
self.next_song = {}
_decode_utf8(self.current)
_decode_utf8(self.next_song)
self.outputs = self.client.outputs()
except ConnectionError:
self.mpd_reconnect()
def ctrl(self, action):
"""execute a mpd command"""
if self.connected:
if action == 'ply':
self.client.play()
elif action == 'pse':
self.client.pause()
elif action == 'vup':
status = self.client.status()
volume = int(status.get('volume', 0))
try:
self.client.setvol(min(volume + _VOLUME_STEP, 100))
except CommandError:
pass
elif action == 'vdn':
status = self.client.status()
volume = int(status.get('volume', 0))
try:
self.client.setvol(max(volume - _VOLUME_STEP, 0))
except CommandError:
pass
elif action == 'rew':
self.client.previous()
elif action == 'fwd':
self.client.next()
elif action[:1] == 'o':
outid = int(action[1:])
for output in self.outputs:
if int(output['outputid']) == outid:
if output['outputenabled'] == '1':
self.client.disableoutput(outid)
else:
self.client.enableoutput(outid)
示例2: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import enableoutput [as 别名]
class BotHelper:
def __init__(self, sensors, rrd, log_path,mpd_event,hub_ctrl = None, mpd_host='localhost',mpd_port='6600'):
self.sensors = sensors
self.worker_thread_mpd = None
self.running_thread = False
self.started = False
self.rrd = rrd
self.hub_ctrl = hub_ctrl
self.mpd_event = mpd_event
self.mpd_client = MPDClient() # create client object
self.mpd_client.timeout = 10 # network timeout in seconds (floats allowed), default: None
self.mpd_client.idletimeout = None # timeout for fetching the result of the idle command is handled seperately, default: None
self.mpd_client.connect(mpd_host, mpd_port) # connect to localhost:6600
# logging config
logging.basicConfig(level=logging.ERROR)
pp = pprint.PrettyPrinter(indent=4)
formatter = logging.Formatter('%(asctime)s %(message)s')
logger = logging.getLogger('')
logger.setLevel(logging.INFO)
fh = logging.FileHandler(log_path)
fh.setLevel(logging.INFO)
fh.setFormatter(formatter)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
ch.setFormatter(formatter)
logger.addHandler(ch)
logger.info("Init")
def get_mpd_state(self):
#return self.mpd_client.status()
pass
def mpd_worker(self):
self.running_thread = True
logging.info("===Starting thread for mpd status listener===")
last_state = None
self.off = False
self.just_off = False
while self.running_thread:
self.mpd_client.idle()
logging.info("===Waiting thread mpd status===")
status = self.mpd_client.status()
logging.info("===Status event in thread mpd===")
state = status['state']
print str(status)
logging.info("Music change state: "+str(status['state']) + " last state: "+str(last_state))
result = self.sensors.active_sound_detector
if state =='play' and last_state!='play' and last_state!=None:
result = self.sensors.detect_sound(True)
if state =='stop' and last_state!='stop' and last_state!=None:
result = self.sensors.detect_sound(False)
# usb ports off (audio usb)
if self.hub_ctrl != None:
self.mpd_client.disableoutput(0)
time.sleep(2)
self.power_off_usbs();
logging.info("Power off usbs")
self.off=True
# since we disabled output mpd_cliend.idle will issue new event with status stop again
self.just_off = True
# usb ports on (audio usb)
if state =='stop' and last_state=='stop':
if self.just_off:
# just power off consuming dsiableoutput event
self.just_off = False;
elif self.off and self.hub_ctrl != None:
# if this is a play command it will not work since power is off but will poweron usb for next command
self.power_on_usbs();
logging.info("Power on usbs")
self.off = False
time.sleep(2)
self.mpd_client.enableoutput(0)
last_state = state
if hasattr(self,'mpd_event'):
self.mpd_event(result);
logging.info("===Ending thread for mpd status listener===\n")
def run(self):
if not self.started:
self.sensors.detect_all(True)
self.worker_thread_mpd = threading.Thread(target=self.mpd_worker)
self.worker_thread_mpd.start()
self.started = True
return True;
else:
return False;
def stop(self):
if self.started:
self.sensors.detect_all(False)
#.........这里部分代码省略.........
示例3: Ajax
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import enableoutput [as 别名]
#.........这里部分代码省略.........
if i > last:
return "Unknown song"
self.client.move(i, i-1)
return "Move up"
def ajax_mpd_movedown(self, args):
try:
i = int(args.get('i'))
except ValueError:
return "Unknown song"
if i < 0:
return "Unknown song"
self.mpd_connect()
status = self.client.status()
last = int(status['playlistlength']) - 1
if i >= last:
return "Can't move last song down"
self.client.move(i, i+1)
return "Move down"
def ajax_mpd_requeue(self, args):
try:
i = int(args.get('i'))
except ValueError:
return "Unknown song"
if i < 0:
return "Unknown song"
self.mpd_connect()
status = self.client.status()
last = int(status['playlistlength']) - 1
self.client.move(i, last)
return "Requeued"
def ajax_mpd_enableoutput(self, args):
try:
i = int(args.get('i'))
except ValueError:
return "Unknown output"
if i < 0:
return "Unknown output"
self.mpd_connect()
self.client.enableoutput(i)
return "Output enabled"
def ajax_mpd_disableoutput(self, args):
try:
i = int(args.get('i'))
except ValueError:
return "Unknown output"
if i < 0:
return "Unknown output"
self.mpd_connect()
self.client.disableoutput(i)
return "Output disabled"
def ajax_html_playlist(self, args):
self.mpd_connect()
pl = self.client.playlistinfo()
map(self.fix_pl, pl)
status = self.client.status()
if 'song' not in status:
status['song'] = -1
mpd_status = 'unknown'
if status['state'] == 'play':
mpd_status = 'playing song %d' % (int(status['song']) + 1)