Skip to content

Instantly share code, notes, and snippets.

@tatey tatey/lastfm.pl
Created Oct 31, 2008

Embed
What would you like to do?
# Now playing script for Irssi which retrieves your currently listened to song from the Last.fm API
#
# 1) Define your last.fm username and api account key
# 2) Load script in to Irssi "/script load lastfm" (Assuming you've placed the script in .irssi/scripts)
# 3) Execute script from witin Irssi "/np"
my $user = "<USERNAME>";
my $api_key = "<API_KEY>";
##### DO NOT EDIT BELOW THIS LINE #####
use strict;
use LWP::UserAgent;
use vars qw($VERSION %IRSSI);
use Irssi;
$VERSION = '1.01';
%IRSSI = (
authors => 'sartek',
contact => 'andras.barna@gmail.com',
name => 'Last.fm now playing',
description => 'Prints the recently played /np song from last.fm',
license => 'CDDL',
);
sub nowplaying {
my $agent = new LWP::UserAgent;
my $request = new HTTP::Request ("GET", "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$user&api_key=$api_key&limit=1");
$agent -> agent ("Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9pre) Gecko/2008050101 Minefield/3.0pre");
my $buf = $agent -> request ($request);
$buf = $buf -> content;
$buf =~ /<artist mbid="[a-z0-9-]*">(.+)<\/artist>/; my $artist = $1;
$buf =~ /<name>(.+)<\/name>/; my $title = $1;
Irssi::active_win()->command('/me np: ' . $artist ." - ". $title . " | http://last.fm/user/$user");
}
Irssi::command_bind('np', 'nowplaying');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.