All pastes #270009 Raw Edit

Untitled

public text v1 · immutable
·published 2006-12-07 00:03 UTC
rendered paste body
__module_name__	= "X-Chat MPD_Info Script"
__module_version__	= "0.1.0.1"
__module_description__	= "Prints Music Player Demon info"
__module_author__	=	"Michael Edwards <eddy@lug-norderstedt.de>"

# This is the MPD_Info Script, written by me ^^ ;)
# Features:
# You can Display the current song or the current radio  stream.
# The script detect, if it is a song or an stream, and toggle the output
# of mpd.
# Known commands:
# mpd         :displays current song/stream information in to the current channel
# mpd_stats   :displays the stats of the mpd server in the current channel
# mpd_play    :toggles between play and pause
# mpd_stop    :stops mpd from playing
# mpd_next    :plays next song, and jump to the beginning of the list if the end is reached
# mpd_local   :prints song information for you
import xchat
import commands

def	mpd_info_full(word, word_eol, userdata):

# Title full #
	volume = commands.getoutput("mpc volume | sed 's/://g' | sed 's/v/V/g' | sed 's/%/ %/g' | sed 's/e1/e 1/g' | cut -c -11")
	notitle = commands.getoutput("mpc | wc -l")
	timetot = commands.getoutput("mpc --format '[%time%]' | head -n1")
	timeof = commands.getoutput("mpc | grep playing | tr ' ' '\012' | grep :")
	url = commands.getoutput("mpc --format '%file%' | head -n1")
	stream = commands.getoutput("mpc --format '%file%' | grep http:// | wc -l")
	streamtitle = commands.getoutput("mpc --format  '[%title% (%name%)]' | head -n 1")
	bitrate = commands.getoutput("echo -e 'status\nclose' | nc localhost 6600 | grep bitrate | sed 's/bitrate: //;'")
	title = commands.getoutput("mpc --format  '[%artist% - %album% - %title%]' | head -n 1 | sed 's/ - $//;s/^ - //'")
	if notitle == "1": xchat.command("me is listening to -=(\002 defintiv nothing\002 )=-")
	else:
		if stream == "1":xchat.command("me is listening to -=(\002 %s - %s - %s\002 at %s\002 )=-" % (streamtitle, url, volume, bitrate))	
		else: 
			xchat.command("me    \00324*    \00319M\00320E\00319R\00320R\00319Y\00320 C\00319H\00320R\00319I\00320S\00319T\00320M\00319A\00320S\00319!!")
			xchat.command("me \00327   / \    \003oorza is listening to")
			xchat.command("me \00327  /   \   \003 %s"% (title))
			xchat.command("me \00327  /   \   \003 %s of %s"% (timeof, timetot))
			xchat.command("me \00327 /     \  \003 %s kbps"% (bitrate))
			xchat.command("me \00323   | |")

	return xchat.EAT_ALL

xchat.hook_command("mpd", mpd_info_full, help="Prints MPD info")

def mpd_local_info(word, word_eol, userdata):

# Title local #
	title = commands.getoutput("mpc | head -n 1")
	print("you are listening to %s" % title)
	return xchat.EAT_ALL
	
xchat.hook_command("mpd_local", mpd_local_info, help="Prints MPD info")

def mpd_stats(word, word_eol, userdata):

# Stats #

	title = commands.getoutput("mpc stats | sed '/^$/d; s/^/\002 ][ \002/'  |  tr -d '\n'| sed 's/$/\002 ]/g; s/ ]//'")
	xchat.command("me Music Player Demon Status: -={\002 %s }=-" % title)
	return xchat.EAT_ALL

xchat.hook_command("mpd_stats", mpd_stats, help="Prints MPD Stats")

def mpd_play(word, word_eol, userdata):

# MPD play/pause toggle; it's a hack, cause I didn't find a way to include "mpc toggle". ;) #
	playing = commands.getoutput("mpc | grep playing | wc -l")
	title = commands.getoutput("mpc | head -n 1")
	play = commands.getoutput("mpc play | head -n 1")
	if playing == "0": print("mpd starts playing: %s" % play)
	else: 
		commands.getoutput("mpc pause") 
		print("mpd is paused")
	return xchat.EAT_ALL
	
xchat.hook_command("mpd_play", mpd_play, help="Prints MPD info")

def mpd_stop(word, word_eol, userdata):

# Stops MPD playing #
	commands.getoutput("mpc stop")
	print("mpd stops playing")
	return xchat.EAT_ALL
	
xchat.hook_command("mpd_stop", mpd_stop, help="Prints MPD info")

def mpd_next(word, word_eol, userdata):

# Go to the next song #
	commands.getoutput("mpc next")
	notitle = commands.getoutput("mpc | wc -l")
	if notitle == "1": commands.getoutput("mpc play")
	print("mpd jumps to next song")
	return xchat.EAT_ALL
	
xchat.hook_command("mpd_next", mpd_next, help="Prints MPD info")



print	"X-Chat2 MPD_info Script [0.1.0.1] by Zappi Successfully loaded!"