• PYTHON > télécharger un torrent

      libtorrent

      import libtorrent as lt
      import time
      ses = lt.session()
      ses.listen_on(6881, 6891)
      params = {
          'save_path': '/home/downloads/',
          'storage_mode': lt.storage_mode_t(2),
          'paused': False,
          'auto_managed': True,
          'duplicate_is_error': True}
      link = "magnet:?xt=urn:btih:4MR6HU7SIHXAXQQFXFJTNLTYSREDR5EI&tr=http://tracker.vodo.net:6970/announce"
      handle = lt.add_magnet_uri(ses, link, params)
      ses.start_dht()
      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):
      s = handle.status()
      state_str = ['queued', 'checking', 'downloading metadata', \
      'downloading', 'finished', 'seeding', 'allocating']
      print '%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s %.3' % \
      (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
      s.num_peers, state_str[s.state], s.total_download/1000000)
      time.sleep(5)

       

      Qui semble bien fonctionner, mais puis ralentit à moins d’un octet/s:Il ralentit et ne se termine jamais. Une idée de pourquoi cela se produit?

      Le save_path n’existe pas, donc la libtorrent bibliothèque téléchargé aussi longtemps qu’il n’avait pas à vider le cache, mais une fois qu’il a tenté d’écrire le fichier, il n’a pas et ne pouvait pas continuer à télécharger, donc le ralentissement et de l’éventuel arrêt. Une fois qu’un chemin d’accès existant a été ajouté ça a bien fonctionné.


      Script of example to download files by torrent in Python (By: magnet url) # https://stackoverflow.com/questions/6051877/loading-magnet-link-using-rasterbar-libtorrent-in-python

       

      #
      # ATTENTION: This is only a example of to use a python bind of torrent library in Python for educational purposes.
      #            I am not responsible for your download of illegal content or without permission.
      #            Please respect the laws license permits of your country.
      import libtorrent as lt
      import time
      ses = lt.session()
      ses.listen_on(6881, 6891)
      params = {
      'save_path': '/home/user/Downloads/torrent',
      'storage_mode': lt.storage_mode_t(2),
      'paused': False,
      'auto_managed': True,
      'duplicate_is_error': True}
      link = "MAGNET_LINK_HERE"
      handle = lt.add_magnet_uri(ses, link, params)
      ses.start_dht()
      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):
      s = handle.status()
      state_str = ['queued', 'checking', 'downloading metadata', \
      'downloading', 'finished', 'seeding', 'allocating']
      print '%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \
      (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
      s.num_peers, state_str[s.state])
      time.sleep(5)

 

Aucun commentaire

 

Laissez un commentaire