Skip to content

Instantly share code, notes, and snippets.

@samukasmk
Created December 22, 2017 13:44
Show Gist options
  • Save samukasmk/611ba2cc61362aa3428b3317ad81d9af to your computer and use it in GitHub Desktop.
Save samukasmk/611ba2cc61362aa3428b3317ad81d9af to your computer and use it in GitHub Desktop.
Script of example to download files by torrent in Python (By: torrent file)
# source:
# http://www.libtorrent.org/python_binding.html
#
# 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 time
import sys
import libtorrent as lt
ses = lt.session()
ses.listen_on(6881, 6891)
e = lt.bdecode(open(sys.argv[1], 'rb').read())
info = lt.torrent_info(e)
params = { 'save_path': '.', \
'storage_mode': lt.storage_mode_t.storage_mode_sparse, \
'ti': info }
h = ses.add_torrent(params)
s = h.status()
while (not s.is_seeding):
s = h.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(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment