当前位置: 首页>>代码示例>>Python>>正文


Python MPDClient.command_list_ok_begin方法代码示例

本文整理汇总了Python中mpd.MPDClient.command_list_ok_begin方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.command_list_ok_begin方法的具体用法?Python MPDClient.command_list_ok_begin怎么用?Python MPDClient.command_list_ok_begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpd.MPDClient的用法示例。


在下文中一共展示了MPDClient.command_list_ok_begin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MPDWrapper

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import command_list_ok_begin [as 别名]
class MPDWrapper():

    def __init__(self, host, port):
        self.mpd = MPDClient(use_unicode=True)
        self.changes = Changes()
        self.host = host
        self.port = port
        self.connected = False
        self.in_idle = False

    def auth(self, password):
        if self.connected:
            try:
                self.mpd.password(password)
            except CommandError:
                return False
        return True

    def connect(self):
        try:
            self.mpd.connect(self.host, self.port)
            self.connected = True
        except SocketError:
            self.connected = False
        return self.connected

    def disconnect(self):
        if self.connected:
            self.mpd.disconnect()
            self.connected = False

    def fileno(self):
        return self.mpd.fileno()

    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()
#.........这里部分代码省略.........
开发者ID:dstenb,项目名称:tbmpcpy,代码行数:103,代码来源:wrapper.py

示例2: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import command_list_ok_begin [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()
开发者ID:BigfootN,项目名称:Dotfiles,代码行数:87,代码来源:musicinfo.py

示例3: Mpd2

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import command_list_ok_begin [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:
#.........这里部分代码省略.........
开发者ID:flacjacket,项目名称:qtile,代码行数:103,代码来源:mpd2widget.py


注:本文中的mpd.MPDClient.command_list_ok_begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。