A rather small bittorrent client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
907B

  1. #!/usr/bin/env python3
  2. import libtorrent as lt
  3. import time
  4. import sys
  5. ses = lt.session()
  6. ses.listen_on(6881, 6891)
  7. save_path = None
  8. info = None
  9. try:
  10. info = lt.torrent_info(sys.argv[1])
  11. except IndexError:
  12. print("You need to specify a torrent file.")
  13. exit(0)
  14. try:
  15. save_path = sys.argv[2];
  16. except IndexError:
  17. print("No directory specified, defaulting to the current directory.")
  18. save_path = "./"
  19. h = ses.add_torrent({'ti': info, 'save_path': save_path})
  20. print ('starting', h.name())
  21. while (not h.is_seed()):
  22. s = h.status()
  23. state_str = ['queued', 'checking', 'downloading metadata', \
  24. 'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']
  25. print ('\r%.2f%% complete (down: %.1f kb/s up: %.1f kB/s)' % (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000))
  26. sys.stdout.write('\r')
  27. time.sleep(1)
  28. print (h.name(), 'complete')
  29. exit(0)