From a248862bbcea7eb1d35dcad2404e6713c303204d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 7 Jul 2008 05:53:15 +0000 Subject: [PATCH] transmission-remote: add a very detailed torrent `info' command --- daemon/remote.c | 203 +++++++++++++++++++++++++++++++++-- daemon/transmission-remote.1 | 29 +++-- 2 files changed, 216 insertions(+), 16 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 3e6355cd8..fcac570d2 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -53,7 +53,8 @@ showUsage( void ) " -f --files Get a file list for the specified torrent\n" " -g --debug Print debugging information\n" " -h --help Display this message and exit\n" - " -l --list Long list of all torrent and status\n" + " -i --info Detailed information for the specified torrent\n" + " -l --list List all torrents\n" " -m --port-mapping Automatic port mapping via NAT-PMP or UPnP\n" " -M --no-port-mapping Disable automatic port mapping\n" " -p --port Port to listen for incoming peers\n" @@ -117,7 +118,7 @@ static void readargs( int argc, char ** argv ) { int opt; - char optstr[] = "a:d:De:f:ghlmMp:r:s:S:t:u:Uv:w:xX"; + char optstr[] = "a:d:De:f:ghi:lmMp:r:s:S:t:u:Uv:w:xX"; const struct option longopts[] = { @@ -128,6 +129,7 @@ readargs( int argc, char ** argv ) { "files", required_argument, NULL, 'f' }, { "debug", no_argument, NULL, 'g' }, { "help", no_argument, NULL, 'h' }, + { "info", required_argument, NULL, 'i' }, { "list", no_argument, NULL, 'l' }, { "port-mapping", no_argument, NULL, 'm' }, { "no-port-mapping", no_argument, NULL, 'M' }, @@ -181,6 +183,20 @@ readargs( int argc, char ** argv ) | TR_RPC_TORRENT_FIELD_PRIORITIES; tr_bencDictAddInt( args, "fields", fields ); break; + case 'i': tr_bencDictAddStr( &top, "method", "torrent-get" ); + tr_bencDictAddInt( &top, "tag", TAG_DETAILS ); + tr_rpc_parse_list_str( tr_bencDictAdd( args, "ids" ), optarg, strlen(optarg) ); + fields = TR_RPC_TORRENT_FIELD_ACTIVITY + | TR_RPC_TORRENT_FIELD_ANNOUNCE + | TR_RPC_TORRENT_FIELD_ERROR + | TR_RPC_TORRENT_FIELD_HISTORY + | TR_RPC_TORRENT_FIELD_ID + | TR_RPC_TORRENT_FIELD_INFO + | TR_RPC_TORRENT_FIELD_SCRAPE + | TR_RPC_TORRENT_FIELD_SIZE + | TR_RPC_TORRENT_FIELD_TRACKER_STATS; + tr_bencDictAddInt( args, "fields", fields ); + break; case 'd': tr_bencDictAddStr( &top, "method", "session-set" ); tr_bencDictAddInt( args, "speed-limit-down", numarg( optarg ) ); tr_bencDictAddInt( args, "speed-limit-down-enabled", 1 ); @@ -297,6 +313,26 @@ etaToString( char * buf, size_t buflen, int64_t eta ) #define MEGABYTE_FACTOR (1024.0 * 1024.0) #define GIGABYTE_FACTOR (1024.0 * 1024.0 * 1024.0) +static char* +strlratio( char * buf, double numerator, double denominator, size_t buflen ) +{ + if( denominator ) + { + const double ratio = numerator / denominator; + if( ratio < 10.0 ) + snprintf( buf, buflen, "%'.2f", ratio ); + else if( ratio < 100.0 ) + snprintf( buf, buflen, "%'.1f", ratio ); + else + snprintf( buf, buflen, "%'.0f", ratio ); + } + else if( numerator ) + tr_strlcpy( buf, "Infinity", buflen ); + else + tr_strlcpy( buf, "None", buflen ); + return buf; +} + static char* strlsize( char * buf, int64_t size, size_t buflen ) { @@ -334,6 +370,159 @@ torrentStatusToString( int i ) } } +static void +printDetails( tr_benc * top ) +{ + tr_benc *args, *torrents; + + if( ( tr_bencDictFindDict( top, "arguments", &args ) ) && + ( tr_bencDictFindList( args, "torrents", &torrents ) ) ) + { + int ti, tCount; + for( ti=0, tCount=tr_bencListSize( torrents ); ti