#!/usr/bin/env python
#Script that prints last played songs from last.fm to xchat
import re, commands, xchat
from urllib import urlopen
#Variables, please change this int oyuor last.fm nickname
user='b4d'
author = 'b4d, www.baccic.be'
__module_name__ = "Xchat lastfm"
__module_version__ = "0.1"
__module_description__ = "python module for xchat to display last played tracks on last.fm"
def lastfm(word, word_eol, userdata):
# open the site
last = urlopen("http://ws.audioscrobbler.com/1.0/user/%s/recenttracks.rss" % user)
# read and close
readit = last.read()
last.close()
# what we are looking for
played = re.compile('<title>(.*?)</title>', re.DOTALL)
# store the data
info = played.findall(readit)[:6]
for song in info:
try: xchat.command('say %s' % song)
except UnboundLocalError: pass
return xchat.EAT_ALL
xchat.hook_command("lastfm", lastfm)
print "lastfmxchat.py loaded"