Torf-cli is a command line tool that can create and read torrent files.

Published on Aug. 22, 2023, 12:12 p.m.

Torf-cli is a command line tool that can create and read torrent files.

The output is pleasant to read for humans or easy to parse .

The only dependencies are pyxdg.

Installation

pipx

The easiest and cleanest installation method is pipx, which installs each application with all dependencies in a separate virtual environment in /.local/venvs/.

$ pipx install torf-cli
$ pipx upgrade torf-cli
$ pipx uninstall torf-cli  # Also removes dependencies

pip

The alternative is regular pip, but if you decide to uninstall, you have .

$ pip3 install torf-cli         # Installs system-wide (/usr/local/)
$ pip3 install --user torf-cli  # Installs in your home (~/.local/)
$ pip3 install [--user] git+https://github.com/rndusr/torf-cli.git

Examples

To create a private torrent with two trackers and a specific creation date :

$ torf ./docs -t http://bar:123/announce -t http://baz:321/announce \
              --private --date '2020-03-31 21:23:42'
       Name  docs
       Size  74.43 KiB
    Created  2020-03-31 21:23:42
 Created By  torf 3.1.0
    Private  yes
   Trackers  http://bar:123/announce
             http://baz:321/announce
 Piece Size  16 KiB
Piece Count  5
 File Count  3
      Files  docs
             ├─torf.1 [14.53 KiB]
             ├─torf.1.asciidoc [10.56 KiB]
             └─torf.1.html [49.34 KiB]
   Progress  100.00 % | 0:00:00 total | 72.69 MiB/s
  Info Hash  0a9dfcf07feb2a82da11b509e8929266d8510a02
     Magnet  magnet:?xt=urn:btih:0a9dfcf07feb2a82da11b509e8929266d8510a02&dn=docs&xl=76217&tr=http%3A%2F%2Fbar%3A123%2Fannounce&tr=http%3A%2F%2Fbaz%3A321%2Fannounce
    Torrent  docs.torrent

display information about it:

$ torf -i docs.torrent
       Name  docs
  Info Hash  0a9dfcf07feb2a82da11b509e8929266d8510a02
       Size  74.43 KiB
    Created  2020-03-31 21:23:42
 Created By  torf 3.1.0
    Private  yes
   Trackers  http://bar:123/announce
             http://baz:321/announce
 Piece Size  16 KiB
Piece Count  5
 File Count  3
      Files  docs
             ├─torf.1 [14.53 KiB]
             ├─torf.1.asciidoc [10.56 KiB]
             └─torf.1.html [49.34 KiB]
     Magnet  magnet:?xt=urn:btih:0a9dfcf07feb2a82da11b509e8929266d8510a02&dn=docs&xl=76217&tr=http%3A%2F%2Fbar%3A123%2Fannounce&tr=http%3A%2F%2Fbaz%3A321%2Fannounce

Quickly add a comment to an existing torrent.

$ torf -i docs.torrent --comment 'Forgot to add this comment.' -o docs.revised.torrent
       Name  docs
  Info Hash  0a9dfcf07feb2a82da11b509e8929266d8510a02
       Size  74.43 KiB
    Comment  Forgot to add this comment.
    Created  2020-03-31 21:23:42
 Created By  torf 3.1.0
    Private  yes
   Trackers  http://bar:123/announce
             http://baz:321/announce
 Piece Size  16 KiB
Piece Count  5
 File Count  3
      Files  docs
             ├─torf.1 [14.53 KiB]
             ├─torf.1.asciidoc [10.56 KiB]
             └─torf.1.html [49.34 KiB]
     Magnet  magnet:?xt=urn:btih:0a9dfcf07feb2a82da11b509e8929266d8510a02&dn=docs&xl=76217&tr=http%3A%2F%2Fbar%3A123%2Fannounce&tr=http%3A%2F%2Fbaz%3A321%2Fannounce
    Torrent  docs.revised.torrent

Verify the files in the doc:

$ <edit torf.1.html>
$ torf -i docs.revised.torrent docs
       Name  docs
  Info Hash  0a9dfcf07feb2a82da11b509e8929266d8510a02
       Size  74.43 KiB
    Comment  Forgot to add this comment.
    Created  2020-03-31 21:23:42
 Created By  torf 3.1.0
    Private  yes
   Trackers  http://bar:123/announce
             http://baz:321/announce
 Piece Size  16 KiB
Piece Count  5
 File Count  3
      Files  docs
             ├─torf.1 [14.53 KiB]
             ├─torf.1.asciidoc [10.56 KiB]
             └─torf.1.html [49.34 KiB]
       Path  docs
  Info Hash  0a9dfcf07feb2a82da11b509e8929266d8510a02
      Error  docs/torf.1.html: Too big: 50523 instead of 50522 bytes
      Error  Corruption in piece 2, at least one of these files is corrupt:
               docs/torf.1.asciidoc
               docs/torf.1.html
   Progress  100.00 % | 0:00:00 total | 72.69 MiB/s
torf: docs does not satisfy docs.revised.torrent

Get a list of files via grep and cut:

$ torf -i docs.revised.torrent | grep '^Files' | cut -f2-
docs/torf.1     docs/torf.1.asciidoc    docs/torf.1.html
# Files are delimited by a horizontal tab (``\t``)

Get a list of files via jq:

$ torf -i docs.revised.torrent --json | jq .Files
[  "docs/torf.1",  "docs/torf.1.asciidoc",  "docs/torf.1.html"]

Get metainfo as JSON:

$ torf -i docs.revised.torrent -m
{
    "announce": "http://bar:123/announce",
    "announce-list": [
        [
            "http://bar:123/announce"
        ],
        [
            "http://baz:321/announce"
        ]
    ],
    "comment": "Forgot to add this comment.",
    "created by": "torf 3.1.0",
    "creation date": 1585682622,
    "info": {
        "name": "docs",
        "piece length": 16384,
        "private": 1,
        "files": [
            {
                "length": 14877,
                "path": [
                    "torf.1"
                ]
            },
            {
                "length": 10818,
                "path": [
                    "torf.1.asciidoc"
                ]
            },
            {
                "length": 50522,
                "path": [
                    "torf.1.html"
                ]
            }
        ]
    }
}

https://github.com/rndusr/torf-cli