7

How would one load a Magnet link via rasterbar libtorrent python binding?

Max
  • 4,152
  • 4
  • 36
  • 52

1 Answers1

18
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)
Arvid
  • 10,915
  • 1
  • 32
  • 40
  • This seems to be broken. If I use this and print `handle.status().download_rate` and `handle.status().num_peers` I can see that initially it is downloading but later on its losing peers and download rate is flattening. This also pertains [this](https://gist.github.com/samukasmk/940ca5d5abd9019e8b1af77c819e4ca9) and [this](https://stackoverflow.com/questions/33694605/simple-libtorrent-python-client) variation. Is there something that has to be done so that peers don't disconnect? – Felix Jan 22 '20 at 11:46