X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite.pl;h=58e4c967392f8294fdc2c6957b3264aac4e42a1e;hb=04ab1c3a6f2107d94804fc7c99ecce659d1ee1b8;hp=ee1fa2695f3b581cda4cdc1bc05b07b21c5ab44a;hpb=671cb9fa217ef151045e7191f175b1437c64f45d;p=videosite.git diff --git a/videosite.pl b/videosite.pl index ee1fa26..58e4c96 100644 --- a/videosite.pl +++ b/videosite.pl @@ -1,9 +1,11 @@ # autodownload flash videos # -# (c) 2007 by Ralf Ertzinger +# (c) 2007-2008 by Ralf Ertzinger # licensed under GNU GPL v2 # # Based on youtube.pl by Christian Garbs +# which in turn is +# based on trigger.pl by Wouter Coekaerts use strict; use Irssi 20020324 qw (command_bind command_runsub signal_add_first signal_add_last); @@ -40,6 +42,8 @@ sub write_irssi { my $witem = shift; my @text = @_; + $text[0] = 'videosite: ' . $text[0]; + if (defined $witem) { $witem->print(sprintf(shift(@text), @text), MSGLEVEL_CLIENTCRAP); } else { @@ -48,12 +52,6 @@ sub write_irssi { } -sub write_verbose { - if (Irssi::settings_get_bool('youtube_verbose')) { - write_irssi(shift, @_); - } -} - sub write_debug { if ($debug) { write_irssi(shift, @_); @@ -76,10 +74,16 @@ sub check_for_link { $witem = Irssi::window_item_find($target); } + # Look if we should ignore this line + if ($message =~ m,(?:\s|^)/nosave(?:\s|$),) { + return; + } + # Offer the message to all Grabbers in turn foreach $g (@grabbers) { if (defined($m = $g->get($message))) { - write_irssi($witem, '%%R>>> %%NSaving %%Y%s%%N %%G%s', $m->{'TYPE'}, $m->{'TITLE'}); + write_debug($witem, 'Metadata: %s', Dumper($m)); + write_irssi($witem, '%%R>>> %%NSaving %%Y%s%%N %%G%s', $m->{'SOURCE'}, $m->{'TITLE'}); unless($getter->get($m)) { write_irssi($witem, '%%R>>> FAILED'); } @@ -89,9 +93,16 @@ sub check_for_link { sub cmd_save { - open(CONF, '>'.$conffile); - print CONF XML::Simple::XMLout($conf, KeepRoot => 1, KeyAttr => ['module', 'key']); - close(CONF); + eval { + open(CONF, '>'.$conffile) or die 'Could not open config file'; + print CONF XML::Simple::XMLout($conf, KeepRoot => 1, KeyAttr => {'config' => 'module', 'option' => 'key'}); + close(CONF); + }; + if ($@) { + write_irssi(undef, 'Could not save config to %s: %s', ($conffile, $@)); + } else { + write_irssi(undef, 'configuration saved to %s', $conffile); + } } sub cmd_set { @@ -147,7 +158,16 @@ sub cmd_help { } write_irssi(undef, 'No such module'); } else { - write_irssi(undef, "Supported commands:\n save: Save the current configuration\n help [modulename]: Display this help, or module specific help\n show [modulename]: Show loaded modules, or the current parameters of a module\n set modulename parameter value: set a module parameter to a new value\n getter [modulename]: display or set the getter to use"); + write_irssi(undef, <<'EOT'); +Supported commands: + save: Save the current configuration + help [modulename]: Display this help, or module specific help + show [modulename]: Show loaded modules, or the current parameters of a module + set modulename parameter value: set a module parameter to a new value + getter [modulename]: display or set the getter to use + debug: enable debugging messages + nodebug: disable debugging messages +EOT } } @@ -224,7 +244,7 @@ sub init_videosite { my $p; - unless(-r $conffile && defined($conf = XML::Simple::XMLin($conffile, ForceArray => ['config', 'option'], KeepRoot => 1, KeyAttr => ['module', 'key']))) { + unless(-r $conffile && defined($conf = XML::Simple::XMLin($conffile, ForceArray => ['config', 'option'], KeepRoot => 1, KeyAttr => {'config' => 'module', 'option' => 'key'}))) { # No config, start with an empty one write_debug(undef, 'No config found, using defaults'); $conf = { 'videosite' => { 'getter' => '' }}; @@ -255,6 +275,8 @@ sub init_videosite { Irssi::signal_add_first('command script load', 'sig_command_script_unload'); Irssi::signal_add_first('command script unload', 'sig_command_script_unload'); + Irssi::signal_add('setup saved', 'cmd_save'); + Irssi::command_bind('videosite' => \&cmdhandler); }