Welcome to torrentinfo’s documentation!

This documentation aims to provide at least an overview of what to expect when using or scripting against torrentinfo.

About

torrentinfo parses .torrent files and displays information about the torrent and the files that it references. On the default basic setting it shows:

  • Torrent name
  • Tracker URL
  • The creator of the torrent
  • The torrent’s creation date
  • The number of files (if a multi-file torrent)
  • The name of the file (if a single-file torrent)
  • The total size of the file/files

If asked to display file information the path and size of each file is listed.

Additionally the entire torrent can be shown in hierachical form.

Why fork?

I forked the original project simply because it was missing functionality I desired, namely what the -t flag does now. It turned out that the code was an undocummented mess but it worked so no one bothered. It was no longer listed on the creators website and the original creator was surprised that anyone even found it useful. For this reason I decided to the dust off the project, clean it up, document it and provide a few tests along the way.

I’m keeping the original name of the project in case someone (like me) finds themself in a similar position and does a Google search for “torrentinfo”.

Usage

usage: torrentinfo [-h] [-v] [-t | -f | -d] [-a] [-n] filename [filename ...]:

Print information about torrent files

positional arguments:
  filename        Torrent files to process

optional arguments:
  -h, --help        show this help message and exit
  -v, --version     Print version and quit
  -t, --top         Only show top level file/directory
  -f, --files       Show files within the torrent
  -d, --detailed    Print more information about the files
  -e, --everything  Print everything we can about the torrent
  -a, --ascii       Only print out ascii
  -n, --nocolour    No ANSI colour

If no settings are specified the script will default to showing the basic information on each file.

Install

TorrentInfo uses the standard Python distribution utilities. So it should just be a case of uncompressing the archive and running:

./setup.py install

The user running this must have sufficient permissions to create a file in the install directory.

Bugs

Any bugs or fixes should be submitted to my GitHub.

Credits

I like to give credit where it’s due. Vrai Stacey is the original creator but no longer maintains the project .

torrentinfo

Parses .torrent files and displays various summaries of the information contained within.

Published under the GNU Public License: http://www.gnu.org/copyleft/gpl.html

class torrentinfo.Config(formatter, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, err=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>, tab_char=' ')[source]

Class storing configuration propagated throughout the program.

class torrentinfo.StringBuffer(string)[source]

String processing class.

exception BufferOverrun[source]

Raised when the buffer goes past EOF.

exception StringBuffer.CharacterExpected[source]

Raised when the buffer doesn’t find the expected character.

StringBuffer.get(length)[source]

Gets certain amount of characters from the buffer.

Parameters:length (int) – Number of characters to get from the buffer
Returns:str – first length characters from the buffer
Raises :BufferOverrun
StringBuffer.get_upto(character)[source]

Gets all characters in a string until the specified one, exclusive.

Parameters:character (str) – Character until which the string should be collected
Returns:str – collected string from the buffer up to character
Raises :CharacterExpected
StringBuffer.is_eof()[source]

Checks whether we’re at the end of the string.

Returns:bool – true if this instance reached end of line
StringBuffer.peek()[source]

Peeks at the next character in the string.

Returns:str – next character of this instance
Raises :BufferOverrun
StringBuffer.unicode_get(length, destructive=True, replacement='×')

A get method called when bytes are encountered. Casts into unicode where at all possible or uses the replacement character otherwise.

Parameters:
  • length (int) – number of characters to get from the buffer
  • destructive (bool) – decides whether to progress the buffer
  • replacement (str) – Replacement to use character if unicode decode fails
Returns:

str – Unicode string from the string buffer

class torrentinfo.TextFormatter(colour)[source]

Class used to format strings before printing.

string_format(format_spec, config, string='')[source]

Attaches colour codes to strings before outputting them.

Parameters:
  • format_spec (int) – value of the colour code
  • string (str) – string to colour
class torrentinfo.Torrent(filename, string_buffer)[source]

A class modelling a parsed torrent file.

exception torrentinfo.UnexpectedType[source]

Thrown when the torrent file is not just a single dictionary

exception torrentinfo.UnknownTypeChar[source]

Thrown when Torrent.parse encounters unexpected character

torrentinfo.basic(config, torrent)[source]

Prints out basic information about a Torrent instance.

Parameters:
  • config (Config) – configuration object to use in this method
  • torrent (Torrent) – torrent instance to use for information
torrentinfo.basic_files(config, torrent)[source]

Prints out basic file information of a Torrent instance.

Parameters:
  • config (Config) – configuration object to use in this method
  • torrent (Torrent) – torrent instance to use for information
torrentinfo.decode(string_buffer)[source]

Decodes a bencoded string.

Parameters:string_buffer (StringBuffer) – bencoded torrent file content buffer
Returns:dict
torrentinfo.dump(item, config, depth, newline=True, as_utf_repr=False)[source]

Printing method.

Parameters:
  • item (dict or list or str or int) – item to print
  • config (Config) – configuration object to use in this method
  • depth (int) – indentation depth
  • newline (bool) – indicates whether to insert a newline after certain strings
  • as_utf_repr (bool) – indicates whether only ASCII should be printed
torrentinfo.dump_as_date(number, config)[source]

Dumps out the Integer instance as a date.

Parameters:
  • n (int) – number to format
  • config (Config) – configuration object to use in this method
torrentinfo.dump_as_size(number, config, depth)[source]

Dumps the string to the stdout as file size after formatting it.

Parameters:
  • n (int) – number to format
  • config (Config) – configuration object to use in this method
  • depth (int) – indentation depth
torrentinfo.get_arg_parser()[source]

Parses command-line arguments.

Returns:ArgumentParser
torrentinfo.get_line(config, prefix, key, torrent, is_date=False)[source]

Print lines from a torrent instance.

Parameters:
  • config (Config) – configuration object to use in this method
  • prefix (str) – prefix to insert in front of the line
  • key (str) – key name in the torrent to print out
  • torrent (Torrent) – torrent instance to use for information
  • depth (int) – indentation depth
  • is_date (bool) – indicates whether the line is a date
  • format_spec (int) – default colour to use for the text
torrentinfo.is_ascii_only(string)[source]

Checks whether a string is ascii only.

Parameters:string (str) – string to check
Returns:bool
torrentinfo.list_files(config, torrent, detailed=False)[source]

Prints out a list of files using a Torrent instance

Parameters:
  • config (Config) – configuration object to use in this method
  • torrent (Torrent) – torrent instance to use for information
  • detailed – indicates whether to print more information about files
  • detailed – bool
torrentinfo.load_torrent(filename)[source]

Loads file contents from a torrent file

Parameters:filename (str:) – torrent file path
Returns:StringBuffer
torrentinfo.main(alt_args=None, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, err=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>)[source]

Main control flow function used to encapsulate initialisation.

torrentinfo.start_line(config, prefix, depth, postfix='', format_spec=1)[source]

Print the first line during information output.

Parameters:
  • config (Config) – configuration object to use in this method
  • prefix (str) – prefix to insert in front of the line
  • depth (int) – indentation depth
  • postfix (str) – postfix to insert at the back of the line
  • format_spec (int) – default colour to use for the text
torrentinfo.top(config, torrent)[source]

Prints out the top file/directory name as well as torrent file name.

Parameters:
  • config (Config) – configuration object to use in this method
  • torrent (Torrent) – torrent instance to use for information

Table Of Contents

This Page