2018-04-28 19:14:54 +03:00
|
|
|
# Torrent file parser and creator for Python
|
2017-05-23 08:35:40 +03:00
|
|
|
|
2018-04-28 19:08:48 +03:00
|
|
|
A simple parser for `.torrent` file.
|
|
|
|
|
2018-05-25 12:24:31 +03:00
|
|
|
Can also edit and write back to torrent format after version 0.2.0.
|
2018-04-28 19:08:48 +03:00
|
|
|
|
2018-06-22 17:42:15 +03:00
|
|
|
## 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
|
|
|
|
- Uniform exception type
|
|
|
|
- CLI provided, with JSON output
|
|
|
|
|
2017-05-23 08:35:40 +03:00
|
|
|
## Install
|
|
|
|
|
|
|
|
```
|
2017-05-23 08:49:54 +03:00
|
|
|
pip install torrent_parser
|
2017-05-23 08:35:40 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage:
|
|
|
|
|
|
|
|
### CLI
|
|
|
|
|
|
|
|
```
|
|
|
|
$ pytp test.torrent
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
$ cat test.torrent | pytp
|
|
|
|
```
|
|
|
|
|
|
|
|
![][screenshots-help]
|
|
|
|
|
|
|
|
![][screenshots-normal]
|
|
|
|
|
|
|
|
![][screenshots-indent]
|
|
|
|
|
|
|
|
|
|
|
|
### As a module
|
|
|
|
|
|
|
|
```pycon
|
|
|
|
>>> import torrent_parser as tp
|
|
|
|
>>> data = tp.parse_torrent_file('test.torrent')
|
2018-06-22 17:42:15 +03:00
|
|
|
>>> data['announce']
|
2017-05-23 08:35:40 +03:00
|
|
|
http://tracker.trackerfix.com:80/announce
|
2018-04-28 19:08:48 +03:00
|
|
|
>>> data['announce'] = 'http://127.0.0.1:12345'
|
|
|
|
>>> tp.create_torrent_file('new.torrent', data)
|
2017-05-23 08:35:40 +03:00
|
|
|
```
|
|
|
|
|
2018-06-22 17:42:15 +03:00
|
|
|
or you don't operate with file, just raw bytes:
|
|
|
|
|
|
|
|
```pycon
|
|
|
|
>>> import torrent_parser as tp
|
|
|
|
>>> data = tp.decode(b'd3:negi-1ee')
|
|
|
|
>>> data['neg']
|
|
|
|
-1
|
|
|
|
>>> tp.encode(data)
|
|
|
|
b'd3:negi-1ee'
|
|
|
|
```
|
|
|
|
|
2017-05-23 08:35:40 +03:00
|
|
|
## Test
|
|
|
|
|
|
|
|
```bash
|
2018-04-06 08:41:51 +03:00
|
|
|
python -m unittest tests
|
2017-05-23 08:35:40 +03:00
|
|
|
```
|
|
|
|
|
2018-04-06 08:41:51 +03:00
|
|
|
## Changelog
|
|
|
|
|
|
|
|
See [Changelog][CHANGELOG].
|
|
|
|
|
2017-05-23 08:35:40 +03:00
|
|
|
## LICENSE
|
|
|
|
|
|
|
|
See [License][LICENSE].
|
|
|
|
|
|
|
|
[screenshots-help]: http://rikka-10066868.image.myqcloud.com/7c23f6d0-b23f-4c57-be93-d37fafe3292a.png
|
|
|
|
[screenshots-normal]: http://rikka-10066868.image.myqcloud.com/1492616d-9f14-4fe2-9146-9a3ac06c6868.png
|
|
|
|
[screenshots-indent]: http://rikka-10066868.image.myqcloud.com/eadc4184-6deb-42eb-bfd4-239da8f50c08.png
|
|
|
|
[LICENSE]: https://github.com/7sDream/torrent_parser/blob/master/LICENSE
|
2018-06-22 17:42:15 +03:00
|
|
|
[CHANGELOG]: https://github.com/7sDream/torrent_parser/blob/master/CHANGELOG.md
|