X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite.pl;h=5fa6006e680197d1b0dedeb1c2be18a08c71e55f;hb=3d47807ddfbde83a6454c9a9e39ead80456e0c9f;hp=4eada1399130e734a5bcb873be33f09d7c5237df;hpb=35306939804820c033c8e25ab5aa5134f5dc5735;p=videosite.git diff --git a/videosite.pl b/videosite.pl index 4eada13..5fa6006 100644 --- a/videosite.pl +++ b/videosite.pl @@ -50,12 +50,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, @_); @@ -78,9 +72,15 @@ 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_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'); @@ -91,9 +91,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, 'videosite: Could not save config to %s: %s', ($conffile, $@)); + } else { + write_irssi(undef, 'Videosite configuration saved to %s', $conffile); + } } sub cmd_set { @@ -149,7 +156,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 } } @@ -226,7 +242,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' => '' }}; @@ -257,6 +273,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); }