1#!/usr/local/bin/perl
2
3# ixmmsa.pl (iXMMSa - irssi XMMS announce), Version 0.3
4#
5# Copyleft (>) 2002 Kristof Korwisi <kk@manoli.im-dachgeschoss.de>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# The complete text of the GNU General Public License can be found
18# on the World Wide Web: <URL:http://www.gnu.org/licenses/gpl.html>
19
20use Xmms();
21use Xmms::Remote ();
22use strict;
23use Irssi;
24use vars qw($VERSION %IRSSI);
25
26$VERSION = "0.2+1";
27%IRSSI = (
28	authors		=> 'Kristof Korwisi',
29	contact		=> 'kk@manoli.im-dachgeschoss.de',
30	name		=> 'iXMMSa',
31	description	=> '/xmms announces which _file_ is currently playing. E.g.  Currently playing: "Kieran Halpin & Band - Mirror Town.mp3"',
32	license		=> 'GPL',
33	url		=> 'http://manoli.im-dachgeschoss.de/~kk/',
34	changed		=> '2006-10-27',
35	changes		=> 'added some comments, added $announce_message:_*-stuff',
36);
37
38Irssi::print("*****\n* $IRSSI{name} $VERSION loaded.\n* Type /xmms to announce currently played file.\n*****");
39
40sub cmd_xmms {
41
42	my ($data, $server, $witem) = @_;
43	my $xmms_remote = Xmms::Remote->new;
44
45        my $announce_message_front = "Currently playing:";      # announce message in front of the filename playing
46	my $announce_message_after = "";                        # announce message after the filename playing
47
48
49	$filename= $xmms_remote->get_playlist_file($xmms_remote->get_playlist_pos);
50
51
52	$filename =~ s/.*\///g;					# removes path
53	$filename =~ s/^$/Nothing's playing/;			# in case there's nothing to listen to ;-)
54	$filename =~ s/[\r\n]/ /g;				# remove newline characters
55
56	if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) {
57		$witem->command("MSG ".$witem->{name}." $announce_message_front \"$filename\" $announce_message_after");
58	} else {
59		Irssi::print("Not on active channel/query");
60	}
61}
62
63Irssi::command_bind('xmms', 'cmd_xmms');
64