本文整理汇总了Python中mpd.MPDClient.command_list_end方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.command_list_end方法的具体用法?Python MPDClient.command_list_end怎么用?Python MPDClient.command_list_end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.command_list_end方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MPDWrapper
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import command_list_end [as 别名]
#.........这里部分代码省略.........
def get_changes(self):
return self.changes.get() if not self.in_idle else []
def has_changes(self):
return len(self.changes.changes)
def idle(self):
if self.connected and not self.in_idle:
self.in_idle = True
self.mpd.send_idle()
return self.in_idle
def noidle(self, block=False):
if self.connected and self.in_idle:
self.in_idle = False
if not block:
self.mpd.send_noidle()
self.changes.add(*self.mpd.fetch_idle())
def player(self, cmd, *args):
if self.connected:
self.changes.add("player")
self.noidle()
getattr(self.mpd, cmd)(*args)
def option(self, cmd, *args):
if self.connected:
self.changes.add("options")
self.noidle()
getattr(self.mpd, cmd)(*args)
def status(self):
return self.mpd.status() if self.connected else None
def ls(self, path):
return self.mpd.lsinfo(path) if self.connected else []
def plchanges(self, version):
return self.mpd.plchanges(version) if self.connected else []
def plchangesposid(self, version):
return self.mpd.plchangesposid(version) if self.connected else []
def add(self, path):
if self.connected:
self.changes.add("playlist")
self.noidle()
self.mpd.add(path)
def add_and_play(self, path):
if self.connected:
self.changes.add("playlist", "player")
self.noidle()
self.mpd.playid(self.mpd.addid(path))
def clear(self):
if self.connected:
self.changes.add("playlist", "player")
self.noidle()
self.mpd.clear()
def delete(self, *poslist):
if self.connected:
self.changes.add("playlist", "player")
self.noidle()
self.mpd.command_list_ok_begin()
for p in poslist:
self.mpd.delete(p)
self.mpd.command_list_end()
def update(self, path=""):
if self.connected:
self.noidle()
self.mpd.update(path)
def playlist_song(self, songid):
return Song(self.mpd.playlistid(songid)[0])
# Fallback if seekcur command isn't available
def _seekcur_fallback(self, posstr):
status = self.status()
time = posstr
if any(posstr.startswith(c) for c in "+-"):
time = str(elapsed_sec(status) + int(posstr))
getattr(self.mpd, "seek")(status.get("song", "-1"), time)
def seekcur(self, posstr):
if self.connected:
self.changes.add("player")
self.noidle()
try:
getattr(self.mpd, "seekcur")(posstr)
except CommandError as e:
if not unknown_command_error(e, "seekcur"):
raise
self._seekcur_fallback(posstr)
def current_song(self):
d = self.mpd.currentsong()
return Song(d) if d else None
示例2: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import command_list_end [as 别名]
class MpdPlayer:
def __init__(self, host, port):
self._host = host
self._port = port
self._client = MPDClient()
self._client.timeout = 10
self._client.idletimeout = None
self._map_commands = {PlayerCommand.NEXT: self._next,
PlayerCommand.PAUSE: self._pause,
PlayerCommand.STOP: self._stop,
PlayerCommand.PREV: self._prev,
PlayerCommand.PLAY_PAUSE: self._play_pause,
PlayerCommand.PLAY: self._play}
def connect(self):
ret = False
try:
self._client.connect(self._host, self._port)
ret = True
except BaseException:
pass
return ret
def call_command(self, command):
command = self._map_commands[command]
command()
def status(self, command):
self._client.command_list_ok_begin()
self._client.status()
status = self._client.command_list_end()[0]["status"]
if not status == "play":
self._play()
else:
self._pause()
def is_up(self):
ret = False
try:
MPDClient().connect(self._port, self._host)
ret = True
except BaseException:
pass
return ret
def current_song(self):
ret = Song()
self._client.command_list_ok_begin()
self._client.currentsong()
mpd_song = self._client.command_list_end()[0]
ret.artist = mpd_song['artist']
ret.album = mpd_song['album']
ret.title = mpd_song['title']
ret.year = int(mpd_song['date'])
return ret
def _pause(self):
self._client.command_list_ok_begin()
self._client.pause(1)
self._client.command_list_end()
def _play(self):
self._client.command_list_ok_begin()
self._client.play()
self._client.command_list_end()
def _next(self):
self._client.command_list_ok_begin()
self._client.next()
self._client.command_list_end()
def _prev(self):
self._client.command_list_ok_begin()
self._client.previous()
self._client.command_list_end()
def _stop(self):
self._client.command_list_ok_begin()
self._client.stop()
self._client.command_list_end()
def _play_pause(self):
self._client.command_list_ok_begin()
self._client.stop()
self._client.command_list_end()
示例3: Mpd2
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import command_list_end [as 别名]
class Mpd2(base.ThreadPoolText):
"""A widget for Music Player Daemon (MPD) based on python-mpd2
This widget exists since python-mpd library is no more supported.
Parameters
==========
status_format :
format string to display status
Full list of values see in ``status`` and ``currentsong`` commands
https://musicpd.org/doc/protocol/command_reference.html#command_status
https://musicpd.org/doc/protocol/tags.html
Default::
{play_status} {artist}/{title} [{repeat}{random}{single}{consume}{updating_db}]
``play_status`` is string from ``play_states`` dict
Note that ``time`` property of song renamed to ``fulltime`` to prevent
conflicts with status information during formating.
prepare_status :
dict of functions for replace values in status with custom
``f(status, key, space_element) => str``
"""
orientations = base.ORIENTATION_HORIZONTAL
defaults = [
('update_interval', 1, 'Interval of update widget'),
('host', 'localhost', 'Host of mpd server'),
('port', 6600, 'Port of mpd server'),
('password', None, 'Password for auth on mpd server'),
('keys', keys, 'Shortcut keys'),
('play_states', play_states, 'Play state mapping'),
('command', None, 'Executable command by "command" shortcut'),
('timeout', 30, 'MPDClient timeout'),
('idletimeout', 5, 'MPDClient idle command timeout'),
('no_connection', 'No connection', 'Text when mpd is disconnected'),
('space', '-', 'Space keeper')
]
def __init__(self, status_format=default_format,
prepare_status=prepare_status, **config):
super().__init__(None, **config)
self.add_defaults(Mpd2.defaults)
self.status_format = status_format
self.prepare_status = prepare_status
self.connected = False
self.client = MPDClient()
self.client.timeout = self.timeout
self.client.idletimeout = self.idletimeout
self.try_reconnect()
def try_reconnect(self):
if not self.connected:
try:
self.client.ping()
except(socket_error, ConnectionError):
try:
self.client.connect(self.host, self.port)
if self.password:
self.client.password(self.password)
self.connected = True
except(socket_error, ConnectionError, CommandError):
self.connected = False
def poll(self):
self.try_reconnect()
if self.connected:
return self.update_status()
else:
return self.no_connection
def update_status(self):
self.client.command_list_ok_begin()
self.client.status()
self.client.currentsong()
status, current_song = self.client.command_list_end()
return self.formatter(status, current_song)
# TODO: Resolve timeouts on the method call
def button_press(self, x, y, button):
self.try_reconnect()
if self.connected:
self[button]
def __getitem__(self, key):
if key == self.keys["toggle"]:
status = self.client.status()
play_status = status['state']
if play_status == 'play':
self.client.pause()
else:
#.........这里部分代码省略.........