libvideosite: Allow skipping of action depending on return value of link_callback
[videosite.git] / libvideosite.pm
index 4252338..da5aefa 100644 (file)
@@ -339,7 +339,7 @@ sub _config_list_add {
         @c = ();
     }
 
-    _debug("Adding %s to list %s", $item, join(".", $path));
+    _debug("Adding %s to list %s", $item, join(".", @{$path}));
     unless(grep { $_ eq $item } @c) {
         push(@c, $item);
     };
@@ -359,7 +359,7 @@ sub _config_list_del {
         return;
     }
 
-    _debug("Removing %s from list %s", $item, join('.', $path));
+    _debug("Removing %s from list %s", $item, join('.', @{$path}));
     @c = map { $item ne $_ } split(/\s*,\s*/, _config_get($path));
 
     _config_set($path, join('.', @c));
@@ -376,7 +376,7 @@ sub _config_list_has {
         return 0;
     }
 
-    _debug("Checking for %s in list %s",  $item, join('.', $path));
+    _debug("Checking for %s in list %s",  $item, join('.', @{$path}));
 
     return grep { $item eq $_ } split(/\s*,\s*/, _config_get($path));
 }
@@ -387,7 +387,7 @@ sub _config_list_has {
 sub _config_list_set {
     my $path = shift;
 
-    _debug("Replacing %s with (%s)", join('.', $path), join(",", @_));
+    _debug("Replacing %s with (%s)", join('.', @{$path}), join(",", @_));
 
     _config_set($path, join(',', @_));
 }
@@ -730,7 +730,7 @@ sub _cmd_connector {
             return;
         }
 
-        unless (_config_list_has(['defined-connectors'])) {
+        unless (_config_list_has(['defined-connectors'], $name)) {
             _io("Connector does not exist");
             return;
         }
@@ -979,6 +979,7 @@ sub check_for_link {
     my $g;
     my $m;
     my $p;
+    my $skip;
 
 
     # Look if we should ignore this line
@@ -996,38 +997,41 @@ sub check_for_link {
         ($m, $p) = $g->get($message);
         while (defined($m)) {
             _debug('Metadata: %s', Dumper($m));
+            $skip = 0;
             if (exists($remote_api->{link_callback})) {
-                $remote_api->{link_callback}->($m);
+                $skip = $remote_api->{link_callback}->($m);
             }
-            if ('download' eq _config_get(['mode'])) {
-                _io(
-                    sprintf('%s>>> %sSaving %s%%s%s %s%%s',
-                        _colorpair('*red'),
-                        _colorpair(),
-                        _colorpair('*yellow'),
-                        _colorpair(),
-                        _colorpair('*green'),
-                    ),
-                    $m->{'SOURCE'},
-                    $m->{'TITLE'}
-                );
-                unless($getter->get($m)) {
-                    _io(sprintf('%s>>> FAILED', _colorpair('*red')));
+            unless($skip) {
+                if ('download' eq _config_get(['mode'])) {
+                    _io(
+                        sprintf('%s>>> %sSaving %s%%s%s %s%%s',
+                            _colorpair('*red'),
+                            _colorpair(),
+                            _colorpair('*yellow'),
+                            _colorpair(),
+                            _colorpair('*green'),
+                        ),
+                        $m->{'SOURCE'},
+                        $m->{'TITLE'}
+                    );
+                    unless($getter->get($m)) {
+                        _io(sprintf('%s>>> FAILED', _colorpair('*red')));
+                    }
+                } elsif ('display' eq _config_get(['mode'])) {
+                    _io(
+                        sprintf('%s>>> %sSaw %s%%s%s %s%%s',
+                            _colorpair('*magenta'),
+                            _colorpair(),
+                            _colorpair('*yellow'),
+                            _colorpair(),
+                            _colorpair('*green')
+                        ),
+                        $m->{'SOURCE'},
+                        $m->{'TITLE'}
+                    );
+                } else {
+                    _io(sprintf('%s>>> Invalid operation mode', _colorpair('*red')));
                 }
-            } elsif ('display' eq _config_get(['mode'])) {
-                _io(
-                    sprintf('%s>>> %sSaw %s%%s%s %s%%s',
-                        _colorpair('*magenta'),
-                        _colorpair(),
-                        _colorpair('*yellow'),
-                        _colorpair(),
-                        _colorpair('*green')
-                    ),
-                    $m->{'SOURCE'},
-                    $m->{'TITLE'}
-                );
-            } else {
-                _io(sprintf('%s>>> Invalid operation mode', _colorpair('*red')));
             }
 
             # Remove the matched part from the message and try again (there may be