#!/usr/bin/pythonimport sys,urllib,os,reresults=[]def mpd_settings(): results=[] print "Beginning setup of xchat_mpd-0.1..." print print "Answer the following questions to install xchat_mpd" print host=raw_input('Please specify the host on which MPD runs: ') port=raw_input('Please specify the port on which MPD runs: ') print print "For xchat_mpd to run, the python mpdclient" print "module must be installed, available at" print "http://www.musicpd.org/py-libmpdclient.shtml" print results=[host,port] return resultsdef module_needsinstall(): install_module=raw_input('Should I install the module for you? [y/n] ') if install_module == 'y': print result='y' return result elif install_module == 'n': print result='n' return result elif install_module == 'yes': print result='y' return result elif install_module == 'no': print result='n' return result else: print "Error: please enter either [y]es or [n]o." exitdef install_module(): print print '---' print 'Attempting automatic installation of required python module.' print 'Please note, this portion of the program is highly experimental;' print 'In the event that the installation fails, download the module' print 'from the given link and perform a manual installation.' print '---' print f = urllib.urlopen("http://mercury.chem.pitt.edu/~shank/py-libmpdclient-0.10.0.tar.gz").read() tarball = open("py-libmpdclient-0.10.0.tar.gz", "wb") tarball.write(f) tarball.close() os.popen('tar zxpf py-libmpdclient-0.10.0.tar.gz') os.chdir('py-libmpdclient-0.10.0/') os.popen('python setup.py install > ../mod_install.log') os.chdir('../') os.remove('py-libmpdclient-0.10.0.tar.gz') os.popen('rm -fr py-libmpdclient-0.10.0')def install_script(host,port): script = """import xchat,mpdclient# Jon Temple [toran] <jtemple@coin.org># 04.05.2005# Released under the GPL## prints the song currently being played by # MPD (http://musicpd.org). In the future it# will hopefully be able to control MPD.__module_name__ = "mpd"__module_version__ = "0.1"__module_description__ = "Gives xchat access to various functions related to the MPD music player."#shows if the script got loaded print "xchat_mpd-0.1 loaded."def mpd_announce(word, word_eol, userdata): try: #see if mpd is running c = mpdclient.MpdController(host='localhost',port=6600) except Traceback: print 'MPD does not appear to be running. Make sure MPD is running on port 6600, and then try again.' if len(word) > 1: #check to see if it got run w/ variable print 'Sorry, mpd-announce does not support any commands at this point. Usage: "/mpd"' else: c = mpdclient.MpdController(host='localhost',port=6600) #get song info song = c.getCurrentSong() z = c.getSongPosition() progress = str(z[2]) # print 'Currently playing: ' + song.artist + ' - ' + song.title + ' [' + progress[:4] + '%]' xchat.command('say Currently playing: ' + song.artist + ' - ' + song.title + ' [' + progress[:4] + '%]') #print it to xchat return xchat.EAT_XCHAT xchat.hook_command("MPD", mpd_announce, help='/MPD displays song currently played by MPD') #get command from xchat""" script = re.sub('6600', port, script) script = re.sub('localhost',host, script) os.chdir(os.environ["HOME"] + '/.xchat2/') file=open('mpd2.py', 'w') file.write(script) file.close()x=mpd_settings()for i in range(len(x)): results.append(x[i])y=module_needsinstall()results.append(y)if results[2] == 'y': install_module()elif results[2] == 'yes': install_module()else: install_script(results[0],results[1])install_script(results[0],results[1])