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


Python MPDClient.outputs方法代码示例

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


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

示例1: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import outputs [as 别名]
class Audio:
    """class representing a single player connected to one mpd instance"""
    def __init__(self, config):
        self.pid = config["id"]       
        self.name = config.get("name", "")
        self.host = config["host"]
        self.port = config.get("port", 6600)
        self.password = config.get("password")
        self.list_mode = config.get("list_mode", False)
        self.playlist_folder = config.get("playlist_folder", '/')
        self.playlists = {}
        self.current = {}
        self.next_song = {}
        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:
#.........这里部分代码省略.........
开发者ID:d-s-e,项目名称:aulosplayer,代码行数:103,代码来源:audioclient.py

示例2: MPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import outputs [as 别名]
from mpd import MPDClient
MPD_SOCKET = '/home/pineman/.config/mpd/socket'
client = MPDClient()
client.connect(MPD_SOCKET, 0)

def get_mpd_data():
	idle = client.idle()
	if idle[0] == 'player':
		state = client.status()['state']
		print(state)
		wanted = ['play', 'pause']
		if state in wanted:
			info = client.currentsong()
			try:
				artist = info['artist']
				title = info['title']
				value = '{0} - {1}'.format(artist, title)
			except KeyError:
				filename = info['file']
				value = filename.split('/')[-1][:-4]
			finally:
				data = {'song': value}
				return data

print(client.outputs())
开发者ID:pineman,项目名称:code,代码行数:27,代码来源:test_mpd.py

示例3: Ajax

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import outputs [as 别名]

#.........这里部分代码省略.........
            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)
        if status['state'] == 'stop':
            mpd_status = 'stopped'
        if status['state'] == 'pause':
            mpd_status = 'paused'
        return render_template('playlist.html', pl=pl, mpd_status=mpd_status, song=status['song'])

    def ajax_html_streams(self, args):
        return render_template('streams.html', streams=self.config['streams'])

    def ajax_html_outputs(self, args):
        self.mpd_connect()
        outputs = self.client.outputs()
        return render_template('outputs.html', outputs=outputs)

    def ajax_json_mpd_idle(self, args):
        self.mpd_connect()
        #idle = self.client.idle('playlist')
        idle = self.client.idle()
        return json.dumps(idle)

    def serve_file(self, fileid):
        sql = select([self.db_songtable], self.db_songtable.c.id == fileid)
        rows = self.dbc.execute(sql).fetchall()
        if len(rows):
            row=rows[0]
            fname = os.path.join(row['path'], row['filename']).encode('utf-8')
            if os.path.exists(fname):
                return send_file(fname, as_attachment=True)
        abort(404)

    def playlist(self, fileid, fmt):
        sql = select([self.db_songtable], self.db_songtable.c.id == fileid)
        rows = self.dbc.execute(sql).fetchall()
        if fmt == 'm3u':
            return Response(render_template('playlist.m3u', rows=rows), mimetype='audio/x-mpegurl')
        if fmt == 'pls':
            return Response(render_template('playlist.pls', rows=rows, num=len(rows)), mimetype='audio/x-scpls')
        abort(404)

    def dir_playlist(self, args, fmt):
        try:
            path = args.get('p')
        except ValueError:
            return
        path = re.sub(r"/+", "/", path.rstrip('/'))
        rows = self.get_songs(args, path)
        if fmt == 'm3u':
            return Response(render_template('playlist.m3u', rows=rows), mimetype='audio/x-mpegurl')
        if fmt == 'pls':
            return Response(render_template('playlist.pls', rows=rows, num=len(rows)), mimetype='audio/x-scpls')
        abort(404)

    def folder_jpg(self, args):
        try:
            path = args.get('p')
        except ValueError:
            return
        path = re.sub(r"/+", "/", path.rstrip('/')).rstrip('#')
        pdir = os.path.realpath(re.sub (r"/+", "/", self.config['rootdir'] + '/' + path))
        # The result has to start with the configured rootdir
        if pdir[0:len(self.config['rootdir'])] != self.config['rootdir']:
            abort(404)

        fname = os.path.join(pdir, 'folder.jpg').encode('utf-8')
        if os.path.exists(fname):
            return send_file(fname)
        return send_file(os.path.join(os.path.dirname(__file__), 'static', 'no_image.jpg'))
        abort(404)

    # This method gets called if the requested AJAX function
    # does not exist as a method on this class
    def default_response(self, args):
        abort(404)
开发者ID:tinuzz,项目名称:traxx,代码行数:104,代码来源:traxxjax.py


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