Первая версия модуля для kodi
parent
2a4eecb830
commit
65796860b8
103
CHANGELOG.md
103
CHANGELOG.md
|
@ -1,103 +0,0 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.3.0] - 2018.06.23
|
||||
|
||||
### Added
|
||||
|
||||
- Add `errors` option in `TorrentFileParser` and `parse_torrent_file` to let user set the encoding error handler. (Thanks [@yasuotakei])
|
||||
- Add `-e`/`--error` to CLI option to set the `errors` option of `parse_torrent_file`.
|
||||
- `BDecoder` class and `decode` shortcut function to directly decode bytes.
|
||||
- `decode` shortcut function to directly encode data to bytes.
|
||||
- Added `hash_fields` parameter and method to customize hash field list.
|
||||
- Added `hash_raw` parameter to let all hash field be parsed as raw bytes.
|
||||
|
||||
### Changed
|
||||
|
||||
- **BreakChange** `TorrentFileCreator` rename to `BEncoder` as the origin name don't describe its function.
|
||||
- `TorrentFileParser` don't need the outmost level of parsed data to be a `dict` now.
|
||||
- `BEncoder` don't need the outmost level of encoded data to be a `dict` now.
|
||||
- `BEncoder` now support encode raw bytes.
|
||||
|
||||
## [0.2.0] - 2018.5.25
|
||||
|
||||
### Change
|
||||
|
||||
- Just bump version to 0.2.0 to follow semver.
|
||||
|
||||
## [0.1.5rc1] - 2018.4.28
|
||||
|
||||
### Added
|
||||
|
||||
- `TorrentFileCreator` class and `create_torrent_file` shortcut function for write back data to a torrent file.
|
||||
|
||||
## [0.1.4] - 2018-04-06
|
||||
|
||||
### Added
|
||||
|
||||
- `encoding` option can be `auto`, which will use `chardet` package to decide which encoding to use. If `chardet` is noe installed, will raise a warning and fallback to 'utf-8'. (Thanks to [@ltfychrise])
|
||||
- Add changelog.
|
||||
|
||||
### Change
|
||||
|
||||
- Reorganize test codes/files.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix integer filed can't be negative bug. (Thanks to [@ltfychrise])
|
||||
- Fix `_seek_back` method not make `_pos` back bug. (Thanks to [@ltfychrise])
|
||||
|
||||
## [0.1.3] - 2017-06-21
|
||||
|
||||
### Added
|
||||
|
||||
- Now `UnicodeDecodeError` is wrapped in `InvalidTorrentDataException`.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Use `IOError` instead of `FileNotFoundError` in Python 2.
|
||||
|
||||
### Changed
|
||||
|
||||
- `InvalidTorrentFileException` rename to `InvalidTorrentDataException`.
|
||||
|
||||
## [0.1.2] - 2017-06-21
|
||||
|
||||
### Changed
|
||||
|
||||
- Emm, I don't know, I just changed the version code...
|
||||
|
||||
## [0.1.1] - 2017-06-20
|
||||
|
||||
### Added
|
||||
|
||||
- CLI add coding `--coding/-c` option for file string filed encoding.
|
||||
|
||||
### Changed
|
||||
|
||||
- `ed2k` and `filehash` field now use same structure as 'pieces'.
|
||||
|
||||
## [0.1.0] - 2017-05-23
|
||||
|
||||
### Added
|
||||
|
||||
- Parse torrent from file and data into a dict.
|
||||
- CLI provided.
|
||||
- Simple tests.
|
||||
- Available on pip.
|
||||
|
||||
[@ltfychrise]: https://github.com/ltfychrise
|
||||
[@yasuotakei]: https://github.com/yasuotakei
|
||||
[Unreleased]: https://github.com/7sDream/torrent_parser/compare/v0.3.0...HEAD
|
||||
[0.3.0]: https://github.com/7sDream/torrent_parser/compare/v0.2.0...v0.3.0
|
||||
[0.2.0]: https://github.com/7sDream/torrent_parser/compare/v0.1.5rc1...v0.2.0
|
||||
[0.1.5rc1]: https://github.com/7sDream/torrent_parser/compare/v0.1.4...v0.1.5rc1
|
||||
[0.1.4]: https://github.com/7sDream/torrent_parser/compare/v0.1.3...v0.1.4
|
||||
[0.1.3]: https://github.com/7sDream/torrent_parser/compare/v0.1.2...v0.1.3
|
||||
[0.1.2]: https://github.com/7sDream/torrent_parser/compare/v0.1.1...v0.1.2
|
||||
[0.1.1]: https://github.com/7sDream/torrent_parser/compare/v0.1.0...v0.1.1
|
||||
[0.1.0]: https://github.com/7sDream/torrent_parser/tree/v0.1.0
|
|
@ -1 +0,0 @@
|
|||
include README.md LICENSE CHANGELOG.md
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<addon id="script.module.torrent_parser" name="torrent_parser" version="0.3.0" provider-name="inpos">
|
||||
<requires>
|
||||
<import addon="xbmc.python" version="2.25.0"/>
|
||||
<import addon="script.module.chardet" />
|
||||
</requires>
|
||||
<extension point="xbmc.python.module" library="lib"/>
|
||||
<extension point="xbmc.addon.metadata">
|
||||
<platform>all</platform>
|
||||
<language>en_GB ru_RU</language>
|
||||
<summary lang="en_GB">Torrent file parser and creator for Python</summary>
|
||||
<summary lang="ru_RU">Обработка и создание файлов .torrent</summary>
|
||||
<description lang="ru">Разработан 7sDream (https://github.com/7sDream/torrent_parser)</description>
|
||||
<description lang="en">Developed by 7sDream (https://github.com/7sDream/torrent_parser)</description>
|
||||
<email>roman@ukamnya.ru</email>
|
||||
<source>https://git.ukamnya.ru/roman/script.module.torrent_parser</source></extension>
|
||||
</addon>
|
|
@ -1,6 +0,0 @@
|
|||
[metadata]
|
||||
description-file = README.md
|
||||
license-file = LICENSE
|
||||
|
||||
[bdist_wheel]
|
||||
universal = 1
|
41
setup.py
41
setup.py
|
@ -1,41 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
try:
|
||||
from setuptools import setup
|
||||
except ImportError:
|
||||
from distutils.core import setup
|
||||
|
||||
import torrent_parser
|
||||
|
||||
setup(
|
||||
name='torrent_parser',
|
||||
keywords=['file', 'torrent', 'JSON', 'parser'],
|
||||
version=torrent_parser.__version__,
|
||||
py_modules=['torrent_parser'],
|
||||
url='https://github.com/7sDream/torrent_parser',
|
||||
license='MIT',
|
||||
author='7sDream',
|
||||
author_email='7seconddream@gmail.com',
|
||||
description='A .torrent file parser and creator for both Python 2 and 3',
|
||||
install_requires=[],
|
||||
entry_points={
|
||||
'console_scripts': ['pytp=torrent_parser:__main']
|
||||
},
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
'Environment :: Console',
|
||||
'Intended Audience :: Developers',
|
||||
'Intended Audience :: End Users/Desktop',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Natural Language :: English',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: 3.6',
|
||||
'Topic :: Multimedia',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
'Topic :: Utilities',
|
||||
]
|
||||
)
|
|
@ -1,7 +0,0 @@
|
|||
from .test_create import *
|
||||
from .test_parse import *
|
||||
from .test_encoding_error import *
|
||||
from .test_encode import *
|
||||
from .test_decode import *
|
||||
from .test_hash_field import *
|
||||
from .test_hash_raw import *
|
|
@ -1,35 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import hashlib
|
||||
import io
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
from torrent_parser import TorrentFileParser, BEncoder
|
||||
|
||||
|
||||
class TestCreate(unittest.TestCase):
|
||||
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files')
|
||||
REAL_FILE = os.path.join(TEST_FILES_DIR, 'real.torrent')
|
||||
|
||||
def test_simple_create(self):
|
||||
data = collections.OrderedDict()
|
||||
data['a'] = 1
|
||||
data['b'] = 2
|
||||
self.assertEqual(BEncoder(data).encode(), b'd1:ai1e1:bi2ee')
|
||||
|
||||
def test_same_output_if_no_edit(self):
|
||||
with open(self.REAL_FILE, 'rb') as fp:
|
||||
in_data = fp.read()
|
||||
data = TorrentFileParser(io.BytesIO(in_data), True).parse()
|
||||
out_data = BEncoder(data).encode()
|
||||
m1 = hashlib.md5()
|
||||
m1.update(in_data)
|
||||
m2 = hashlib.md5()
|
||||
m2.update(out_data)
|
||||
self.assertEqual(m1.digest(), m2.digest())
|
||||
|
||||
def test_dont_need_dict_outmost(self):
|
||||
data = 123456
|
||||
self.assertEqual(BEncoder(data).encode(), b'i123456e')
|
|
@ -1,11 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
|
||||
from torrent_parser import decode
|
||||
|
||||
|
||||
class TestDecode(unittest.TestCase):
|
||||
|
||||
def test_decode(self):
|
||||
self.assertEqual(decode(b'i12345e'), 12345)
|
|
@ -1,11 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
|
||||
from torrent_parser import encode
|
||||
|
||||
|
||||
class TestEncode(unittest.TestCase):
|
||||
|
||||
def test_encode(self):
|
||||
self.assertEqual(encode(12345), b'i12345e')
|
|
@ -1,25 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
from torrent_parser import (
|
||||
TorrentFileParser, parse_torrent_file, InvalidTorrentDataException
|
||||
)
|
||||
|
||||
|
||||
class TestDecodingError(unittest.TestCase):
|
||||
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files')
|
||||
FILE = os.path.join(TEST_FILES_DIR, 'utf8.encoding.error.torrent')
|
||||
|
||||
def test_default_option_will_raise_exception(self):
|
||||
with self.assertRaises(InvalidTorrentDataException):
|
||||
parse_torrent_file(self.FILE)
|
||||
with self.assertRaises(InvalidTorrentDataException):
|
||||
with open(self.FILE, 'rb') as f:
|
||||
TorrentFileParser(f).parse()
|
||||
|
||||
def test_not_raise_exception_when_use_ignore(self):
|
||||
parse_torrent_file(self.FILE, errors='ignore')
|
||||
with open(self.FILE, 'rb') as f:
|
||||
TorrentFileParser(f, errors='ignore').parse()
|
|
@ -1 +0,0 @@
|
|||
d3:negi-1ee
|
|
@ -1 +0,0 @@
|
|||
8:announce
|
Binary file not shown.
Binary file not shown.
|
@ -1,21 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
from torrent_parser import (
|
||||
TorrentFileParser, parse_torrent_file, decode
|
||||
)
|
||||
|
||||
|
||||
class TestHashField(unittest.TestCase):
|
||||
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files')
|
||||
FILE = os.path.join(TEST_FILES_DIR, 'utf8.encoding.error.torrent')
|
||||
|
||||
def test_not_raise_exception_when_add_hash_fields(self):
|
||||
parse_torrent_file(self.FILE, hash_fields={'info_hash': (20, False)})
|
||||
with open(self.FILE, 'rb') as f:
|
||||
TorrentFileParser(f).hash_field('info_hash').parse()
|
||||
with open(self.FILE, 'rb') as f:
|
||||
data = f.read()
|
||||
decode(data, hash_fields={'info_hash': (20, False)})
|
|
@ -1,23 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
from torrent_parser import decode, encode
|
||||
|
||||
|
||||
class TestHashRaw(unittest.TestCase):
|
||||
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files')
|
||||
FILE = os.path.join(TEST_FILES_DIR, 'utf8.encoding.error.torrent')
|
||||
|
||||
def test_hash_raw_decode(self):
|
||||
data = b'd4:hash4:\xAA\xBB\xCC\xDDe'
|
||||
res = decode(data, hash_fields={'hash': (4, False)}, hash_raw=False)
|
||||
self.assertEqual(res['hash'], 'aabbccdd')
|
||||
res = decode(data, hash_fields={'hash': (4, False)}, hash_raw=True)
|
||||
self.assertEqual(res['hash'], b'\xAA\xBB\xCC\xDD')
|
||||
|
||||
def test_raw_bytes_encode(self):
|
||||
res = {'hash': b'\xAA\xBB\xCC\xDD'}
|
||||
data = encode(res)
|
||||
self.assertEqual(data, b'd4:hash4:\xAA\xBB\xCC\xDDe')
|
|
@ -1,63 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import os.path
|
||||
import unittest
|
||||
|
||||
from torrent_parser import TorrentFileParser, parse_torrent_file
|
||||
|
||||
|
||||
class TestParse(unittest.TestCase):
|
||||
TEST_FILES_DIR = os.path.join(os.path.dirname(__file__), 'test_files')
|
||||
REAL_FILE = os.path.join(TEST_FILES_DIR, 'real.torrent')
|
||||
NEG_FILE = os.path.join(TEST_FILES_DIR, 'neg.torrent')
|
||||
STRING_FILE = os.path.join(TEST_FILES_DIR, 'outmost.string.torrent')
|
||||
|
||||
def test_parse_torrent_file_use_shortcut(self):
|
||||
parse_torrent_file(self.REAL_FILE)
|
||||
|
||||
def test_parse_torrent_file_use_class(self):
|
||||
with open(self.REAL_FILE, 'rb') as fp:
|
||||
TorrentFileParser(fp).parse()
|
||||
|
||||
def test_encoding_auto(self):
|
||||
with open(self.REAL_FILE, 'rb') as fp:
|
||||
TorrentFileParser(fp, encoding='auto').parse()
|
||||
|
||||
def test_parse_torrent_file_to_ordered_dict(self):
|
||||
data = parse_torrent_file(self.REAL_FILE, True)
|
||||
self.assertIsInstance(data, collections.OrderedDict)
|
||||
|
||||
with open(self.REAL_FILE, 'rb') as fp:
|
||||
data = TorrentFileParser(fp, True).parse()
|
||||
self.assertIsInstance(data, collections.OrderedDict)
|
||||
|
||||
def test_parse_correctness(self):
|
||||
data = parse_torrent_file(self.REAL_FILE)
|
||||
self.assertIn(['udp://tracker.publicbt.com:80/announce'],
|
||||
data['announce-list'])
|
||||
self.assertEqual(data['creation date'], 1409254242)
|
||||
|
||||
def test_parse_two_times(self):
|
||||
with open(self.REAL_FILE, 'rb') as fp:
|
||||
parser = TorrentFileParser(fp)
|
||||
data = parser.parse()
|
||||
self.assertIn(['udp://tracker.publicbt.com:80/announce'],
|
||||
data['announce-list'])
|
||||
self.assertEqual(data['creation date'], 1409254242)
|
||||
data = parser.parse()
|
||||
self.assertIn(['udp://tracker.publicbt.com:80/announce'],
|
||||
data['announce-list'])
|
||||
self.assertEqual(data['creation date'], 1409254242)
|
||||
|
||||
def test_int_is_negative(self):
|
||||
data = parse_torrent_file(self.NEG_FILE)
|
||||
self.assertEqual(data['neg'], -1)
|
||||
|
||||
def test_dont_need_dict_outmost(self):
|
||||
data = parse_torrent_file(self.STRING_FILE)
|
||||
self.assertEqual(data, 'announce')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue