dump body
[cloudstore.git] / torrent / rtorrent-dump.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use RTPG;
6 use Data::Dump qw(dump);
7
8 my $h = new RTPG(url=> $ENV{SOCKET} || '/rsync1/s1/torrent/socket');
9
10 if ( @ARGV ) {
11         print "# ",dump(@ARGV), " -> ";
12         my $out = $h->rpc_command(@ARGV);
13         print dump($out),$/;
14         exit;
15 }
16
17 my $sfmt;
18 my @keys;
19 while (<DATA>) {
20         chomp;
21         next if /^#/;
22         my ($name,$fmt) = split(/\t+/,$_,2);
23         $sfmt .= $fmt . ' ';
24         push @keys, $name;
25 }
26 $sfmt =~ s/\s+$/\n/;
27
28 # arrayref and error (standard version)
29 my ($tlist, $error)=$h->torrents_list;
30 warn dump( $tlist, $error ) if $ENV{DEBUG};
31
32 printf $sfmt, @keys;
33 foreach my $t ( @$tlist ) {
34         printf $sfmt, map { $t->{$_} } @keys;
35 }
36
37 __DATA__
38 #hash                   %-40s
39 percent                 %5s
40 status                  %-11s
41 size_bytes              %12d
42 #base_filename  %s
43 loaded_file             %s