Hello world

Example 1: Default configuration

s = Session()


d = s.start_download(tdef)

Session Tribler session instance
TorrentDef Definition class containing a torrent
d = class Download download in progress

This piece of code first starts a Tribler session and loads a torrent file. The third line starts downloading the file and returns a Download object, which can be used to monitor the progress.

Example 2: Override the destination

s = Session()

tdef= TorrentDef.load('HelloWorld.torrent')

dscfg = DownloadStartupConfig()


d = s.start_download(tdef,dscfg)

api:Tribler.Core.DownloadConfig.DownloadStartupConfig class which contains download parameters

A api:Tribler.Core.DownloadConfig.DownloadStartupConfig object can be used to override the default behavior. In this case the destination directory is overridden to /tmp.

Example 3. Status monitoring

s = Session()

tdef= TorrentDef.load('HelloWorld.torrent')

d = s.start_download(tdef)



def state_callback(ds):

    print ds.get_status()

    print ds.get_progress() 

    return (5.0,False)

This code example defines a callback function state_callback which can do magic in your GUI to display the download status. It returns a list a list of two parameters. The first one is the time in seconds before the next callback should happen. The second one tells the core whether or not to retrieve the details of all connected peers and place them in the download state for the next callback.