w00t-labs / libtorrent

Automatically exported from code.google.com/p/libtorrent
Other
0 stars 0 forks source link

Get hash for each file inside a torrent !? #626

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello, I'm trying to match some files with the files inside a torrent, but 
comparing just the file size isn't enough since there are many files that have 
the exact same file size but different content :(

So is there a way to get the hash for each file inside a torrent file !?

I've found here 
http://stackoverflow.com/questions/2572521/extract-the-sha1-hash-from-a-torrent-
file how to verify the files, but that's not what I want... I want is to get 
the hash for every file inside the torrent and compare it with other random 
files...

    # get files from torrent
    torrentFiles = []
    tPath = '123.torrent'
    t = lt.bdecode(open(tPath, 'rb').read())
    info = lt.torrent_info(t)
    for x in info.files():
        torrentFiles.append([x.path, x.size, x.hash!? ])

Original issue reported on code.google.com by Rappy...@gmail.com on 22 May 2014 at 1:07

GoogleCodeExporter commented 9 years ago
I can see two approaches:

1. Download the files in the torrent, then calculate the hashes of those files.

2. Don't calculate the hashes of files, but instead calculate the piece hashes 
of the files you want to compare with, and compare those piece hashes with the 
piece hashes in the .torrent file. Make sure to make sure you get the piece 
alignment right, since pieces are not necessarily aligned to file boundaries.

Original comment by arvid.no...@gmail.com on 23 May 2014 at 4:31

GoogleCodeExporter commented 9 years ago
btw. this doesn't seem like a bug report or feature request for libtorrent.

Original comment by arvid.no...@gmail.com on 23 May 2014 at 4:31