1 # shim to connect libvideosite to weechat
3 # (c) 2007-2008 by Ralf Ertzinger <ralf@camperquake.de>
4 # licensed under GNU GPL v2
11 $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
15 "Ralf Ertzinger (ralf\@skytale.net)",
18 "videosite Video URL grabber script (usage: /videosite)",
23 # Reading a configuration value. Called by the core
27 my $item = join('.', @{$path});
29 if (weechat::config_is_set_plugin($item)) {
30 return weechat::config_get_plugin($item);
37 # Returns a true value if the config item exists
41 my $item = join('.', @{$path});
43 return weechat::config_is_set_plugin($item);
47 # Setting a configuration value. Called by the core
52 my $item = join('.', @{$path});
54 weechat::config_set_plugin($item, $value);
58 # Delete a configuration value. Called by the core.
62 my $item = join('.', @{$path});
64 weechat::config_unset_plugin($item);
68 # Return a color code. Called by the core
73 return weechat::color($fg . ",", $bg);
77 # Handle commands (/videosite ...)
80 my ($data, $buffer, $args) = @_;
83 io => sub { weechat::print($buffer, @_) },
87 libvideosite::handle_command(\%event);
89 return weechat::WEECHAT_RC_OK;
93 # Handle a received message.
94 # Create an event structure and hand it off to libvideosite
97 my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message ) = @_;
100 io => sub { weechat::print($buffer, @_) },
104 libvideosite::check_for_link(\%event);
106 return weechat::WEECHAT_RC_OK;
112 sub videosite_reset {
113 unless(libvideosite::register_api({
114 io => sub { weechat::print("", @_) },
115 config_init => sub {},
116 config_get => \&config_get,
117 config_set => \&config_set,
118 config_has => \&config_has,
119 config_save => sub { 1 },
120 config_del => \&config_del,
121 color => \&colorpair,
122 module_path => sub { return File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl') },
123 quote => sub { return $_ },
124 reload => sub { weechat::print("", "Please use \"/script reload ...\" to reload") },
126 weechat::print("", sprintf("videosite API register failed: %s", $libvideosite::error));
130 unless(libvideosite::init()) {
131 weechat::print("", sprintf("videosite init failed: %s", $libvideosite::error));
139 # Find out the script directory, and add it to @INC.
140 # This is necessary to find libvideosite.pm
142 push(@INC, File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl'));
145 if (videosite_reset()) {
146 weechat::hook_print("", "notify_message", "://", 1, "message_hook", "");
147 weechat::hook_print("", "notify_private", "://", 1, "message_hook", "");
148 weechat::hook_print("", "notify_highlight", "://", 1, "message_hook", "");
149 weechat::hook_print("", "notify_none", "://", 1, "message_hook", "");
150 weechat::hook_command( "videosite", "videosite control functions", "", "", "", "videosite_hook", "");