本文整理汇总了Python中mpd.MPDClient.lsinfo方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.lsinfo方法的具体用法?Python MPDClient.lsinfo怎么用?Python MPDClient.lsinfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.lsinfo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import lsinfo [as 别名]
class Database:
def __init__( self, music_root ):
self._music_root = music_root
self._con = MPDClient()
self._con.timeout = 10
self._con.idletimeout = None
self._con.connect( 'localhost', 6600 )
def addToDb( self, song_obj ):
temp = song_obj.getInfo()['file']
while self._con.find( 'file', temp) == []:
try:
temp = temp.split( '/', 1 )[1]
except IndexError:
print( 'ERROR: Could not add. Please put the song (if it exists) under the mpd root.' )
break
if self._con.find( 'file', temp) != []:
self._con.update( temp )
def listDbDir( self, dir_loc ):
listings = []
for listing in self._con.lsinfo( dir_loc ):
temp = Song.Song( self._music_root + listing['file'] )
listings.append( temp )
return listings
def __del__( self ):
self._con.close()
示例2: dir_to_list
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import lsinfo [as 别名]
def dir_to_list(dir):
client = MPDClient()
client.connect("localhost", 6600)
client.use_unicode = True
lst = client.lsinfo(""+dir)
client.close()
out = [x["file"] for x in lst if "file" in x.keys()]
return out
示例3: list_tracks
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import lsinfo [as 别名]
def list_tracks():
client = MPDClient()
client.connect("localhost",6600)
try:
response = json.dumps(client.lsinfo())
except:
response = False
client.close()
client.disconnect()
return response
示例4: add_spotify_directory
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import lsinfo [as 别名]
def add_spotify_directory(name):
client=MPDClient()
mopidyAddress = 'localhost'
mopidyPort = 6600
client.timeout = 10
client.idletimeout = None
client.connect(mopidyAddress,mopidyPort)
#client.password('IlPits2013')
foldername = 'Spotify/{name:s}'.format(name=name)
files = client.lsinfo(foldername)
files = [x['file'] for x in files]
files = sorted(files)
for f in files:
client.add(f)
#print(files)
client.disconnect()
示例5: MPDWrapper
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import lsinfo [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()
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import lsinfo [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:
#.........这里部分代码省略.........