Skip to content

Instantly share code, notes, and snippets.

@tatey
Created October 31, 2008 14:37
Show Gist options
  • Save tatey/21317 to your computer and use it in GitHub Desktop.
Save tatey/21317 to your computer and use it in GitHub Desktop.
# 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 => '[email protected]',
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