# Ampache Now-Playing Script for irssi # Copyright (C) 2012 Paul Arthur # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License version 2 # as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # The full version of the license can be found at # http://www.gnu.org/copyleft/gpl.html. use strict; use LWP::UserAgent; use Irssi; use vars qw{$VERSION %IRSSI}; $VERSION = "0.1"; %IRSSI = ( name => 'ampache', authors => 'Paul Arthur', contact => 'ampache@flowerysong.com', license => 'GPLv2', description => 'Print the song you are listening to', ); sub np { my ($data,$server,$witem) = @_; my $url = Irssi::settings_get_str('ampache_url') . '/rss.php?type=now_playing'; my $ua = LWP::UserAgent->new; $ua->agent("ampache/irssi/$VERSION"); my $request = HTTP::Request->new(GET => $url); my $result = $ua->request($request); if (!$result->is_success) { Irssi::print("LWP request failed: $result->code"); return; } my $string = '/me np: '; my $content = $result->content; $content =~ s/.*//s; $content =~ s/<\/description>.*//s; $content = substr($content, 9, -3); $string .= $content; if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) { $witem->command($string); } else { Irssi::print("You're not in a channel."); } } Irssi::settings_add_str('ampache', 'ampache_url', ''); Irssi::command_bind np => \&np;