ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: Anonan on June 22, 2019, 11:22:28 PM

Title: Show the count of a torrent's pieces
Post by: Anonan on June 22, 2019, 11:22:28 PM
I have found that torrent files contain the information about pieces' count.
It's strange that I don't see the mention about it here https://wiki.theory.org/index.php/BitTorrentSpecification
But each torrent file that I have checked by Notepad++ has that value multiplied by 20.

Examples from random torrents:
"...12:piece lengthi8388608e6:pieces16080:삅纡ΓoEry5..." -> 804 pieces
"...12:piece lengthi4194304e6:pieces276660:Dr֙ՋჽyΪN..." -> 13833 pieces
"...12:piece lengthi2097152e6:pieces233940:ߴ͝ۉPd؋/ݰꬅԒ..." -> 11697 pieces
Title: Re: Show the count of a torrent's pieces
Post by: Anonan on June 22, 2019, 11:28:23 PM
I also have found the bug, Exiftool throws the error if a torrent file does not have an announce field.


$ exiftool error.torrent

ExifTool Version Number         : 11.52
File Name                       : error.torrent
Directory                       : .
File Size                       : 655 bytes
File Modification Date/Time     : 2019:06:23 06:18:32+00:00
File Access Date/Time           : 2019:06:23 06:18:03+00:00
File Creation Date/Time         : 2019:06:23 06:18:03+00:00
File Permissions                : rw-rw-rw-
Error                           : File format error


$ exiftool ok.torrent
ExifTool Version Number         : 11.52
File Name                       : ok.torrent
Directory                       : .
File Size                       : 687 bytes
File Modification Date/Time     : 2019:06:23 06:21:02+00:00
File Access Date/Time           : 2019:06:23 06:19:44+00:00
File Creation Date/Time         : 2019:06:23 06:19:43+00:00
File Permissions                : rw-rw-rw-
File Type                       : Torrent
File Type Extension             : torrent
MIME Type                       : application/x-bittorrent
Announce                        : HERE_IS_THE_ADDRESS
Creator                         : qBittorrent v4.1.6
Create Date                     : 2019:06:23 06:21:02+00:00
File 1 Length                   : 254 kB
File 1 Path                     : 2.jpg
File 2 Length                   : 88 kB
File 2 Path                     : 1.jpg
Name                            : torrent folder
Piece Length                    : 16384
Pieces                          : (Binary data 440 bytes, use -b option to extract)
Private                         : 1

Title: Re: Show the count of a torrent's pieces
Post by: Anonan on June 23, 2019, 04:10:56 PM
The question: can ExifTool create computer-friendly json?
Where is files is an array and a path (of a file) is an arrays of folders name + file name.

A lot of other bencode viewers makes json in this way.
For example: https://chocobo1.github.io/bencode_online/
https://en.wikipedia.org/wiki/Torrent_file#Examples


Exiftool:

$ exiftool -j -n -g1 1.torrent > o.json
...
    "Height": 2160,
    "File1Length": 123456,
    "File1Path": "folder1/folder1.1/file1.mp4",
    "File2Length": 234567,
    "File2Path": "folder1/folder1.2/file2.mp4",
...


Other programs:

   "height": 2160,
   "info": {
      "files": [
         {
            "length": 123456,
            "path": [
               "folder1",
               "folder1.1",
               "file1.mp4"
            ]
         },
         {
            "length": 234567,
            "path": [
               "folder1",
               "folder1.2",
               "file12.mp4"
            ]
         },

The properties names are different too. It looks more simply.


The question is actual for usual files too, when you use -recurse -json you get "SourceFile": "folder/subfolder/file.jpg"


Title: Re: Show the count of a torrent's pieces
Post by: Anonan on June 24, 2019, 01:18:15 AM
In addition to the count of pieces of a torrent file you can get (calculate) a torrent hash (info hash).
Here's how:
https://stackoverflow.com/questions/19749085/calculating-the-info-hash-of-a-torrent-file/19800109#19800109
I have easily reproduced it with Notepad++ and https://md5file.com/calculator
A torrent hash allows you to get the torrent from DHT / create a magnet link from it (magnet:?xt=urn:btih:HERE_IS_THE_HASH).
Title: Re: Show the count of a torrent's pieces
Post by: Phil Harvey on June 24, 2019, 09:55:14 AM
I'll fix the error if "announce" doesn't exist, thanks.

ExifTool 11.53 will enhance the -struct option to give this output:

> exiftool -j -struct tmp/error.torrent --system:all
[{
  "SourceFile": "tmp/error.torrent",
  "ExifToolVersion": 11.53,
  "FileType": "Torrent",
  "FileTypeExtension": "torrent",
  "MIMEType": "application/x-bittorrent",
  "Creator": "qBittorrent v4.1.6",
  "CreateDate": "2019:06:22 23:18:32-04:00",
  "Info": {
    "files": [{
      "length": 260451,
      "path": ["2.jpg"]
    },{
      "length": 90443,
      "path": ["1.jpg"]
    }],
    "name": "torrent folder",
    "piece length": 16384,
    "pieces": "(Binary data 440 bytes, use -b option to extract)",
    "private": 1
  },
  "BaseName": "error",
  "FileExtension": "torrent",
  "FileTypeDescription": "BitTorrent description file"
}]


I hope this is what you wanted.

- Phil