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 $fg = defined($fg)?$fg:'default';
71 $bg = defined($bg)?$bg:'default';
73 return weechat::color($fg . ",", $bg);
77 # Handle commands (/videosite ...)
80 my ($data, $buffer, $args) = @_;
83 ewpf => sub { weechat::print($buffer, @_) },
86 libvideosite::handle_command(\%event);
88 return weechat::WEECHAT_RC_OK;
92 # Handle a received message.
93 # Create an event structure and hand it off to libvideosite
96 my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message ) = @_;
99 ewpf => sub { weechat::print($buffer, @_) },
102 libvideosite::check_for_link(\%event);
104 return weechat::WEECHAT_RC_OK;
110 sub videosite_reset {
111 unless(libvideosite::register_api({
112 io => sub { weechat::print("", @_) },
113 config_init => sub {},
114 config_get => \&config_get,
115 config_set => \&config_set,
116 config_has => \&config_has,
117 config_save => sub {},
118 config_del => \&config_del,
119 color => \&colorpair,
120 module_path => sub { return File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl') },
121 quote => sub { return $_ },
124 weechat::print("", sprintf("videosite API register failed: %s", $libvideosite::error));
128 unless(libvideosite::init()) {
129 weechat::print("", sprintf("videosite init failed: %s", $libvideosite::error));
137 # Find out the script directory, and add it to @INC.
138 # This is necessary to find libvideosite.pm
140 push(@INC, File::Spec->catfile(weechat::info_get("weechat_dir", ""), 'perl'));
143 if (videosite_reset()) {
144 weechat::hook_print("", "notify_message", "://", 1, "message_hook", "");
145 weechat::hook_print("", "notify_private", "://", 1, "message_hook", "");
146 weechat::hook_print("", "notify_highlight", "://", 1, "message_hook", "");
147 weechat::hook_print("", "notify_none", "://", 1, "message_hook", "");
148 weechat::hook_command( "videosite", "videosite control functions", "", "", "", "videosite_hook", "");