pythonlibtorrentlibtorrent-rasterbar

How to remove completed torrent using libtorrent rasterbar python binding?


I have a python script that downloads files using libtorrent python binding. I just want to know how to remove the torrent once the download is complete.

I'm posting here the example script I used to make mine (I'm not posting mine because it's too large, it has database parts).

import libtorrent as lt
import time

ses = lt.session()
params = { 'save_path': '/home/downloads/'}
link = "magnet:?xt=urn:btih:4MR6HU7SIHXAXQQFXFJTNLTYSREDR5EI&tr=http://tracker.vodo.net:6970/announce"
handle = lt.add_magnet_uri(ses, link, params)

print 'downloading metadata...'
while (not handle.has_metadata()): time.sleep(1)
print 'got metadata, starting torrent download...'
while (handle.status().state != lt.torrent_status.seeding):
    print '%d %% done' % (handle.status().progress*100)
    time.sleep(1)

Thanks.


Solution

  • you call remove_torrent() on the session object, passing in the torrent_handle to remove.

    http://libtorrent.org/reference-Core.html#remove_torrent()

    In your script:

    ses.remove_torrent(handle)