# # Spotify Irssi plugin # Decode and print information from Spotify URIs # # TODO: print private messages to right place (help me?) # # # Changes # 0.29: Fixed regexp use strict; use Irssi; use Irssi::Irc; use LWP::UserAgent; use vars qw($VERSION %IRSSI); $VERSION = '0.29'; %IRSSI = ( authors => 'Toni Viemerö', contact => 'toni.viemero@iki.fi', name => 'spotifyuri', description => 'Decode Spotify URIs', license => 'BSD', url => 'http://spotify.url.fi/', ); sub spotifyuri_public { my ($server, $data, $nick, $mask, $target) = @_; my $retval = spotifyuri_get($data); my $win = $server->window_item_find($target); if ($win) { $win->print("[spotifyuri] $retval", MSGLEVEL_CRAP) if $retval; } else { Irssi::print("[spotifyuri] $retval") if $retval; } } sub spotifyuri_private { my ($server, $data, $nick, $mask) = @_; my $retval = spotifyuri_get($data); my $win = $server->window_item_find($nick); if ($win) { $win->print("[spotifyuri] $retval", MSGLEVEL_CRAP) if $retval; } else { Irssi::print("[spotifyuri] $retval") if $retval; } } sub spotifyuri_parse { my ($url) = @_; if ($url =~ /(http:\/\/open.spotify.com\/|spotify:)(album|artist|track)([:\/])([a-zA-Z0-9]+)\/?/) { return "http://spotify.url.fi/$2/$4?txt"; } return 0; } sub spotifyuri_get { my ($data) = @_; my $url = spotifyuri_parse($data); my $ua = LWP::UserAgent->new(env_proxy=>1, keep_alive=>1, timeout=>5); $ua->agent("irssi/$VERSION " . $ua->agent()); my $req = HTTP::Request->new('GET', $url); my $res = $ua->request($req); if ($res->is_success()) { return $res->content(); } return 0; } Irssi::signal_add_last('message public', 'spotifyuri_public'); Irssi::signal_add_last('message private', 'spotifyuri_private');