本文整理汇总了Python中mpd.MPDClient.next方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.next方法的具体用法?Python MPDClient.next怎么用?Python MPDClient.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
def main():
print "Content-Type: application/json\n"
client = MPDClient()
if not mpdConnect(client, CON_ID):
print '{ "status": "failure", "message": "failed to connect to MPD server. '+HOST+':'+PORT+'"}'
sys.exit(-1)
if PASSWORD != '':
if not mpdAuth(client, PASSWORD):
print '{ "status": "failure", "message": "failed to auth against MPD server."}'
sys.exit(-1)
command = os.environ['SCRIPT_NAME'].replace('/mpd/control/', '')
try:
if command == 'pause/':
client.pause()
print '{ "status": "success" }'
elif command == 'play/':
client.play()
print '{ "status": "success" }'
elif command == 'next/':
client.next()
print '{ "status": "success" }'
elif command == 'previous/':
client.previous()
print '{ "status": "success" }'
except CommandError:
print '{ "status": "failure", "message": "unknown command" }'
示例2: Jukebox
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
class Jukebox():
def __init__(self):
self.dt = DisplayThread(self)
self.dt.start()
## MPD object instance
self.client = MPDClient()
if mpdConnect(self.client, CON_ID):
print 'Got connected!'
else:
print 'fail to connect MPD server.'
sys.exit(1)
try:
f = open('/media/usb/playlist.txt','r')
playlist = f.readline().rstrip()
print "Loading " + playlist
self.client.clear()
self.client.load(playlist)
except IOError:
print "Problem reading playlist"
self.client.stop()
self.client.play()
carryOn = True
while (carryOn):
if (humble.switch(0)):
time.sleep(PAUSE)
self.toggle()
if (humble.switch(1)):
time.sleep(PAUSE)
self.skip()
if (humble.switch(2)):
time.sleep(PAUSE)
self.stop()
carryOn = False
time.sleep(PAUSE)
# Stop the display thread
self.dt.done()
def skip(self):
print "Skipping"
self.client.next()
def stop(self):
print "Stopping"
self.client.stop()
humble.data.setLine(0,"")
humble.data.setLine(1,"")
humble.data.setLed('red', False)
humble.data.setLed('green', False)
time.sleep(0.5)
def toggle(self):
status = self.client.status()
if status['state'] == 'pause' or status['state'] == 'stop':
self.client.play()
else:
self.client.pause()
示例3: Play
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
class Play():
def __init__(self):
self.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
def connect(self):
try:
self.client.connect(mpd_host, mpd_port)
print("MPD Version: " + self.client.mpd_version) # print the MPD version
except OSError:
print("Error connecting to MPD")
except mpd.ConnectionError:
# Already connected?
pass
def current_track_info(self):
self.connect()
try:
return self.client.currentsong()
except mpd.ConnectionError:
print("[ERROR] current_track_info(): mpd.ConnectionError")
return None
except mpd.CommandError:
print("[ERROR] play_album(): mpd.CommandError")
return None
def next_track(self):
self.connect()
try:
self.client.next()
except mpd.ConnectionError:
print("[ERROR] next_track(): mpd.ConnectionError")
except mpd.CommandError:
print("[ERROR] play_album(): mpd.CommandError")
def pause(self):
self.connect()
try:
self.client.pause()
except mpd.ConnectionError:
print("[ERROR] pause(): mpd.ConnectionError")
except mpd.CommandError:
print("[ERROR] play_album(): mpd.CommandError")
def play_album(self, album_path):
self.connect()
# mpc -h 192.168.1.80 -p 6600 listall Yeah_Yeah_Yeahs/
# Maybe you need album_path[1:]?
print("Requesting mpd play album: {}".format(album_path[1:]))
try:
self.client.clear()
self.client.add(album_path) # [1:] to strip leading /
self.client.play()
except mpd.ConnectionError:
print("[ERROR] play_album(): mpd.ConnectionError")
except mpd.CommandError:
print("[ERROR] play_album(): mpd.CommandError")
示例4: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [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_stats(self):
#{'playtime': '848', 'uptime': '2565'}
#{'songid': '33', 'playlistlength': '1', 'playlist': '86', 'repeat': '0',
#'consume': '0', 'mixrampdb': '0.000000', 'random': '0', 'state': 'play',
# 'elapsed': '7.476', 'volume': '-1', 'single': '0', 'time': '7:0', 'song': '0', 'audio': '44100:16:2', 'bitrate': '128'}
all = {}
all.update(self.client.stats())
all.update(self.client.status())
stats = {}
stats["elapsed"] = all["elapsed"] if all.has_key("elapsed") else "0"
stats["state"] = all["state"] if all.has_key("state") else "stopped"
stats["playtime"] = all["playtime"]
stats["uptime"] = all["uptime"]
stats["bitrate"] = all["bitrate"] if all.has_key('bitrate') else 0
stats["playlistlength"] = all["playlistlength"] if all.has_key("playlistlength") else 0
stats["song"] = all["song"] if all.has_key("song") else 0
# print stats
return stats
def get_playing(self):
name = "unknown"
val = self.client.currentsong()
name= val["name"] if val.has_key('name') else None
name= val["title"] if val.has_key('title') else name
# print val
return name
def load(self, list):
# print "loading list", list
self.client.clear()
self.client.load(list)
def next(self):
self.client.next()
def prev(self):
self.client.previous()
def play(self):
self.client.play()
def stop(self):
self.client.stop()
示例5: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
class MPDCli:
def __init__(self, ipaddress):
self.client = MPDClient()
self.client.timeout = 10
self.client.idletimeout = None
self.client.connect(ipaddress, 6600)
self.client.consume(0)
self.ip = ipaddress
def close(self):
self.client.close()
self.client.disconnect()
def __tryConnect(self):
try:
self.client.update()
except ConnectionError:
self.client.connect(self.ip, 6600)
self.client.update()
def getNowPlaying(self):
self.__tryConnect()
return self.client.currentsong()
def getCurrentStatus(self):
self.__tryConnect()
return self.client.status()
def play(self):
self.__tryConnect()
currentState = self.client.status()['state']
if currentState == 'stop':
self.client.play(int(self.client.status()['song']))
else:
self.client.pause()
return self.client.status()
def stop(self):
self.__tryConnect()
self.client.stop()
return self.client.status()
def prev(self):
self.__tryConnect()
self.client.previous()
return self.client.status()
def next(self):
self.__tryConnect()
self.client.next()
return self.client.status()
def idle(self):
self.__tryConnect()
self.client.idle()
示例6: mpd
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
def mpd(bot, trigger):
"""Used to control the mpd music player at the space"""
rulenum = trigger.group(2)
## MPD object instance
client = MPDClient()
try:
client.connect(host=HOST, port=PORT)
except SocketError:
bot.say('socketerror')
exit(1)
# Auth if password is set non False
if PASSWORD:
try:
client.password(PASSWORD)
except CommandError:
client.disconnect()
sys.exit(2)
mpdcommand = str(rulenum)
if ((mpdcommand == 'playing') or (mpdcommand == 'state')) :
currentsong = client.currentsong()
currentstatus = client.status()
if currentstatus['state'] == 'play':
saySong(bot,currentsong)
elif currentstatus['state'] == 'pause':
bot.say('Music is currently paused (' + songNow(currentsong) + ')')
elif currentstatus['state'] == 'stop':
bot.say('No music is playing')
elif mpdcommand == 'play':
bot.say('Pressing play on mpd...')
client.play()
currentsong = client.currentsong()
saySong(bot,currentsong)
elif mpdcommand == 'pause':
bot.say('Pausing mpd...')
client.pause()
elif mpdcommand == 'stop':
bot.say('Stopping mpd...')
client.stop()
elif mpdcommand == 'next':
bot.say('Moving to next song on mpd...')
client.next()
currentsong = client.currentsong()
saySong(bot,currentsong)
else:
bot.say('invalid mpd command')
示例7: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [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: next
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
def next():
client = MPDClient()
client.connect("localhost", 6600)
# Next track
client.next()
client.close()
client.disconnect()
return jsonify(ok=True)
示例9: MyMPDClient
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
class MyMPDClient():
def __init__(self):
## MPD object instance
self.client = MPDClient()
if mpdConnect(self.client, CON_ID):
print 'Got connected!'
else:
print 'fail to connect MPD server.'
sys.exit(1)
# Auth if password is set non False
if PASSWORD:
if mpdAuth(client, PASSWORD):
print 'Pass auth!'
else:
print 'Error trying to pass auth.'
self.client.disconnect()
sys.exit(2)
def getCurrentsong(self):
return self.client.currentsong()
def pause(self):
return self.client.pause()
def previous(self):
return self.client.previous()
def _next(self):
return self.client.next()
def stop(self):
return self.client.stop()
def play(self):
return self.client.play()
def getStatus(self):
return self.client.status()
def add(self, item):
self.client.add(item)
def playlist(self):
return self.client.playlist()
def getPlaylistid(self):
return self.client.playlistid()
def playId(self,_id):
self.client.playid(_id)
def getItemIdInPLaylist(self, item):
playlist = self.getPlaylistid()
for pos in playlist:
if pos['file'] == item:
return pos['id']
return '-1'
示例10: MPDSwitch
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
class MPDSwitch(SwitchClass):
class_metadata = {"type":"music"}
metadata = {}
client = None
state = {}
broadcast_status = False
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.getMPDClient()
self.poll()
def getMPDClient(self):
if self.client == None:
self.client = MPDClient()
self.client.connect("localhost", 6600)
else:
try:
self.client.ping()
except ConnectionError as e:
self.client = None
self.getMPDClient()
def poll(self):
""" This function calls itself every second to check for config changes """
self.getMPDClient()
state = self.getState(status=self.broadcast_status)
if self.state != state:
self.state = state
state = self.getState()
metadata = self.getMetaData()
res = {"result":"state", "switch":self.name, "state":state, "metadata":metadata}
self.factory.broadcast(res)
self.factory.loop.call_later(1, self.poll)
def close(self):
self.client.close()
self.client.disconnect()
def getCurrentSong(self):
song = self.parseSong(self.client.currentsong())
return song
def parseSong(self, song):
if "artist" in song and "album" in song and "title" in song:
song_str = "{artist} - {album}: {title}".format(**song)
elif "title" in song:
song_str = "{title}".format(**song)
elif "file" in song:
song_str = "{file}".format(**song).rpartition("/")[-1]
else:
song_str = "No song selected"
return song_str
def getState(self, song=True, playlist=True, status=True):
self.getMPDClient()
state = {}
if song: state["song"] = self.getCurrentSong()
if playlist: state["playlist"] = self.getPlaylist()
if status: state["status"] = self.getStatus()
return state
def getPlaylist(self):
self.getMPDClient()
playlist = self.client.playlistid()
parsed_playlist = [self.parseSong(song) for song in playlist]
return parsed_playlist
def getStatus(self):
self.getMPDClient()
status = self.client.status()
return status
@publicMethod
def get_playlist(self):
return self.getPlaylist()
@publicMethod
def next(self):
self.getMPDClient()
self.client.next()
return True
@publicMethod
def stop(self):
self.getMPDClient()
self.client.stop()
return True
@publicMethod
def previous(self):
self.getMPDClient()
self.client.previous()
return True
@publicMethod
def pause(self):
self.getMPDClient()
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
#.........这里部分代码省略.........
###### API CALLS #######
def api_pause(self):
"""
Pauses the current song
Does nothing if no song is playing
"""
self.__api.pause()
def api_play(self):
"""
Plays the current song
If the current song is paused it resumes the song
If no songs are in the queue, it does nothing
"""
if self.__state() == 'pause':
self.__api.play()
else:
self.auto_play()
def api_play_pause(self):
"""
Toggles between paused and playing
Scenarios of current song
Not Playing: Plays the song
Paused: Resumes playback
Playing: Pauses song
If no songs are in the queue, it does nothing
"""
if self.__state() == 'play':
self.api_pause()
elif self.__state() == 'pause' or not len(self.queue) == 0:
self.api_play()
def api_next(self):
"""
Plays the next song in the queue
If no songs are left it does nothing
"""
self.__api.next()
def api_stop(self):
"""
Stops playback
If no songs are in the queue, it does nothing
"""
self.__api.stop()
def api_previous(self):
"""
Plays the previous song in the queue.
"""
self.__api.previous()
def api_shuffle(self):
"""
Shuffles entire playlist. Probably should not be used.
"""
self.__api.shuffle()
def api_clear_queue(self):
"""
Clears the queue of all the songs.
If the queue is already cleared, this will do nothing.
"""
self.__api.clear()
示例12: Mpd
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
#.........这里部分代码省略.........
try:
self.client.disconnect()
except Exception:
self.log.exception('Error disconnecting mpd')
return False
self.connected = False
return True
def mpdAuth(self, secret):
"""
Authenticate
"""
try:
self.client.password(secret)
except CommandError:
return False
return True
def _configure(self, qtile, bar):
base._Widget._configure(self, qtile, bar)
self.layout = self.drawer.textlayout(
self.text, self.foreground, self.font, self.fontsize,
markup=True)
self.timeout_add(1, self.update)
atexit.register(self.mpdDisconnect)
def update(self):
if self.connect(True):
try:
status = self.client.status()
song = self.client.currentsong()
volume = status.get('volume', '-1')
if song:
artist = ''
title = ''
if 'artist' in song:
artist = song['artist'].decode('utf-8')
if 'title' in song:
title = song['title'].decode('utf-8')
if 'artist' not in song and 'title' not in song:
playing = song.get('file', '??')
else:
playing = u'%s − %s' % (artist, title)
if status and status.get('time', None):
elapsed, total = status['time'].split(':')
percent = float(elapsed) / float(total)
progress = int(percent * len(playing))
playing = '<span color="%s">%s</span>%s' % (
utils.hex(self.foreground_progress),
utils.escape(playing[:progress].encode('utf-8')),
utils.escape(playing[progress:].encode('utf-8')))
else:
playing = utils.escape(playing)
else:
playing = 'Stopped'
playing = '%s [%s%%]' % (playing,
volume if volume != '-1' else '?')
except Exception:
self.log.exception('Mpd error on update')
playing = self.msg_nc
self.mpdDisconnect()
else:
if self.reconnect:
playing = self.msg_nc
else:
return False
if self.text != playing:
self.text = playing
self.bar.draw()
return True
def click(self, x, y, button):
if not self.connect(True):
return False
try:
status = self.client.status()
if button == 3:
if not status:
self.client.play()
else:
self.client.pause()
elif button == 4:
self.client.previous()
elif button == 5:
self.client.next()
elif button == 8:
if status:
self.client.setvol(
max(int(status['volume']) - self.inc, 0))
elif button == 9:
if status:
self.client.setvol(
min(int(status['volume']) + self.inc, 100))
except Exception:
self.log.exception('Mpd error on click')
示例13: myMPD
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
#.........这里部分代码省略.........
# "password commmand failed: %s" %
# (self._host, e))
#db.write_log_to_db_a(ac, "MPD-PW-Error: %s" % str(e), "x",
# "write_also_to_console")
return None
# Catch all other possible errors
except (MPDError, IOError) as e:
#raise RunError("Could not connect to '%s': "
# "error with password command: %s" %
# (self._host, e))
db.write_log_to_db_a(ac, "MPD-Error-2: %s" % str(e), "x",
"write_also_to_console")
return None
def disconnect(self):
# Try to tell MPD we're closing the connection first
try:
self._client.close()
# If that fails, don't worry, just ignore it and disconnect
except (MPDError, IOError):
pass
try:
self._client.disconnect()
# Disconnecting failed, so use a new client object instead
# This should never happen. If it does, something is seriously broken,
# and the client object shouldn't be trusted to be re-used.
except (MPDError, IOError):
self._client = MPDClient()
def exec_command(self, db, ac, command, value):
"""spread out exec commands"""
result = None
try:
if command == "access":
result = self.mpd_access(db, ac)
if command == "play":
result = self._client.play()
if command == "update":
result = self._client.update()
if command == "song":
result = self._client.currentsong()
if command == "status":
result = self._client.status()
if command == "add":
result = self._client.add(value)
if command == "consume":
result = self._client.consume(value)
if command == "crossfade":
result = self._client.crossfade(value)
if command == "seek":
result = self._client.seek(value)
if command == "repeat":
result = self._client.repeat(value)
if command == "random":
result = self._client.random(value)
if command == "single":
result = self._client.single(value)
if command == "replay_gain_mode":
result = self._client.replay_gain_mode(value)
if command == "next":
result = self._client.next()
if command == "setvol":
result = self._client.setvol(value)
# via mpc-client
if command == "crop":
result = mpc_client(db, ac, "crop", value)
if command == "vol":
result = mpc_client(db, ac, "volume", value)
# via os
if command == "reload-1":
result = run_cmd(db, ac, "killall", value)
if command == "reload-2":
result = run_cmd(db, ac, "mpd", value)
return result
# Couldn't get the current cmd, so try reconnecting and retrying
except (MPDError, IOError) as e:
# No error handling required here
# Our disconnect function catches all exceptions, and therefore
# should never raise any.
error_msg = "MPD-Error-3: %s" % str(e)
if value is not None:
error_msg = error_msg + ", cmd: " + value
#db.write_log_to_db_a(ac, "MPD-E-3 cmd-value: " + value, "x",
# "write_also_to_console")
if str(e) == "Not connected":
error_msg = error_msg + ", try recon.:"
db.write_log_to_db_a(ac, error_msg, "x",
"write_also_to_console")
self.connect(db, ac)
self.exec_command(db, ac, command, value)
else:
db.write_log_to_db_a(ac, error_msg, "x",
"write_also_to_console")
return None
示例14: Mpc
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
#.........这里部分代码省略.........
logger.error('Lost connection on get volume')
def get_status(self):
logger.debug("get_status")
try:
clientStatus = self.client.status()
return clientStatus
except mpd.ConnectionError:
logger.error('Lost connection on get status')
def refresh_play_status(self):
logger.debug("refresh_playing_status")
try:
status = self.get_status()
if 'state' in status:
self.play_status = status['state']
Observable.notify_toggle_observers(self, {'status': self.play_status})
except mpd.ConnectionError:
logger.error('Lost connection on get get_playing_status')
def refresh_time(self):
logger.debug("refresh_time")
try:
status = self.get_status()
if 'elapsed' in status:
self.song_time_elapsed = float(status['elapsed'])
else:
self.song_time_elapsed = 0.0
if 'time' in self.current_song:
self.song_time_total = float(self.current_song['time'])
else:
self.song_time_total = 0.0
if status['state'] == 'play':
self.thread_play()
else:
self.thread_pause()
except mpd.ConnectionError:
logger.error('Lost connection on get get_playing_status')
def refresh_current_song(self):
self.current_song = self.client.currentsong()
logger.debug('Current song: %s', self.current_song)
Observable.notify_song_observers(self, {'song': self.current_song})
def toggle(self):
logger.debug("toggle")
if self.play_status == 'stop':
self.client.play(0)
if self.play_status == 'play':
self.client.pause(1)
if self.play_status == 'pause':
self.client.pause(0)
def stop(self):
logger.debug("stop")
try:
self.client.stop()
except mpd.ConnectionError:
logger.error('Lost connection on stop')
def song_previous(self):
logger.debug("song_previous")
try:
self.client.previous()
except mpd.ConnectionError:
logger.error('Lost connection on previous')
def song_next(self):
logger.debug("song_next")
try:
self.client.next()
except mpd.ConnectionError:
logger.error('Lost connection on next')
def volume_down(self):
logger.debug("volume_down")
volume_to_set = self.volume - 10
if volume_to_set < 0:
volume_to_set = 0
self.client.setvol(volume_to_set)
def volume_up(self):
logger.debug("volume_up")
volume_to_set = self.volume + 10
if volume_to_set > 100:
volume_to_set = 100
self.client.setvol(volume_to_set)
def volume_mute(self):
logger.debug("volume_mute")
try:
self.client.setvol(0)
except mpd.ConnectionError:
logger.error('Lost connection on mute')
示例15: Mpd
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import next [as 别名]
#.........这里部分代码省略.........
def get_volume(self):
return self.status['volume']
def get_single(self):
if self.status['single'] == '1':
return '1'
else:
return '_'
def get_repeat(self):
if self.status['repeat'] == '1':
return 'R'
else:
return '_'
def get_shuffle(self):
if self.status['random'] == '1':
return 'S'
else:
return '_'
formats = {'a': get_artist, 'A': get_album, 'e': get_elapsed,
'f': get_file, 'l': get_length, 'n': get_number,
'p': get_playlistlength, 's': get_status, 'S': get_longstatus,
't': get_title, 'T': get_track, 'v': get_volume, '1': get_single,
'r': get_repeat, 'h': get_shuffle, '%': lambda x: '%', }
def match_check(self, m):
try:
return self.formats[m.group(1)](self)
except KeyError:
return "(nil)"
def do_format(self, string):
return re.sub("%(.)", self.match_check, string)
def update(self):
if not self.configured:
return True
if self.connect(True):
try:
self.status = self.client.status()
self.song = self.client.currentsong()
if self.status['state'] != 'stop':
playing = self.do_format(self.fmt_playing)
if self.do_color_progress and self.status and self.status.get('time', None):
elapsed, total = self.status['time'].split(':')
percent = float(elapsed) / float(total)
progress = int(percent * len(playing))
playing = '<span color="%s">%s</span>%s' % (
utils.hex(self.foreground_progress),
utils.escape(playing[:progress]),
utils.escape(playing[progress:]))
else:
playing = utils.escape(playing)
else:
playing = self.do_format(self.fmt_stopped)
except Exception:
self.log.exception('Mpd error on update')
playing = self.msg_nc
self.mpdDisconnect()
else:
if self.reconnect:
playing = self.msg_nc
else:
return False
if self.text != playing:
self.text = playing
self.bar.draw()
return True
def button_press(self, x, y, button):
if not self.connect(True):
return False
try:
status = self.client.status()
if button == 3:
if not status:
self.client.play()
else:
self.client.pause()
elif button == 4:
self.client.previous()
elif button == 5:
self.client.next()
elif button == 8:
if status:
self.client.setvol(
max(int(status['volume']) - self.inc, 0))
elif button == 9:
if status:
self.client.setvol(
min(int(status['volume']) + self.inc, 100))
except Exception:
self.log.exception('Mpd error on click')