本文整理汇总了Python中mpd.MPDClient.playlistinfo方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.playlistinfo方法的具体用法?Python MPDClient.playlistinfo怎么用?Python MPDClient.playlistinfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.playlistinfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: currentTrack
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def currentTrack(self, i3status_output_json, i3status_config):
try:
c = MPDClient()
c.connect(host=HOST, port=PORT)
if PASSWORD:
c.password(PASSWORD)
status = c.status()
song = int(status.get("song", 0))
next_song = int(status.get("nextsong", 0))
if (status["state"] == "pause" and HIDE_WHEN_PAUSED) or (status["state"] == "stop" and HIDE_WHEN_STOPPED):
text = ""
else:
try:
song = c.playlistinfo()[song]
song["time"] = "{0:.2f}".format(int(song.get("time", 1)) / 60)
except IndexError:
song = {}
try:
next_song = c.playlistinfo()[next_song]
except IndexError:
next_song = {}
format_args = song
format_args["state"] = STATE_CHARACTERS.get(status.get("state", None))
for k, v in next_song.items():
format_args["next_{}".format(k)] = v
text = STRFORMAT
for k, v in format_args.items():
text = text.replace("{" + k + "}", v)
for sub in re.findall(r"{\S+?}", text):
text = text.replace(sub, "")
except SocketError:
text = "Failed to connect to mpd!"
except CommandError:
text = "Failed to authenticate to mpd!"
c.disconnect()
if len(text) > MAX_WIDTH:
text = text[-MAX_WIDTH-3:] + "..."
if self.text != text:
transformed = True
self.text = text
else:
transformed = False
response = {
'cached_until': time() + CACHE_TIMEOUT,
'full_text': self.text,
'name': 'scratchpad-count',
'transformed': transformed
}
return (POSITION, response)
示例2: play_MPD
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def play_MPD(path):
""" Joue MPD avec comme argument le chemin du fichier à jouer """
client = MPDClient() # create client object
client.timeout = 10 # network timeout in seconds (floats allowed), default: None
client.idletimeout = None
client.connect("localhost", 6600) # connect to localhost:6600
MPDClient.add(path)
client.play(0)
print MPDClient.playlistinfo()
示例3: print_files
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def print_files():
sync_files = open('/media/satellite_mpds/files2sync.txt','a')
client=MPDClient()
mopidyAddress = 'localhost'
mopidyPort = 6600
client.timeout = 10
client.idletimeout = None
client.connect(mopidyAddress,mopidyPort)
#client.password('IlPits2013')
files = client.playlistinfo()
# files = client.lsinfo(foldername)
files = [x['file'] for x in files]
files = sorted(files)
outfiles=[]
for f in files:
real_path=os.path.join(music_dir,f)
if os.path.exists(real_path):
if os.path.islink(real_path):
target_path = os.readlink(real_path)
abs_target_path = os.path.realpath(real_path)
target_path_rel_to_music_dir = os.path.relpath(abs_target_path, music_dir)
print target_path_rel_to_music_dir
sync_files.write(target_path_rel_to_music_dir+'\n')
outfiles.append(target_path_rel_to_music_dir)
sync_files.write(f+'\n')
outfiles.append(f)
print('ADDED')
print f
sync_files.close()
#print(files)
client.disconnect()
示例4: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
class Player:
def __init__(self):
self.client = MPDClient()
self.client.connect("localhost", 6600)
self.client.timeout = 10
self.client.idletimeout = None
def quit(self):
self.client.close()
self.client.disconnect()
def get_playlists(self):
val = self.client.listplaylists()
return val
def get_playing(self):
name = "unknown"
val = self.client.playlistinfo()
if(len(val)>0):
print val[0]
name = val[0]["name"]
return name
def load(self,list):
print "loading list", list
self.client.clear()
self.client.load(list)
def play(self):
self.client.play()
def stop(self):
self.client.stop()
示例5: onevent
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def onevent(msg):
# add song if needed
client = MPDClient()
client.connect("localhost", 6600)
client.use_unicode = True
if client.status()["playlistlength"] == '0' and autoaddstate == 1:
song = choose_from_list(current_list)
client.add(song)
# while client.status()['state']=='stop':
client.play()
# currentsong info
if 'player' in msg or 'playlist' in msg:
print("publish currentsong")
currentsong = client.currentsong()
print(currentsong)
# pre-treat the data if artist/title not present:
if 'title' not in currentsong.keys():
currentsong['artist'] = "?"
if 'file' in currentsong.keys():
currentsong['title'] = currentsong['file'].split('/')[-1]
yield app.session.publish('radio.updatesong', currentsong)
# player status info
if ('player' in msg or
'mixer' in msg or
'options' in msg or
'playlist' in msg):
print("publish player status")
status = client.status()
status[u'autoadd'] = autoaddstate
yield app.session.publish('radio.updatestatus', status)
# playlist info
if 'playlist' in msg:
print("publish playlist")
playlist = client.playlistinfo()
print(playlist)
playlist_trim = []
for song in playlist:
song_trim = {}
if 'http' in song['file']:
song_trim['artist'] = song['file']
song_trim['title'] = ''
song_trim['time'] = 9999
song_trim['id'] = song['id']
else:
if 'title' not in song.keys() or 'artist' not in song.keys():
song_trim['artist'] = "?"
if 'file' in song.keys():
song_trim['title'] = song['file'].split('/')[-1]
else:
song_trim['artist'] = song['artist']
song_trim['title'] = song['title']
song_trim['id'] = song['id']
song_trim['time'] = song['time']
playlist_trim.append(song_trim)
yield app.session.publish('radio.updateplaylist', playlist_trim)
client.close()
示例6: Observer
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
class Observer(QThread):
"""MPD Observer thread."""
def __init__(self):
self._config = ServiceLocator.getGlobalServiceInstance(ServiceNames.Configuration)
self.client = MPDClient()
return QThread.__init__(self)
def __del__(self):
self.wait()
def mpdConnect(self):
self.client.timeout = 10
self.client.idletimeout = None
self.client.connect(self._config.mpdserver, self._config.mpdport)
if len(self._config.mpdpassword) > 0:
self.client.password(self._config.mpdpassword)
self.client.update()
def run(self):
try:
self.mpdConnect()
while True:
info = self.client.idle()
print("info:{0}".format(info))
if 'update' in info:
# Update all
self.updatePlaylist()
self.updatePlayer()
self.updateMixer()
if 'playlist' in info:
self.updatePlaylist()
if 'player' in info:
self.updatePlayer()
self.updateMixer()
if 'mixer' in info:
self.updateMixer()
self.sleep(2)
except:
self.emit(SIGNAL(ObserverSignals.ConnectionError))
pass
def updatePlaylist(self):
playlist = self.client.playlistinfo()
self.emit(SIGNAL(ObserverSignals.PlaylistChanged), playlist)
pass
def updateMixer(self):
status = self.client.status()
self.emit(SIGNAL(ObserverSignals.MixerChanged), status)
pass
def updatePlayer(self):
currentSong = self.client.currentsong()
self.emit(SIGNAL(ObserverSignals.PlayerChanged), currentSong)
pass
示例7: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
class Client:
client = None
def __init__(self):
self.client = MPDClient()
self.client.timeout = 10
self.client.idletimeout = None
self.client.connect("localhost", 6600)
def version(self):
return self.client.mpd_version
def getstatus(self):
return self.client.status()
def getcurrentsong(self):
return self.client.currentsong()
def getplaylist(self):
xs = []
for (id , file) in enumerate(self.client.playlistid()):
xs.append({'file' : file, 'id' : id})
return xs
def getplaylistsong(self,songid):
return self.client.playlistinfo()[songid]
def player(self,option):
if option == "pause":
self.client.pause(1)
else:
getattr(self.client, option)()
def playid(self,songid):
try:
self.client.playlistid(songid)
except:
return False
self.client.playid(songid)
return True
def getplayerstatus(self):
return self.client.status()["state"]
def previous(self):
self.client.previous()
return self.getcurrentsong()
def next(self):
self.client.next()
return self.getcurrentsong()
def random(self, active):
return self.client.random(active)
def repeat(self, active):
return self.client.repeat(active)
示例8: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def main():
## MPD object instance
client = MPDClient()
if mpdConnect(client, CON_ID):
print 'Got connected!'
else:
print 'fail to connect MPD server.'
sys.exit(1)
## Fancy output
pp = pprint.PrettyPrinter(indent=4)
currentsong = client.currentsong()
print '\nCurrent song file path:'
pp.pprint(currentsong)
##songfile = currentsong['file']
##pp.pprint(string.split(songfile, '/'))
print '\nCurrent playlist:'
pp.pprint(client.playlistinfo())
file_currentsong = open("/tmp/currentsong", 'w')
file_playlist = open("/tmp/playlist", 'w')
cPickle.dump(client.playlistinfo(), file_playlist);
cPickle.dump(currentsong, file_currentsong);
示例9: get_info
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def get_info(track_pos):
client = MPDClient()
client.connect("localhost", 6600)
if int(track_pos) < 0:
response = False
else:
try:
response = json.dumps(client.playlistinfo(track_pos))
except:
response = False
client.close()
client.disconnect()
return response
示例10: index
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def index():
client = MPDClient()
client.connect("localhost", 6600)
# Get song(s) in the playlist
playlist = client.playlistinfo()
# Get current song
current = client.currentsong()
# Get status
status = client.status()
client.close()
client.disconnect()
# Create empty (playlist) list
pl = []
for song in playlist:
s = {}
# Format time 00:00:00
s["time"] = str(datetime.timedelta(seconds=float(song["time"])))
if song.has_key("title") and not song["title"] is None:
s["title"] = song["title"]
else:
s["title"] = "Unknown"
if song.has_key("artist") and not song["artist"] is None:
s["artist"] = song["artist"]
else:
s["artist"] = "Unknown"
if song.has_key("album") and not song["album"] is None:
s["album"] = song["album"]
else:
s["album"] = "Unknown"
pl.append(s)
progress = 0
if current.has_key("time") and status.has_key("elapsed"):
time = int(current['time']);
elapsed = float(status['elapsed'])
progress = (elapsed/time)*100
return render_template("index.html", playlist=pl, current=current, status=status, progress=progress)
示例11: update_queue
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def update_queue():
client = MPDClient()
client.connect("localhost", 6600)
status = client.status()
if status['state'] == 'play':
current_song = client.currentsong()
current_song_position = current_song['pos']
if int(current_song_position) > 0:
client.delete('0:'+current_song_position)
try:
response = json.dumps(client.playlistinfo())
except:
response = False
client.close()
client.disconnect()
return response
示例12: init
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def init():
global CLIENT, PLAYLIST, LIBRARY
## MPD object instance
CLIENT = MPDClient()
if mpdConnect(CLIENT, CON_ID):
logging.info('Connected to MPD server')
CLIENT.setvol(95)
PLAYLIST = CLIENT.playlistinfo()
LIBRARY = CLIENT.listallinfo()
repeat(True) # Repeat all tracks
else:
logging.critical('Failed to connect to MPD server')
logging.critical("Sleeping 1 second and retrying")
time.sleep(1)
init()
示例13: dev
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def dev():
client = MPDClient()
client.connect("localhost", 6600)
# Get song(s) in the playlist
playlist = client.playlistinfo()
# Get current song
current = client.currentsong()
# Get status
status = client.status()
# Get stats
stats = client.stats()
client.close()
client.disconnect()
# Create empty (playlist) list
pl = []
for song in playlist:
s = {}
# Format time 00:00:00
s["time"] = str(datetime.timedelta(seconds=float(song["time"])))
if song.has_key("title") and not song["title"] is None:
s["title"] = song["title"]
else:
s["title"] = "Unknown"
if song.has_key("artist") and not song["artist"] is None:
s["artist"] = song["artist"]
else:
s["artist"] = "Unknown"
if song.has_key("album") and not song["album"] is None:
s["album"] = song["album"]
else:
s["album"] = "Unknown"
pl.append(s)
return render_template("dev.html", playlist=pl, current=current, status=status, stats=stats)
示例14: drawSongs
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def drawSongs(stdscr):
logging.debug("Drawing Songs" + "\n")
client = MPDClient() # create client object
client.timeout = 10 # network timeout in seconds (floats allowed), default: None
client.idletimeout = None # timeout for fetching the result of the idle command is handled seperately, default: None
client.connect("localhost", 6600) # connect to localhost:6600
client.consume(1)
if x=='blank':
blankLine=" "
# print("Max Height", maxHeight)
# print("Max Width", maxWidth)
#Clear Song lines
stdscr.move(maxHeight-2,0)
stdscr.clrtoeol()
stdscr.move(maxHeight-3,0)
stdscr.clrtoeol()
# stdscr.addstr(maxHeight-2,0,blankLine[:maxWidth-5])
# stdscr.addstr(maxHeight-3,0,blankLine[:maxWidth-5])
songList=[]
try:
currentPlaylist=client.playlistinfo()
for playlistSong in currentPlaylist:
songList.append(playlistSong['title'])
stdscr.addstr(maxHeight-2,5,"Up Next: " + str(songList))
except:
pass
try:
currentSong=client.currentsong()
stdscr.addstr(maxHeight-3,5,"Now Playing: " + str(currentSong['title']) + " (" + str(currentSong['artist']) + ")", curses.A_BOLD)
except:
stdscr.addstr(maxHeight-3,5,"Now Playing: ", curses.A_BOLD)
pass
client.close() # send the close command
client.disconnect()
stdscr.refresh()
示例15: current_track
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistinfo [as 别名]
def current_track(self, i3s_output_list, i3s_config):
try:
c = MPDClient()
c.connect(host=self.host, port=self.port)
if self.password:
c.password(self.password)
status = c.status()
song = int(status.get("song", 0))
next_song = int(status.get("nextsong", 0))
if (status["state"] == "pause" and self.hide_when_paused) or (status["state"] == "stop" and self.hide_when_stopped):
text = ""
else:
try:
song = c.playlistinfo()[song]
song["time"] = "{0:.2f}".format(int(song.get("time", 1)) / 60)
except IndexError:
song = {}
try:
next_song = c.playlistinfo()[next_song]
except IndexError:
next_song = {}
format_args = song
format_args["state"] = STATE_CHARACTERS.get(status.get("state", None))
for k, v in next_song.items():
format_args["next_{}".format(k)] = v
text = self.format
for k, v in format_args.items():
text = text.replace("{" + k + "}", v)
for sub in re.findall(r"{\S+?}", text):
text = text.replace(sub, "")
except SocketError:
text = "Failed to connect to mpd!"
except CommandError:
text = "Failed to authenticate to mpd!"
c.disconnect()
if len(text) > self.max_width:
text = text[-self.max_width-3:] + "..."
if self.text != text:
transformed = True
self.text = text
else:
transformed = False
response = {
'cached_until': time() + self.cache_timeout,
'full_text': self.text,
'transformed': transformed
}
if self.color:
response['color'] = self.color
return response