Loading a magnet torrent with Python and Libtorrent

642 Views Asked by At

I'm trying to download a torrent with a magnet link. The magnet link works as I've tried it on a few clients but this code gets stuck on "0% done" and loops without downloading. Does anyone know why?

enter image description here

import libtorrent as lt
import time

ses = lt.session()
params = { 'save_path': '/downloads/'}
link = "magnet:?xt=urn:btih:bee75372b98077bfd4de8ef03eb33e9289be5cd8&dn=Avengers+Infinity+War+2018+NEW+PROPER+720p+HD-CAM+X264+HQ-CPG&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969"
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)
1

There are 1 best solutions below

0
Arvid On

There are many reasons torrents may fail to download.

A few examples:

  • There are no seeds on the swarm
  • There is much higher demand than supply, and you haven't been unchoked yet
  • your disk is full or have some other permission issues

You can find a troubleshooting chart on libtorrent.org, which covers some common symptoms and hints about what metrics to look at.

It's created from a simple dot file, so feel free to submit pull requests with improvements if your problem isn't covered.