1 # shim to connect libvideosite to weechat
3 # (c) 2007-2008 by Ralf Ertzinger <ralf@camperquake.de>
4 # licensed under GNU GPL v2
12 "Ralf Ertzinger (ralf\@skytale.net)",
15 "videosite Video URL grabber script (usage: /videosite)",
20 # Reading a configuration value. Called by the core
24 my $item = join('.', @{$path});
26 if (weechat::config_is_set_plugin($item)) {
27 return weechat::config_get_plugin($item);
34 # Returns a true value if the config item exists
38 my $item = join('.', @{$path});
40 return weechat::config_is_set_plugin($item);
44 # Setting a configuration value. Called by the core
49 my $item = join('.', @{$path});
51 weechat::config_set_plugin($item, $value);
55 # Delete a configuration value. Called by the core.
59 my $item = join('.', @{$path});
61 weechat::config_unset_plugin($item);
65 # Return a color code. Called by the core
70 return weechat::color($fg . ",", $bg);
74 # Handle commands (/videosite ...)
77 my ($data, $buffer, $args) = @_;
80 ewpf => sub { weechat::print($buffer, @_) },
84 libvideosite::handle_command(\%event);
86 return weechat::WEECHAT_RC_OK;
90 # Handle a received message.
91 # Create an event structure and hand it off to libvideosite
94 my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message ) = @_;
97 ewpf => sub { weechat::print($buffer, @_) },
101 libvideosite::check_for_link(\%event);
103 return weechat::WEECHAT_RC_OK;
109 sub videosite_reset {
110 unless(libvideosite::register_api({
111 io => sub { weechat::print("", @_) },
112 config_init => sub {},
113 config_get => \&config_get,
114 config_set => \&config_set,
115 config_has => \&config_has,
116 config_save => sub { 1 },
117 config_del => \&config_del,
118 color => \&colorpair,
119 module_path => sub { return File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl') },
120 quote => sub { return $_ },
121 reload => sub { weechat::print("", "Please use \"/script reload ...\" to reload") },
123 weechat::print("", sprintf("videosite API register failed: %s", $libvideosite::error));
127 unless(libvideosite::init()) {
128 weechat::print("", sprintf("videosite init failed: %s", $libvideosite::error));
136 # Find out the script directory, and add it to @INC.
137 # This is necessary to find libvideosite.pm
139 push(@INC, File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl'));
142 if (videosite_reset()) {
143 weechat::hook_print("", "notify_message", "://", 1, "message_hook", "");
144 weechat::hook_print("", "notify_private", "://", 1, "message_hook", "");
145 weechat::hook_print("", "notify_highlight", "://", 1, "message_hook", "");
146 weechat::hook_print("", "notify_none", "://", 1, "message_hook", "");
147 weechat::hook_command( "videosite", "videosite control functions", "", "", "", "videosite_hook", "");