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


Python MPDClient.stats方法代码示例

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


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

示例1: main

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stats [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)

    # Auth if password is set non False
    if PASSWORD:
        if mpdAuth(client, PASSWORD):
            print('Pass auth!')
        else:
            print('Error trying to pass auth.')
            client.disconnect()
            sys.exit(2)

    ## Fancy output
    pp = pprint.PrettyPrinter(indent=4)

    ## Print out MPD stats & disconnect
    print('\nCurrent MPD state:')
    pp.pprint(client.status())

    print('\nMusic Library stats:')
    pp.pprint(client.stats())

    client.disconnect()
    sys.exit(0)
开发者ID:HikaruLim,项目名称:python-mpd2,代码行数:32,代码来源:stats.py

示例2: __init__

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

示例3: main

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stats [as 别名]
def main():
    client = MPDClient()

    while True:
        if not mpdConnect(client, CON_ID):
            sys.stderr.write('fail to connect MPD server.')
            sys.exit(1)

        results = dict(client.status().items() + client.stats().items())

        for key, value in results.items():
            if not send_value(key, value):
                sys.stderr.write('failed to send value to graphite.')
                sys.exit(1)

        client.disconnect()
        time.sleep(1)
开发者ID:pixelistik,项目名称:mpd-stats-to-graphite,代码行数:19,代码来源:mpd-stats-to-graphite.py

示例4: dev

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stats [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)
开发者ID:rawswift,项目名称:fmwc,代码行数:48,代码来源:app.py

示例5: Player

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

    def __init__(self,):
        self.setPort('6600')
        self.setHost('localhost')
        self.client = MPDClient()

    def setPort(self, _port):
        self.port = _port

    def setHost(self, _host):
        self.host = _host

    def connectMPD(self):
        try:
            con_id = {'host': self.host, 'port': self.port}
            self.client.connect(**con_id)
        except SocketError:
            print "mpd connection error"
            print traceback.print_exc()
            return False

        print self.client.status()
        return True

    def disconnect(self):
        try:
            self.client.disconnect()
        except SocketError:
            print "mpd connection error"
            print traceback.print_exc()

    def getState(self):
        try:
            return self.client.status()["state"]
        except SocketError:
            print "mpd connection error"
            print traceback.print_exc()

    def getStats(self):
        try:
            return self.client.stats()
        except SocketError:
            print "mpd connection error"
            print traceback.print_exc()

    def playPause(self):
        state = self.client.status()["state"]
        if state == "stop" or state == "pause":
            print "play"
            self.client.play()
        else:
            print "pause"
            self.client.pause()

    def increaseVolume(self, delta):
        volume = int(self.client.status()["volume"])
        volume += delta
        print "settings volume to " + str(volume)
        self.client.setvol(str(volume))

    def decreaseVolume(self, delta):
        volume = int(self.client.status()["volume"])
        volume -= delta
        print "settings volume to " + str(volume)
        self.client.setvol(str(volume))

    def nextSong(self):
        print "next song"
        self.client.next()

    def prevSong(self):
        print "prev song"
        self.client.previous()

    def seekCur(self, time):
        print "seek"
        self.client.seekcur(time)
开发者ID:MrZoidberg,项目名称:RPi-OBABP,代码行数:80,代码来源:player.py

示例6: MPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stats [as 别名]
client = MPDClient()               # create client object
# network timeout in seconds (floats allowed), default: None
client.timeout = 10
# timeout for fetching the result of the idle command is handled
# seperately, default: None
client.idletimeout = None
client.connect("localhost", 6600)  # connect to localhost:6600
print(client.mpd_version)          # print the MPD version
# print result of the command "find any house"
print(client.find("any", "house"))
# command list的机制现在还不理解,在把python-mpd2的动态方法改成静态方法的过程中,command list暂且还不能好好处理
# client.command_list_ok_begin()       # start a command list
client.update()                      # insert the update command into the list
client.status()                      # insert the status command into the list
print(client.status())
print(client.stats())
# results = client.command_list_end()  # results will be a list with the results
# print((results))
client.iterate = True
for song in client.playlistinfo():
    #print( song["file"])
    pass
client.iterate = False
client.send_idle()
events = client.fetch_idle()
print(events)
print(client.status())
client.close()                     # send the close command
client.disconnect()                # disconnect from the server
# client.delete((1,))     # delete all songs, but the first.
开发者ID:rbn42,项目名称:mpd-script,代码行数:32,代码来源:start.py

示例7: len

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stats [as 别名]
client.timeout = 10
client.idletimeout = None
client.connect("localhost", 6600)

currentsong = client.currentsong()

print ""
if len(currentsong) > 0:
	for text in currentsong:
		print text + ": " + str(currentsong.get(text))

	current_id = int(currentsong.get("pos")) + 1
	print "current_id", current_id
else:
	print "No current song"

print ""
print "Status"
status = client.status()
for text in status:
	print text + ": " + str(status.get(text))

print ""
stats = client.stats()
for text in stats:
	print text + ": " + str(stats.get(text))

# End of program


开发者ID:durone,项目名称:piradio,代码行数:30,代码来源:display_current.py

示例8: __init__

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

