Reputation: 1
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: \n");
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
Upvotes: 0
Views: 303
Reputation: 11245
This is most likely because the last piece of the file you want to download overlaps with the next file. In order to verify the hash of that piece, the whole piece needs to be downloaded. The part of the piece that falls outside of the file you've selected to download, will still need to be saved somewhere.
In older versions of libtorrent, all pieces would be saved in their correct location, whether you wanted the corresponding file or not.
Newer versions of libtorrent (1.1.0 and later) use partfiles by default, to save these "parts" together in a separate file.
Upvotes: 0