I'm using the following code to create a new torret and share but something is wrong because never seed.
import sys
import time
import libtorrent as lt
#Create torrent
fs = lt.file_storage()
lt.add_files(fs, "./test.txt")
t = lt.create_torrent(fs)
t.add_tracker("udp://tracker.openbittorrent.com:80/announce", 0)
t.set_creator('libtorrent %s' % lt.version)
t.set_comment("Test")
lt.set_piece_hashes(t, ".")
torrent = t.generate()
f = open("mytorrent.torrent", "wb")
f.write(lt.bencode(torrent))
f.close()
#Seed torrent
ses = lt.session()
ses.listen_on(6881, 6891)
h = ses.add_torrent({'ti': lt.torrent_info('mytorrent.torrent'), 'save_path': '.', 'seed_mode': True})
print "Total size: " + str(h.status().total_wanted)
print "Name: " + h.name()
while True:
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 peers: %d) %s' % \
(s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state]))
sys.stdout.flush()
time.sleep(1)
Test in order:
100.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) seeding (8 times)
100.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 1) seeding (11 times)(This happens always, even if not run the torrent client.)
100.00% complete (down: 0.0 kb/s up: 0.0 kB/s peers: 0) seeding (infinite times)
Variations in the test with the same results:
I tried to use different trackers:
trackerList = ['udp://tracker.istole.it:80/announce',
'udp://tracker.ccc.de:80/announce',
'http://tracker.torrentbay.to:6969/announce',
'udp://fr33domtracker.h33t.com:3310/announce',
'udp://tracker.publicbt.com:80/announce',
'udp://tracker.openbittorrent.com:80/announce',
'udp://11.rarbg.com/announce'
'udp://tracker.istole.it:80/announce']
for tracker in trackerList:
t.add_tracker(tracker, 0)
I have run the torrent file in client immediately after executing the script and also later.
Additional Information:
Other tests:
In the computer I used to share, I tried to share a torrent created by someone else. I have run the code marked with "#Seed torrent" it worked:
100.00% complete (down: 2.0 kb/s up: 45.0 kB/s peers: 13) seeding
In the computer that I use to download the torrent I downloaded a torrent (with libtorrent) already created by someone else, and it worked correctly.
Therefore I can only think that there is a problem in "#create torrent" piece of code. As if the tracker will not save the information set.
The problem has been solved using different trackers instead of listed in "trackerList". The code is correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With