This commit is contained in:
mirro-chan 2019-01-31 17:16:21 +01:00 committed by GitHub
parent 3132d00b0c
commit 0122b4a8c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

34
trrt.py Normal file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
import libtorrent as lt
import time
import sys
ses = lt.session()
ses.listen_on(6881, 6891)
save_path = None
info = None
try:
info = lt.torrent_info(sys.argv[1])
except IndexError:
print("You need to specify a torrent file.")
exit(0)
try:
save_path = sys.argv[2];
except IndexError:
print("No directory specified, defaulting to the current directory.")
save_path = "./"
h = ses.add_torrent({'ti': info, 'save_path': save_path})
print ('starting', h.name())
while (not h.is_seed()):
s = h.status()
state_str = ['queued', 'checking', 'downloading metadata', \
'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']
print ('\r%.2f%% complete (down: %.1f kb/s up: %.1f kB/s)' % (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000))
sys.stdout.write('\r')
time.sleep(1)
print (h.name(), 'complete')
exit(0)