tp
torrent_parser
pypi i torrent_parser
tp

torrent_parser

A .torrent file parser and creator for both Python 2 and 3

by 7sDream

0.3.0 (see all)License:MIT
pypi i torrent_parser
Readme

Torrent file parser and creator for Python

A simple parser for .torrent file.

Can also edit and write back to torrent format after version 0.2.0.

Features

  • Decoder and encoder for torrent files
  • Auto decode bytes field to string with used specified encoding and error handler
  • Auto detect encoding when use auto as encoding(need chardet installed)
  • Auto decode hash value filed to hash blocks, also customizable
  • CLI provided, with JSON output

Install

pip install torrent_parser

Usage

CLI

pytp test.torrent
cat test.torrent | pytp

As a module

>>> import torrent_parser as tp
>>> data = tp.parse_torrent_file('test.torrent')
>>> data['announce']
http://tracker.trackerfix.com:80/announce
>>> data['announce'] = 'http://127.0.0.1:12345'
>>> tp.create_torrent_file('new.torrent', data)

or you don't operate with file, just raw bytes:

>>> import torrent_parser as tp
>>> data = tp.decode(b'd3:negi-1ee')
>>> data['neg']
-1
>>> tp.encode(data)
b'd3:negi-1ee'

Test

python -m unittest tests

Changelog

See Changelog.

LICENSE

See License.

GitHub Stars

121

LAST COMMIT

7mos ago

MAINTAINERS

1

CONTRIBUTORS

4

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
0.3.0
4yrs ago
0.2.0
4yrs ago
0.1.5rc1
4yrs ago
0.1.4
4yrs ago
No alternatives found
No tutorials found
Add a tutorial