Changeset 13397


Ignore:
Timestamp:
Jul 23, 2012, 3:28:27 PM (9 years ago)
Author:
jordan
Message:

(trunk utils) #4979 "add manget link generator to transmission-show" -- done.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent-magnet.c

    r12589 r13397  
    370370
    371371char*
    372 tr_torrentGetMagnetLink( const tr_torrent * tor )
     372tr_torrentInfoGetMagnetLink( const tr_info * inf )
    373373{
    374374    int i;
    375375    const char * name;
    376     struct evbuffer * s;
    377 
    378     assert( tr_isTorrent( tor ) );
    379 
    380     s = evbuffer_new( );
    381     evbuffer_add_printf( s, "magnet:?xt=urn:btih:%s", tor->info.hashString );
    382     name = tr_torrentName( tor );
     376    struct evbuffer * s = evbuffer_new( );
     377
     378    evbuffer_add_printf( s, "magnet:?xt=urn:btih:%s", inf->hashString );
     379
     380    name = inf->name;
    383381    if( name && *name )
    384382    {
    385383        evbuffer_add_printf( s, "%s", "&dn=" );
    386         tr_http_escape( s, tr_torrentName( tor ), -1, true );
    387     }
    388     for( i=0; i<tor->info.trackerCount; ++i )
     384        tr_http_escape( s, name, -1, true );
     385    }
     386
     387    for( i=0; i<inf->trackerCount; ++i )
    389388    {
    390389        evbuffer_add_printf( s, "%s", "&tr=" );
    391         tr_http_escape( s, tor->info.trackers[i].announce, -1, true );
     390        tr_http_escape( s, inf->trackers[i].announce, -1, true );
    392391    }
    393392
  • trunk/libtransmission/transmission.h

    r13361 r13397  
    13631363
    13641364
     1365char* tr_torrentInfoGetMagnetLink( const tr_info * inf );
     1366
    13651367/**
    13661368 * Returns a newly-allocated string with a magnet link of the torrent.
    13671369 * Use tr_free() to free the string when done.
    13681370 */
    1369 char* tr_torrentGetMagnetLink( const tr_torrent * tor );
     1371static inline
     1372char* tr_torrentGetMagnetLink( const tr_torrent * tor )
     1373{
     1374    return tr_torrentInfoGetMagnetLink( tr_torrentInfo( tor ) );
     1375}
    13701376
    13711377/**
  • trunk/utils/show.c

    r13195 r13397  
    5353static tr_option options[] =
    5454{
     55  { 'm', "magnet", "Give a magnet link for the specified torrent", "m", 0, NULL },
    5556  { 's', "scrape", "Ask the torrent's trackers how many peers are in the torrent's swarm", "s", 0, NULL },
    5657  { 'V', "version", "Show version number and exit", "V", 0, NULL },
     
    6465}
    6566
     67static bool magnetFlag = false;
    6668static bool scrapeFlag = false;
    6769static bool showVersion = false;
     
    7880        switch( c )
    7981        {
     82            case 'm': magnetFlag = true; break;
    8083            case 's': scrapeFlag = true; break;
    8184            case 'V': showVersion = true; break;
     
    8689
    8790    return 0;
     91}
     92
     93static void
     94doShowMagnet( const tr_info * inf )
     95{
     96    char * str = tr_torrentInfoGetMagnetLink( inf );
     97    printf( "%s", str );
     98    tr_free( str );
    8899}
    89100
     
    319330    }
    320331
    321     printf( "Name: %s\n", inf.name );
    322     printf( "File: %s\n", filename );
    323     printf( "\n" );
    324     fflush( stdout );
    325 
    326     if( scrapeFlag )
    327         doScrape( &inf );
     332    if( magnetFlag )
     333    {
     334        doShowMagnet( &inf );
     335    }
    328336    else
    329         showInfo( &inf );
     337    {
     338        printf( "Name: %s\n", inf.name );
     339        printf( "File: %s\n", filename );
     340        printf( "\n" );
     341        fflush( stdout );
     342
     343        if( scrapeFlag )
     344            doScrape( &inf );
     345        else
     346            showInfo( &inf );
     347    }
    330348
    331349    /* cleanup */
  • trunk/utils/transmission-show.1

    r11626 r13397  
    99.Nm
    1010.Op Fl h
     11.Op Fl m
    1112.Op Fl s
    1213.Op Ar torrentfile
     
    1920.It Fl h Fl -help
    2021Show a short help page and exit.
     22.It Fl m Fl -magnet
     23Show a magnet link for the specified .torrent file
    2124.It Fl s Fl -scrape
    2225Ask the torrent's trackers how many peers are in the torrent's swarm
Note: See TracChangeset for help on using the changeset viewer.