use strict; use vars qw($VERSION %IRSSI); use Irssi qw(command_bind active_win); use LWP::UserAgent; $VERSION = '0.1.1'; %IRSSI = ( authors => 'Damian Pasternok', contact => '', name => 'last.fm now playing script', description => 'displays last played song from Audioscrobbler', license => 'GPL', url => 'http://crahker.ath.cx/lastfm', changed => 'Wed Sep 10 11:41:10 CEST 2007', commands => 'lastfm', ); # replace the $username variable with your login from last.fm my $username = 'CrAhKeR'; my $cache; sub get_title { my $lfm_url = "http://ws.audioscrobbler.com/1.0/user/$username/recenttracks.txt"; my $agent = LWP::UserAgent->new; $agent->agent('irssi'); $agent->timeout(60); my $request = HTTP::Request->new(GET => $lfm_url); my $result = $agent->request($request); $result->is_success or return; my $str = $result->content; my @arr = split(/\n/, $str); my $new_track = ''; $new_track = $arr[0]; $new_track =~ s/^[0-9]*,//; $new_track =~ s/\xe2\x80\x93/-/; if($cache eq $new_track) { return; } else { active_win->command("/me is listening to $new_track (last.fm)"); $cache = $new_track; } } Irssi::command_bind('lastfm', 'get_title'); Irssi::print("last.fm now playing script $VERSION.");