X-Chat Last.fm plugin

March 9th, 2009 | Categories: Programming | Tags: , , ,

上班無聊隨便寫了個….

This plugin can retrieve the most recent 10 updates from your personal rss on last.fm, please notice that there is delay for the rss to get updated.

## 	Use Modules 			##
use XML::Simple;
use LWP::Simple;
 
## 	last.fm home address 	##
## 	change to your own 		##
$home = "http://www.last.fm/user/jiening";
 
## 	last.fm feed rss 		##
## 	change to your own 		##
$url = "http://ws.audioscrobbler.com/1.0/user/jiening/recenttracks.rss";
 
##	Registering The Script 	##
##	and Commands 			##
Xchat::register("LastFM", "0.1", "A Script to display the latest song listed on your last.fm");
Xchat::hook_command("lastfm", lastfm);
Xchat::hook_command("lasthelp", lasthelp);
 
## 	Text to print when		##
##	the script is loaded 	##
sub lastfm_load {
	Xchat::command("ECHO ---");
	Xchat::command("ECHO LastFM 1.0 by Phill84 loaded");
	Xchat::command("ECHO For HELP type /lasthelp");
	Xchat::command("ECHO ---");
	return Xchat::EAT_NONE;
}
lastfm_load();
 
## 	Help 					##
sub lasthelp {
	Xchat::command("ECHO ---");
	Xchat::command("ECHO just type /lastfm, what's so difficult about it?");
	Xchat::command("ECHO ---");
	return Xchat::EAT_NONE;
}
 
## 	Main function 			##
sub lastfm {
	my $xml = new XML::Simple;
	my $content = get($url);
	if(!$content) {
		Xchat::command("ECHO Could not retrieve $url");
		return Xchat::EAT_NONE;
	} else {
		my $rss = $xml->XMLin($content);
		Xchat::command("SAY 10 recent updates on $home");
		for ($i = 0; $i < 10; $i ++) {
			my $title = $rss->{channel}->{item}[$i]->{title};
			my $date = $rss->{channel}->{item}[$i]->{pubDate};
			$date =~ s/\+0000//;
			Xchat::command("SAY $title - $date");
		}
	}
	return Xchat::EAT_NONE;
}

zip X Chat Last.fm plugin  lastfm.zip (794 bytes, 411 hits)

1 trackbacks

  1. X-Chat Last.fm plugin | phill84.org Pingback | 2009/03/09
Brain Bliss