-# autodownload flash videos
+# shim to connect libvideosite to irssi
#
# (c) 2007-2008 by Ralf Ertzinger <ralf@camperquake.de>
# licensed under GNU GPL v2
-#
-# Based on youtube.pl by Christian Garbs <mitch@cgarbs.de>
-# which in turn is
-# based on trigger.pl by Wouter Coekaerts <wouter@coekaerts.be>
-
use strict;
use Irssi 20020324 qw (command_bind command_runsub signal_add_first signal_add_last);
use vars qw($VERSION %IRSSI);
use File::Spec;
+use Module::Load;
+use XML::Simple;
+use JSON -support_by_pp;
+
+#
+# List of foreground colors. This list is not complete, it just
+# contains the colors needed by videosite.
+#
+# The % are doubled because these are used in sprintf.
+#
+my %foreground_colors = (
+ 'magenta' => '%%m',
+ '*magenta' => '%%M',
+ '*yellow' => '%%Y',
+ '*green' => '%%G',
+ '*red' => '%%R',
+ 'default' => '%%n',
+);
#
# Initialize the config subsystem. Called by the core.
# Try to find old config files and load them.
if (-r $conffile) {
+ Irssi::print("Converting configuration from videosite.json. This will happen only once.");
eval {
local $/;
open(CONF, '<', $conffile);
close(CONF);
};
} elsif (-r $xmlconffile) {
+ Irssi::print("Converting configuration from videosite.xml. This will happen only once.");
$conf = XML::Simple::XMLin($xmlconffile, ForceArray => ['config', 'option', 'connectorlist'], KeepRoot => 1, KeyAttr => {'connector' => '+name', 'config' => 'module', 'option' => 'key'});
+ } else {
+ # No old config files around. Just exit.
+ return;
}
#
# Copy the "basic" settings.
foreach (qw(getter mode)) {
- config_set(['getter'], $conf->{videosite}->{$_});
+ config_set([$_], $conf->{videosite}->{$_});
}
# Copy the per-getter/setter settings
}
}
}
- config_set(['active-connectors'], join(",", @{$conf->{connectorlist}}));
+ config_set(['active-connectors'], join(",", @{$conf->{videosite}->{connectorlist}}));
config_set(['defined-connectors'], join(",", @connectors));
config_set(['config-version'], '2');
}
my $val;
- Irssi::settings_add_str('videosite', $item, "\0");
- $val = Irssi::settigs_get_str($item);
+ Irssi::settings_add_str('videosite', $item, "\1");
+ $val = Irssi::settings_get_str($item);
- return ($val ne "\0")?$val:undef;
+ return ($val ne "\1")?$val:undef;
}
#
my $path = shift;
my $item = join('.', 'videosite', @{$path});
- Irssi::settings_add_str('videosite', $item, "\0");
- return Irssi::settings_get_str ne "\0";
+ Irssi::settings_add_str('videosite', $item, "\1");
+ return Irssi::settings_get_str($item) ne "\1";
}
#
my $value = shift;
my $item = join('.', 'videosite', @{$path});
- Irssi::settings_add_str('videosite', $item, "\0");
+ Irssi::settings_add_str('videosite', $item, "\1");
Irssi::settings_set_str($item, $value);
}
#
# Return a color code. Called by the core
#
+# Does not handle background colors yet.
+#
sub colorpair {
my ($fg, $bg) = @_;
- Irssi::print(sprintf("Asked to convert (%s,%s) into irssi color codes", $fg, $bg));o
+ $fg = exists($foreground_colors{$fg})?$foreground_colors{$fg}:'';
+ $bg = '';
- return '';
+ return $fg . $bg;
}
#
my ($cmdline, $server, $witem) = @_;
my %event = (
message => $cmdline,
- ewpf => sub { defined($evitem)?$evitem->print(@_):Irssi::print(@_) },
+ ewpf => sub { defined($witem)?$witem->print($_[0]):Irssi::print($_[0]) },
);
libvideosite::handle_command(\%event);
my $evitem = $server->window_item_find($channel);
my %event = (
message => $msg,
- ewpf => sub { defined($evitem)?$evitem->print(@_):Irssi::print(@_) },
+ ewpf => sub { defined($evitem)?$evitem->print($_[0]):Irssi::print($_[0]) },
);
libvideosite::check_for_link(\%event);
sub videosite_reset {
unless(libvideosite::register_api({
- io => sub { Irssi::print(@_) },
+ io => sub { Irssi::print($_[0]) },
config_init => \&config_init,
config_get => \&config_get,
config_set => \&config_set,