微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么这显示 1 个文件下载但在 LibTorrent 中保存了 2 个文件

如何解决为什么这显示 1 个文件下载但在 LibTorrent 中保存了 2 个文件

我想从大 torrent 下载 torrent 特定文件我已经编写了这段代码,但它显示了 colab 中 1 个文件的下载状态,但执行结束后驱动器中有两个文件,例如它说图片显示第 7 季第 3 集已下载,但驱动器中还有第二集。谁能告诉我为什么会这样。

    //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,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

解决方法

这很可能是因为您要下载的文件的最后一部分与下一个文件重叠。为了验证该片段的哈希值,需要下载整个片段。超出您选择下载的文件的部分仍需要保存在某处

在旧版本的 libtorrent 中,无论您是否需要相应的文件,所有片段都将保存在正确的位置。

较新版本的 libtorrent(1.1.0 及更高版本)默认使用部分文件,将这些“部分”一起保存在一个单独的文件中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。