From 45a216bdc2cbcd80b67d34533c2a4576119a76c8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 10 Jul 2008 20:59:15 +0000 Subject: [PATCH] (daemon) let file download flags and priorities be set by transmission-remote. Add examples to the man page and --help. (libT) minor tweaks to tr-getopt (gtk) tweak the preference dialog's "port forwarding" text for clarity as suggested in the forums --- daemon/remote.c | 91 +++++++++++++++++++++++++++++++----- daemon/transmission-remote.1 | 80 ++++++++++++++++++++++++++----- gtk/tr-prefs.c | 2 +- libtransmission/rpc.c | 36 ++++++++++---- libtransmission/tr-getopt.c | 2 +- 5 files changed, 178 insertions(+), 33 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 69c524f0b..59114bb32 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -10,6 +10,7 @@ * $Id$ */ +#include #include #include #include /* strcmp */ @@ -36,22 +37,38 @@ enum { TAG_LIST, TAG_DETAILS, TAG_FILES }; static const char* getUsage( void ) { - return "Transmission "LONG_VERSION_STRING" http://www.transmissionbt.com/\n" - "A fast and easy BitTorrent client\n" - "\n" - "Usage: "MY_NAME" [host] [options]\n" - " "MY_NAME" [port] [options]\n" - " "MY_NAME" [host:port] [options]"; + return +"Transmission "LONG_VERSION_STRING" http://www.transmissionbt.com/\n" +"A fast and easy BitTorrent client\n" +"\n" +"Usage: "MY_NAME" [host] [options]\n" +" "MY_NAME" [port] [options]\n" +" "MY_NAME" [host:port] [options]\n" +"\n" +"Notes:\n" +" can be 'all', a single index, or a comma-separated list.\n" +" can be 'all', a torrent id or hash string, or a comma-separated list of ids and hash strings.\n" +"\n" +"Examples:\n" +" \""MY_NAME" -l\" (list all torrents)\n" +" \""MY_NAME" -tall --start\" (start all torrents)\n" +" \""MY_NAME" --add ~/Desktop/*torrent\" (add all the torrent files in $HOME/Desktop)\n" +" \""MY_NAME" -t1 -i\" (get detailed information on the torrent whose id is '1')\n" +" \""MY_NAME" -t1 -Gall -g2,4,6\" (same torrent; only download the second, fourth, and sixth files)\n" +" \""MY_NAME" -tall -ph1,2\" (set all torrent's first two files' priorities to high)\n" +" \""MY_NAME" -tall -pnall\" (set all torrent's files' priorities to normal)"; } static tr_option opts[] = { { 'a', "add", "Add torrent files", "a", 0, NULL }, + { 'b', "debug", "Print debugging information", "b", 0, NULL }, { 'd', "downlimit", "Set the maximum download speed in KB/s", "d", 1, "" }, { 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL }, { 'e', "encryption", "Set encryption mode [required, preferred, tolerated]", "e", 1, "" }, { 'f', "files", "Get a file list for the current torrent(s)", "f", 0, NULL }, - { 'g', "debug", "Print debugging information", "g", 0, NULL }, + { 'g', "get", "Mark files for download", "g", 1, "" }, + { 'G', "no-get", "Mark files for not downloading", "G", 1, "" }, { 'h', "help", "Show this help page and exit", "h", 0, NULL }, { 'i', "info", "Show details of the current torrent(s)", "i", 0, NULL }, { 'l', "list", "List all torrents", "l", 0, NULL }, @@ -59,10 +76,13 @@ static tr_option opts[] = { 'M', "no-portmap", "Disable portmapping", "M", 0, NULL }, { 'n', "auth", "Set username for authentication", "n", 1, ":" }, { 'p', "port", "Port to listen for incoming peers", "p", 1, "" }, + { 900, "priority-high", "Set one or more files' priority as high", "ph", 1, "" }, + { 901, "priority-normal", "Set one or more files' priority as normal", "pn", 1, "" }, + { 902, "priority-normal", "Set one or more files' priority as low", "pl", 1, "" }, { 'r', "remove", "Remove the current torrent(s)", "r", 0, NULL }, { 's', "start", "Start the current torrent(s)", "s", 0, NULL }, { 'S', "stop", "Stop the current torrent(s)", "S", 0, NULL }, - { 't', "torrent", "Set the current torrent(s)", "t", 1, "" }, + { 't', "torrent", "Set the current torrent(s)", "t", 1, "" }, { 'u', "uplimit", "Set the maximum upload speed in KB/s", "u", 1, "" }, { 'U', "no-uplimit", "Don't limit the upload speed", "U", 0, NULL }, { 'v', "verify", "Verify the current torrent(s)", "v", 0, NULL }, @@ -125,11 +145,40 @@ addIdArg( tr_benc * args, const char * id ) if( !*id ) { fprintf( stderr, "No torrent specified! Please use the -t option first.\n" ); id = "-1"; /* no torrent will have this ID, so should be a no-op */ - } else if( strcmp( id, "all" ) ) { + } + if( strcmp( id, "all" ) ) { tr_rpc_parse_list_str( tr_bencDictAdd( args, "ids" ), id, strlen(id) ); } } +static void +addFiles( tr_benc * args, const char * key, const char * arg ) +{ + tr_benc * files = tr_bencDictAddList( args, key, 100 ); + + if( !*arg ) + { + fprintf( stderr, "No files specified!\n" ); + arg = "-1"; /* no file will have this index, so should be a no-op */ + } + if( strcmp( arg, "all" ) ) + { + const char * walk = arg; + while( *walk ) { + char * p; + unsigned long l; + errno = 0; + l = strtol( walk, &p, 10 ); + if( errno ) + break; + tr_bencListAddInt( files, l - 1 ); + if( *p != ',' ) + break; + walk = p + 1; + } + } +} + static void readargs( int argc, const char ** argv ) { @@ -165,6 +214,9 @@ readargs( int argc, const char ** argv ) case 'a': addingTorrents = 1; addArg = FALSE; break; + case 'b': debug = 1; + addArg = FALSE; + 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 ); @@ -183,8 +235,13 @@ readargs( int argc, const char ** argv ) | TR_RPC_TORRENT_PRIORITIES; tr_bencDictAddInt( args, "fields", fields ); break; - case 'g': debug = 1; - addArg = FALSE; + case 'g': tr_bencDictAddStr( &top, "method", "torrent-set" ); + addIdArg( args, id ); + addFiles( args, "files-wanted", optarg ); + break; + case 'G': tr_bencDictAddStr( &top, "method", "torrent-set" ); + addIdArg( args, id ); + addFiles( args, "files-unwanted", optarg ); break; case 'i': tr_bencDictAddStr( &top, "method", "torrent-get" ); tr_bencDictAddInt( &top, "tag", TAG_DETAILS ); @@ -252,6 +309,18 @@ readargs( int argc, const char ** argv ) case 'X': tr_bencDictAddStr( &top, "method", "session-set" ); tr_bencDictAddInt( args, "pex-allowed", 0 ); break; + case 900: tr_bencDictAddStr( &top, "method", "torrent-set" ); + addIdArg( args, id ); + addFiles( args, "priority-high", optarg ); + break; + case 901: tr_bencDictAddStr( &top, "method", "torrent-set" ); + addIdArg( args, id ); + addFiles( args, "priority-normal", optarg ); + break; + case 902: tr_bencDictAddStr( &top, "method", "torrent-set" ); + addIdArg( args, id ); + addFiles( args, "priority-low", optarg ); + break; default: fprintf( stderr, "got opt [%d]\n", (int)c ); showUsage( ); break; diff --git a/daemon/transmission-remote.1 b/daemon/transmission-remote.1 index b573eb33f..fe02190a4 100644 --- a/daemon/transmission-remote.1 +++ b/daemon/transmission-remote.1 @@ -12,11 +12,13 @@ and .Nm .Op Ar host:port | host | port .Op Fl a Ar torrent-files +.Op Fl b .Op Fl d Ar number .Op Fl D .Op Fl e Ar mode .Op Fl f -.Op Fl g +.Op Fl g Ar files +.Op Fl G Ar files .Op Fl h .Op Fl i .Op Fl l @@ -24,6 +26,9 @@ and .Op Fl M .Op Fl n Ar user:pass .Op Fl p Ar port +.Op Fl ph Ar files +.Op Fl pl Ar files +.Op Fl pn Ar files .Op Fl r .Op Fl s .Op Fl S @@ -53,6 +58,9 @@ The options are as follows: Add metainfo .Ar torrent-file(s) . +.It Fl b Fl -debug +Enable debugging mode. + .It Fl d Fl -downlimit Ar limit Limit the download speed to .Ar limit @@ -71,6 +79,16 @@ Prefer unencrypted peer connections. .It Fl f Fl -files Get a file list for the current torrent(s) +.It Fl g Fl -get Ar files +Mark file(s) for download. +.Ar files +can be a file index, or a comma-separated list of file indices, or the literal +.Ar all +for all files in the torrent. + +.It Fl g Fl -no-get Ar files +Mark file(s) for not downloading + .It Fl h Fl -help Print command-line option descriptions. @@ -96,6 +114,25 @@ Set the .Ar port for use when listening for incoming peer connections +.It Fl ph Fl -priority-high Ar files +Mark +.Ar files +as high priority. +.Ar files +can be a file index, or a comma-separated list of file indices, or the literal +.Ar all +for all files in the torrent. + +.It Fl pl Fl -priority-low Ar files +Mark +.Ar files +as low priority + +.It Fl pn Fl -priority-normal Ar files +Mark +.Ar files +as normal priority + .It Fl r Fl -remove Remove the current torrent(s). This does not delete the downloaded data. @@ -135,28 +172,47 @@ Disable peer exchange (PEX). .El .Sh EXAMPLES -Show all torrents, their ID numbers, and their status: + +List all torrents: .Pp -.Dl transmission-remote -l +.Dl $ transmission-remote -l .Pp -Pause torrent #12: + +Start all torrents: .Pp -.Dl transmission-remote -t 12 -S -.Dl transmission-remote --torrent=12 --stop +.Dl $ transmission-remote -tall --start .Pp -Start all torrents: + +Get detailed information on the torrent whose ID is '1': .Pp -.Dl transmission-remote -t all -s -.Dl transmission-remote --torrent=all --start +.Dl $ transmission-remote -t1 -i .Pp + +Only download the second, fourth, and sixth files of the torrent whose ID is '1': +.Pp +.Dl $ transmission-remote -t1 -Gall -g2,4,6 +.Pp + +Set all torrents' first two files' priorities to high: +.Pp +.Dl $ transmission-remote -t1 -ph1,2 +.Pp + +Set all torrents' files' priorities to normal: +.Pp +.Dl $ transmission-remote -tall -pnall +.Pp + Set download and upload limits to 100 KiB/sec and 20 KiB/sec: .Pp -.Dl transmission-remote -d 100 -u 20 -.Dl transmission-remote -d=100 -u=20 +.Dl $ transmission-remote -d 100 -u 20 +.Dl $ transmission-remote -d=100 -u=20 .Pp + Add two torrents: .Pp -.Dl transmission-remote -a one.torrent two.torrent +.Dl $ transmission-remote -a one.torrent two.torrent +.Pp .Sh AUTHORS .An -nosplit diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index 38390a4bc..9bafef9d6 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -979,7 +979,7 @@ networkPage( GObject * core ) t = hig_workarea_create( ); hig_workarea_add_section_title (t, &row, _( "Router" ) ); - s = _("Use port _forwarding from my router" ); + s = _("Use UPnP or NAT-PMP port _forwarding from my router" ); w = new_check_button( s, PREF_KEY_PORT_FORWARDING, core ); hig_workarea_add_wide_control( t, &row, w ); diff --git a/libtransmission/rpc.c b/libtransmission/rpc.c index 2ded11266..3022533f0 100644 --- a/libtransmission/rpc.c +++ b/libtransmission/rpc.c @@ -338,11 +338,21 @@ setFilePriorities( tr_torrent * tor, int priority, tr_benc * list ) int64_t tmp; int fileCount = 0; const int n = tr_bencListSize( list ); - tr_file_index_t * files = tr_new0( tr_file_index_t, n ); + tr_file_index_t * files = tr_new0( tr_file_index_t, tor->info.fileCount ); - for( i=0; iinfo.fileCount ) + files[fileCount++] = tmp; + } + else // if empty set, apply to all + { + tr_file_index_t t; + for( t=0; tinfo.fileCount; ++t ) + files[fileCount++] = t; + } if( fileCount ) tr_torrentSetFilePriorities( tor, files, fileCount, priority ); @@ -357,11 +367,21 @@ setFileDLs( tr_torrent * tor, int do_download, tr_benc * list ) int64_t tmp; int fileCount = 0; const int n = tr_bencListSize( list ); - tr_file_index_t * files = tr_new0( tr_file_index_t, n ); + tr_file_index_t * files = tr_new0( tr_file_index_t, tor->info.fileCount ); - for( i=0; iinfo.fileCount ) + files[fileCount++] = tmp; + } + else // if empty set, apply to all + { + tr_file_index_t t; + for( t=0; tinfo.fileCount; ++t ) + files[fileCount++] = t; + } if( fileCount ) tr_torrentSetFileDLs( tor, files, fileCount, do_download ); diff --git a/libtransmission/tr-getopt.c b/libtransmission/tr-getopt.c index 2077134f4..eddccf9e6 100644 --- a/libtransmission/tr-getopt.c +++ b/libtransmission/tr-getopt.c @@ -56,7 +56,7 @@ getopts_usage_line( const tr_option * opt, const char * longName = opt->longName ? opt->longName : ""; const char * shortName = opt->shortName ? opt->shortName : ""; const char * arg = getArgName( opt ); - printf( " -%*s, --%-*s %-*s %s\n", shortWidth, shortName, + printf( " -%-*s --%-*s %-*s %s\n", shortWidth, shortName, longWidth, longName, argWidth, arg, opt->description ); -- 2.40.0