#.........这里部分代码省略.........

		# TODO - use python plugin (on remote server?)
		if test_all:
			subprocess.call('espeak '+'"'+song+'" -s 150 -v '+ v1 + '>/dev/null 2>&1',shell=True)
		if self.speak_option == "artist" or self.speak_option == "all" or test_all:
			subprocess.call('espeak '+'"'+art+'" -s 130 -v '+ v1 + '>/dev/null 2>&1',shell=True)
		if self.speak_option == "all" or test_all:
			subprocess.call('espeak '+'"'+alb+'" -s 150 -v '+ v2 + '>/dev/null 2>&1',shell=True)


	def speak(self,this_text):
		print "+ "+this_text
		#text = self.font2.render(this_text,True,self.colour['white'],self.colour['black']) #a surf
		#self.surf.blit(text,(10,150))
		#pyg.display.update()
		if self.speak_option!="none":
			devnull = open(os.devnull, 'white')
			subprocess.call('espeak "'+this_text+'" -s 150 -v en+f2',shell=True, stdout=devnull, stderr=devnull)
	

	def set_volume(self,delta_vol):
		status = self.c.status()
		if status.get('state')!="stop":
			volume = int(status.get("volume"))
			if volume!=-1:
				volume+=delta_vol
				if volume>100:
					volume = 100
				elif volume<0:
					volume=0
				self.c.setvol(volume)
		
		
	def output_stats(self):
		#print(self.genre,self.last_genre,self.mode,self.last_mode,self.speak_option)
		print "+ Status:"
		pp = pprint.PrettyPrinter(indent=3)
		#pp.pprint(self)
		#pp.pprint(self.sort_albums)
		pp.pprint(self.c.stats())
		pp.pprint(self.c.status())
		pp.pprint(self.c.currentsong())
		

	def set_graphics_mode(self):
		if self.graphics == "simple":
			self.graphics = "full"
		else:
			self.graphics = "simple"
			
			
	def open_picard(self):
		# Edit metadata for this album (in Picard)
		temp = self.c.currentsong()
		uri=temp.get("file","")
		temp = uri.split("/")
		uri=""
		for n in range(0,len(temp)-2):
			uri = uri+temp[n]+"/"
		# Special case for various - select album as well
		if temp[n]=="Various":
			uri = uri+temp[n+1]
		arg = "picard "+'"'+self.folder+uri+'"'
		print "+ Opening Picard ("+arg+")"
		subprocess.call(arg,shell=True)
		
开发者ID:Bisxuit,项目名称:dukebox,代码行数:69,代码来源:dukebox_player.py

示例9: MPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stats [as 别名]
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(LEDPIN, GPIO.OUT)

# init mpc
client = MPDClient()
client.timeout = 2
client.idletimeout = None
client.connect('localhost', 6600)

# check led
led_state = GPIO.input(LEDPIN)

# get mpd stats
stats = client.status()
stat = client.stats()
client.close()
client.disconnect()

#print "LED = %s" % led_state
#print "MPD_status = %s" % stats
#print "MPD_stats  = %s" % stat
#print "uptime = %s" % get_uptime()
#print "timestamp = %s" % dt.utcnow().isoformat()
 
msg = {"led":(led_state == 0),
       "mpd":{ 
         "status":stats,
         "stat":stat
       },
       "uptime":get_uptime(),
开发者ID:artxfm,项目名称:box,代码行数:33,代码来源:checkin.py

示例10: stderr_print

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import stats [as 别名]
if sys.argv[4].find("NEXT") != -1:
    client.next()

if sys.argv[4].find("PREV") != -1:
    client.previous()

if sys.argv[4].find("PLAY") != -1:
    client.play()
    stderr_print("Playing music!")

if sys.argv[4].find("PAUSE") != -1:
    client.pause()
    stderr_print("Paused music!")

if sys.argv[4].find("STATS") != -1:
    results = client.stats()

    uptime = results['uptime']
    artists = results['artists']
    albums = results['albums']
    songs = results['songs']

    playtime = int(results['db_playtime'])
    remainder = playtime % 86400

    days = (playtime - remainder) / 86400

    playtime = remainder
    remainder = playtime % 3600

    hours = (playtime - remainder) / 3600
开发者ID:nathan-hoad,项目名称:makeme,代码行数:33,代码来源:mpd-remote.py

示例11: __init__

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

#.........这里部分代码省略.........
				self.data['title'] = self.toUpper(title)
				
		# If player is playing or it's paused, get elapsed time, total track time and bitrate
		if (self.data['state'] == 1 or self.data['state'] == 2):
			# If file is playing, get total track time
			if (self.data['type'] == 0):
				try:
					self.data['total_time'] = int(self.client.currentsong()['time'])
				except KeyError:
					self.data['total_time'] = 0
					
			# Else, if radio is playing, there's no total track time
			else:
				self.data['total_time'] = 0
			
			# Get elapsed time and convert it to seconds (int)
			try:
				self.data['elapsed_time'] = int(math.floor(float(self.client.status()['elapsed'])))
			except KeyError:
				self.data['elapsed_time'] = 0
				
			# Get track/station bitrate
			try:
				self.data['bitrate'] = int(self.client.status()['bitrate'])
			except KeyError:
				self.data['bitrate'] = 0
		
		# Else, put elapsed time to zero
		else:
			self.data['elapsed_time'] = 0		
		
		# Get total playtime and uptime from last reboot
		try:
			self.data['uptime'] = int(self.client.stats()['uptime'])
		except KeyError:
			self.data['uptime'] = 0
			
		try:
			self.data['playtime'] = int(self.client.stats()['playtime'])
		except KeyError:
			self.data['playtime'] = 0
		
		# Get shuffle state
		try:
			temp = self.client.status()['random']
			if (temp == '0'):
				temp = False
			elif (temp == '1'):
				temp = True
			
			# Check if shuffle has changed
			if (temp != self.data['shuffle']):
				changed = 0 # Shuffle has changed
				self.data['shuffle'] = temp # Update data
		except KeyError:
			pass
			
		# Get repeat all state
		try:
			temp = self.client.status()['repeat']
			if (temp == '0'):
				temp = False
			elif (temp == '1'):
				temp = True
			
			# Check if repeat all has changed
开发者ID:DustyMustard,项目名称:RuneAudioLCD,代码行数:70,代码来源:mpd_client.py


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