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, @_) },
83 libvideosite::handle_command(\%event);
85 return weechat::WEECHAT_RC_OK;
89 # Handle a received message.
90 # Create an event structure and hand it off to libvideosite
93 my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message ) = @_;
96 ewpf => sub { weechat::print($buffer, @_) },
99 libvideosite::check_for_link(\%event);
101 return weechat::WEECHAT_RC_OK;
107 sub videosite_reset {
108 unless(libvideosite::register_api({
109 io => sub { weechat::print("", @_) },
110 config_init => sub {},
111 config_get => \&config_get,
112 config_set => \&config_set,
113 config_has => \&config_has,
114 config_save => sub {},
115 config_del => \&config_del,
116 color => \&colorpair,
117 module_path => sub { return File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl') },
118 quote => sub { return $_ },
121 weechat::print("", sprintf("videosite API register failed: %s", $libvideosite::error));
125 unless(libvideosite::init()) {
126 weechat::print("", sprintf("videosite init failed: %s", $libvideosite::error));
134 # Find out the script directory, and add it to @INC.
135 # This is necessary to find libvideosite.pm
137 push(@INC, File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl'));
140 if (videosite_reset()) {
141 weechat::hook_print("", "notify_message", "://", 1, "message_hook", "");
142 weechat::hook_print("", "notify_private", "://", 1, "message_hook", "");
143 weechat::hook_print("", "notify_highlight", "://", 1, "message_hook", "");
144 weechat::hook_print("", "notify_none", "://", 1, "message_hook", "");
145 weechat::hook_command( "videosite", "videosite control functions", "", "", "", "videosite_hook", "");