5 transmission-client.pl - Alternative to transmission-remote
9 transmission-client.pl list;
10 transmission-client.pl session;
11 transmission-client.pl session $key $value;
12 transmission-client.pl stats;
13 transmission-client.pl add /path/to/file.torrent
14 transmission-client.pl remove 1 [,2,3...]
18 This is an example application for L<Transmission::Client>
25 use Transmission::Client;
26 use Data::Dump qw(dump);
28 my $action = shift @ARGV or _help();
30 my %a = ( autodie => 1 );
31 @a{ qw(username password) } = split(/:/, $ENV{TR_AUTH}) if $ENV{TR_AUTH};
33 my $tc = Transmission::Client->new( %a );
35 if($action eq 'list') {
36 printf "%3s %-34s %4s %4s %5s %5s\n", 'id', 'name', 'lcrs', 'sdrs', 'rate', 'eta';
38 for my $torrent ($tc->read_torrents) {
39 warn dump($torrent) if $ENV{DEBUG};
40 printf "%3i %-34s %4s %4s %5s %5s\n",
42 substr($torrent->name, 0, 34),
43 _peers($torrent->leechers),
44 _peers($torrent->seeders),
45 _rate($torrent->rate_download),
50 elsif($action eq 'session') {
51 if(my $set = shift @ARGV) {
52 $tc->session->$set(shift @ARGV);
53 $tc->session->${ \"clear_$set" };
54 printf "%s: %s\n", $set, $tc->session->$set;
58 my $res = $tc->session->read_all;
59 for my $key (sort keys %$res) {
60 printf "%-30s %s\n", $key, $res->{$key};
64 elsif($action eq 'stats') {
65 my $res = $tc->session->stats->read_all;
66 for my $key (sort keys %$res) {
67 printf "%-30s %s\n", $key, $res->{$key};
71 elsif($action eq 'add') {
74 download_dir => '/rsync1/s1/torrent/download',
78 elsif($action eq 'remove') {
90 #==============================================================================
110 elsif($kbps < 1000) {
114 return int($kbps / 1e3) . 'k';
117 return int($kbps / 1e6) . 'M';
134 return int($sec / 6) / 10 . "m";
136 elsif($sec < 86400) {
137 return int($sec / 360) / 10 . "h";
145 exec perldoc => -tT => $0;
150 This library is free software; you can redistribute it and/or modify it under
151 the same terms as Perl itself.