我想从大型torrent下载特定于torrent的文件我已经编写了这段代码,但它在colab中显示了1个文件的下载状态,但在执行结束后驱动器中有两个文件,例如,它在图片中说第七季第三集已下载,但驱动器中还有第二集。可以吗有人告诉我为什么会这样吗
//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])
这很可能是因为您要下载的文件的最后一部分与下一个文件重叠。为了验证该片段的散列,需要下载整个片段。您选择下载的文件之外的部分仍然需要保存在的某个位置
在旧版本的libtorrent中,无论您是否需要相应的文件,所有片段都将保存在正确的位置
libtorrent的较新版本(1.1.0及更高版本)默认情况下使用partfiles,将这些“部分”保存在单独的文件中
相关问题 更多 >
编程相关推荐