I want to download torrent specific files from large torrent I have written this code but it is showing the download status of 1 file in the colab but there are two files in the drive after the execution ends for example it is saying as in pictures that season 7 episode 3 is downloaded but in the drive there is also the second episode.Can anyone tell me why is this happening.
//Uploading Torrent File
from google.colab import files
uploaded = files.upload()
//creating Libtorrent instance
import libtorrent as lt
import time
ses = lt.session()
ses.listen_on(6881, 6891)
e = lt.bdecode(open("20_gg.torrent", 'rb').read())
info = lt.torrent_info(e)
//Printing Number of files so that user select the files he/she wants to Download
fileStr=''
FilesIndexToDownload=[]
FilesStringToDownload=[]
i=0
for f in info.files():
fileStr=f
print(i,":",fileStr.path)
i=i+1
//Saving Number of files User wants to Download
print("Enter the No of files you want");
numb=0
numb=input(numb)
numb=int(numb)
//Saving File Index and File String
for j in range(0,numb):
print("Enter the Index of ",j," File:
");
num=input()
num=int(num)
FilesIndexToDownload.append(num)
for j in FilesIndexToDownload:
i=0
for f in info.files():
if i == j:
fileStr = f
FilesStringToDownload.append(fileStr)
i += 1
def SelectiveDownload(fileIndex,fileStr):
print(fileStr.path)
h = ses.add_torrent(info, "/content/drive/MyDrive/SingleFileCheck/")
pr = info.map_file(fileIndex,0,fileStr.size)
n_pieces = pr.length / info.piece_length() + 1
for i in range(info.num_pieces()):
if i in range(int(pr.piece),int(pr.piece+n_pieces)):
h.piece_priority(i,7)
else:
h.piece_priority(i,0)
while (not h.is_seed()):
s = h.status()
state_str = ['queued', 'checking', 'downloading metadata',
'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']
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]))
if s.progress>=1:
break
time.sleep(1)
//Starting Download
for i in range(0,numb):
SelectiveDownload(FilesIndexToDownload[i],FilesStringToDownload[i])
starting Download
Download End
Drive Files
question from:
https://stackoverflow.com/questions/65898077/why-this-is-showing-1-file-download-but-saving-2-files-in-libtorrent 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…