Comments (3)
parse_torrent_file
will use Python's default dict, but it provides a use_ordered_dict
argument, to use collections.OrderedDict
. This parameter should be used in this scenario. It seems that this test is not rigorous. I will fix it when I have time.
And for now, you can just use the code in the test file(with use_ordered_dict=True
) to calculate info hash. For more context, see Issue #13.
from torrent_parser.
Oh, I notice the sorted
you want to disscuess is not what I think of.
If you are talking about lexicographic order, the corrent implementation do not follow this. There is no mandatory requirement for the dictionary to be in order when parsing, and it will not actively perform sorting operations during encoding.
But this seems do not effect calculation of info hash, as long as the encoding step generated key order of info dict is the same as origin file bytes(by adding the use_ordered_dict=True
parameter).
from torrent_parser.
There is no mandatory requirement for the dictionary to be in order when parsing
this would be nice to preserve the infohash
it provides a
use_ordered_dict
argument, to usecollections.OrderedDict
this is needed only for python2
and then torrent_parser should use OrderedDict automatically, to preserve the infohash
if sys.version_info[0] == 2:
from collections import OrderedDict
result = dict()
if sys.version_info[0] == 2:
result = OrderedDict()
in python3, dict
is an OrderedDict
>>> dict(b=2, a=1)
{'b': 2, 'a': 1}
>>> { "b": 2, "a": 1 }
{'b': 2, 'a': 1}
alternative solution: the parser could calculate the infohashes from raw source bytes of the info dict, and store the infohashes in attributes of the result data dict. calculating sha1 and sha256 digests should be cheap enough to make this default for parse_torrent_file
. internally, only the raw hashes are stored. the _hex
attributes return _raw.hex()
(in python3)
torrent = torrent_parser.parse_torrent_file("input.torrent")
if torrent.has_v1:
info_hash_v1_raw = torrent.info_hash_v1_raw # -> bytes
info_hash_v1_hex = torrent.info_hash_v1_hex # -> string
if torrent.has_v2:
info_hash_v2_raw = torrent.info_hash_v2_raw # -> bytes
info_hash_v2_hex = torrent.info_hash_v2_hex # -> string
alternatively, we could store the source locations of the info dict, and the user has to read the file again and calculate the digest manually. but IMO, the infohash is always useful when dealing with torrent files
from torrent_parser.
Related Issues (12)
- UnicodeDecodeError: 'utf8' codec can't decode byte 0xb5 in position 1: invalid start byte HOT 4
- Changing trackers in announce-list corrupts save HOT 7
- Missing dependency typing_extensions HOT 3
- torrent_parser does not return "Info Hash v1" value HOT 6
- Python2.7 处理不存在的文件时出现 NameError: global name 'FileNotFoundError' is not defined HOT 1
- hello,I find something wrong in you code.. HOT 4
- UnicodeDecodeError HOT 7
- Same error with every torrent. HOT 2
- Web siders are sorted by length, but not by name. HOT 5
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 43 HOT 2
- v2 Torrent supported? HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torrent_parser.