Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

python - Why this is showing 1 File Download but saving 2 files in LibTorrent

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...