use RTPG;
use Data::Dump qw(dump);
-my $h = new RTPG(url=>'/srv/cloudstore/var/torrent/socket');
+my $h = new RTPG(url=> $ENV{SOCKET} || '/rsync1/s1/torrent/socket');
+
+if ( @ARGV ) {
+ print "# ",dump(@ARGV), " -> ";
+ my $out = $h->rpc_command(@ARGV);
+ print dump($out),$/;
+ exit;
+}
+
+my $sfmt;
+my @keys;
+while (<DATA>) {
+ chomp;
+ next if /^#/;
+ my ($name,$fmt) = split(/\t+/,$_,2);
+ $sfmt .= $fmt . ' ';
+ push @keys, $name;
+}
+$sfmt =~ s/\s+$/\n/;
# arrayref and error (standard version)
my ($tlist, $error)=$h->torrents_list;
-print dump( $tlist, $error );
+warn dump( $tlist, $error ) if $ENV{DEBUG};
+
+printf $sfmt, @keys;
+foreach my $t ( @$tlist ) {
+ printf $sfmt, map { $t->{$_} } @keys;
+}
+
+__DATA__
+#hash %-40s
+percent %5s
+status %-11s
+size_bytes %12d
+#base_filename %s
+loaded_file %s