All pastes #1766034 Raw Edit

lolwut?

public python v1 · immutable
#1766034 ·published 2010-01-26 02:22 UTC
rendered paste body
#!/usr/bin/env python## Python MPD Information Library## Cheats using MPC"""  Ruby / Sapphire - Title Demo ~Departure From Houen District~  [playing] #344/452   0:22/0:35 (63%)  volume:100%   repeat: on    random: on"""from commands import getoutputimport sys, reclass Stopped(Exception):	def __init__(self): 		sys.stderr.write("MPD appears to be stopped\n")		exit(1)	class getMpdInfo(object):	def __init__(self, host="localhost", port=6600):		self.refresh()	def refresh(self):		self.mpcOutput = getoutput("mpc status").split("\n")	def line(self, ln):		try:			if (self.mpcOutput[1]):				return self.mpcOutput[ln]		except:			raise Stopped()	def song(self):		split = self.line(0).split(" - ")		if (len(split) == 2):			return {"title":split[1], "author":split[0]} 		else:			return {"song":self.line(0)}	def status(self):		regex = "\[(.+?)\] * #(\d+?)/(\d+?) * (\d.+)$"		parsed = re.match(regex, self.line(1))				return { "status": parsed.groups()[0],			"playnum": parsed.groups()[1],			"playmax": parsed.groups()[2],			"time":    parsed.groups()[3] }if __name__ == "__main__":	# Output common information, not used as library	info = getMpdInfo()	if (info.status()["status"] == "paused"):		part1 = "MPD is paused:"	else:		part1 = "Now playing with MPD:"			tmp = info.song()	try:		part2 = "%s by %s" % (tmp["title"], tmp["author"])	except:		part2 = tmp["song"]			tmp = re.match("(.+) \((\d+%)\)$", info.status()["time"])	part3 = "%s [%s]" % (tmp.groups()[0], tmp.groups()[1])			print "%s %s (%s)" % (part1, part2, part3)