__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 youimport xchatimport commandsdef mpd_info_full(word, word_eol, userdata):# Title full # volume = commands.getoutput("mpc volume | sed 's/volume://g' | sed 's/ //g' | sed 's/%/ %/'") 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") title = commands.getoutput("mpc --format '[%artist% - %title%]' | head -n 1 | sed 's/ - $//;s/^ - //'") album = commands.getoutput("mpc --format '[%album%]' | head -n 1 | sed 's/ - $//;s/^ - //'") artist = commands.getoutput("mpc --format '[%artist%]' | head -n 1 | sed 's/ - $//;s/^ - //'") song = commands.getoutput("mpc --format '[%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 )=-" % (streamtitle, url, volume)) else: title = xchat.command("me is listening to\002 %s\002 by \002%s\002 from \002%s" % (song, artist, album)) return xchat.EAT_ALLxchat.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_ALLxchat.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_ALLxchat.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_ALLxchat.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_ALLxchat.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_ALLxchat.hook_command("mpd_next", mpd_next, help="Prints MPD info")print "X-Chat2 MPD_info Script [0.1.0.1] by Zappi Successfully loaded!"