API workers using Gearman::Driver
[cloudstore.git] / torrent / transmission-client.pl
index 8bccb81..8ddae2f 100755 (executable)
@@ -10,6 +10,8 @@ transmission-client.pl - Alternative to transmission-remote
  transmission-client.pl session;
  transmission-client.pl session $key $value;
  transmission-client.pl stats;
+ transmission-client.pl add /path/to/file.torrent
+ transmission-client.pl remove 1 [,2,3...]
 
 =head1 DESCRIPTION
 
@@ -21,15 +23,20 @@ use strict;
 use warnings;
 use lib qw(lib);
 use Transmission::Client;
+use Data::Dump qw(dump);
 
 my $action = shift @ARGV or _help();
 
-my $tc = Transmission::Client->new;
+my %a = ( autodie => 1 );
+@a{ qw(username password) } = split(/:/, $ENV{TR_AUTH}) if $ENV{TR_AUTH};
+
+my $tc = Transmission::Client->new( %a );
 
 if($action eq 'list') {
     printf "%3s %-34s %4s %4s %5s %5s\n", 'id', 'name', 'lcrs', 'sdrs', 'rate', 'eta';
     print "-" x 79, "\n";
     for my $torrent ($tc->read_torrents) {
+       warn dump($torrent) if $ENV{DEBUG};
         printf "%3i %-34s %4s %4s %5s %5s\n",
             $torrent->id,
             substr($torrent->name, 0, 34),
@@ -60,6 +67,20 @@ elsif($action eq 'stats') {
         printf "%-30s %s\n", $key, $res->{$key};
     }
 }
+
+elsif($action eq 'add') {
+       $tc->add(
+               filename => $ARGV[0],
+               download_dir => '/rsync1/s1/torrent/download',
+       );
+}
+
+elsif($action eq 'remove') {
+       $tc->remove(
+               ids => @ARGV
+       );
+}
+
 else {
     _help();
 }