Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rsnitsch committed Jan 11, 2021
2 parents 68bc426 + 71410a7 commit 338198c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
15 changes: 9 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
docs/build/
src/__pycache__/
Pipfile.lock
dist
src/py3createtorrent.egg-info
build
docs/build/
src/__pycache__/
Pipfile.lock
dist
src/py3createtorrent.egg-info
build
testdata/
.idea/
*.torrent
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Of course, you need to have Python 3 installed on your system. py3createtorrent
Full documentation
------------------

https://py3createtorrent.readthedocs.io/en/develop/user.html
https://py3createtorrent.readthedocs.io/en/latest/user.html
32 changes: 30 additions & 2 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
Changelog
=========

Version 1.0.0
-------------

*Release date: 2021/01/11*

* changed: **requires Python 3.5+ now**
* changed: specifying trackers is now optional with the new ``-t`` switch, thus **trackerless torrents are now
possible**
* added: **bestN shortcut**! It is now possible to add the best N trackers from `ngosang/trackerslist <https://github.com/ngosang/trackerslist>`_
by using the new `bestN shortcut <user.html#bestn-automatically-add-the-best-trackers>`__
* changed: use **external JSON files for configuration**, by default try to load ``.py3createtorrent.cfg``
from user's home directory
* added: DHT bootstrap nodes can now be specified with the new ``--node`` switch (doing so is recommended for
trackerless torrents)
* added: **webseed support** with the new ``--webseed`` switch (GetRight style, i.e. `<http://bittorrent.org/beps/bep_0019.html>`_)
* changed: increased max piece size to 16 MiB
* changed: show warning if piece size is not a multiple of 16 KiB
* changed: updated the default trackers (openbt is now opentrackr, dropped publicbt, added cyberia and coppersurfer)
* added: Pipfile and Pipfile.lock for pipenv support
* added: README.md
* changed: improved performance of single file torrent creation
* fixed: parentheses are now allowed in names specified by using the ``--name`` switch
* refactored: switched to bencode.py module for encoding the torrent data
* refactored: switched from optparse to argparse
* refactored: reformatted code with yapf, using a new column limit of 120
* refactored: added type hints to enable analysis with mypy (we use Python's typing module which was added in
Python 3.5, thus Python 3.5 is the new minimum version that is required)

Version 1.0.0b2 (beta version)
------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

*Release date: 2021/01/08*

* fixed: parentheses are now allowed in names specified by using the ``--name`` switch

Version 1.0.0b1 (beta version)
------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

*Release date: 2021/01/04*

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# General information about the project.
project = u'py3createtorrent'
copyright = u'2013-2020, Robert Nitsch'
copyright = u'2013-2021, Robert Nitsch'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -50,7 +50,7 @@
# The short X.Y version.
version = '1.0'
# The full version, including alpha/beta/rc tags.
release = '1.0.0b2'
release = '1.0.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
21 changes: 10 additions & 11 deletions src/py3createtorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
print()
raise

__all__ = ['calculate_piece_length', 'get_files_in_directory', 'sha1_20', 'split_path']
__all__ = ['calculate_piece_length', 'get_files_in_directory', 'sha1', 'split_path']

# Do not touch anything below this line unless you know what you're doing!

__version__ = '1.0.0b2'
__version__ = '1.0.0'

# Note:
# Kilobyte = kB = 1000 Bytes
Expand Down Expand Up @@ -118,11 +118,11 @@ def printv(*args: Any, **kwargs: Any) -> None:
print(*args, **kwargs)


def sha1_20(data: bytes) -> bytes:
"""Return the first 20 bytes of the given data's SHA-1 hash."""
def sha1(data: bytes) -> bytes:
"""Return the given data's SHA-1 hash (= always 20 bytes)."""
m = hashlib.sha1()
m.update(data)
return m.digest()[:20]
return m.digest()


def create_single_file_info(file: str, piece_length: int, include_md5: bool = True) -> Dict:
Expand All @@ -140,6 +140,7 @@ def create_single_file_info(file: str, piece_length: int, include_md5: bool = Tr

# Total byte count.
length = os.path.getsize(file)
assert length > 0, "empty file"

# Concatenated 20byte sha1-hashes of all the file's pieces.
piece_count = int(math.ceil(length / piece_length))
Expand All @@ -162,20 +163,18 @@ def create_single_file_info(file: str, piece_length: int, include_md5: bool = Tr
if count == piece_length:
if include_md5:
md5.update(piece_data)
pieces[i * 20:(i + 1) * 20] = sha1_20(piece_data)
pieces[i * 20:(i + 1) * 20] = sha1(piece_data)
elif count != 0:
if include_md5:
md5.update(piece_data[:count])
pieces[i * 20:(i + 1) * 20] = sha1_20(piece_data[:count])
pieces[i * 20:(i + 1) * 20] = sha1(piece_data[:count])
else:
break

i += 1

printv("done")

assert length > 0, "empty file"

info = {
'pieces': bytes(pieces),
'name': os.path.basename(file),
Expand Down Expand Up @@ -242,7 +241,7 @@ def create_multi_file_info(directory: str, files: List[str], piece_length: int,
data += filedata

if len(data) >= piece_length:
info_pieces += sha1_20(data[:piece_length])
info_pieces += sha1(data[:piece_length])
data = data[piece_length:]

if include_md5:
Expand All @@ -260,7 +259,7 @@ def create_multi_file_info(directory: str, files: List[str], piece_length: int,

# Don't forget to hash the last piece. (Probably the piece that has not reached the regular piece size.)
if len(data) > 0:
info_pieces += sha1_20(data)
info_pieces += sha1(data)

# Build the final dictionary.
info = {'pieces': bytes(info_pieces), 'name': os.path.basename(directory.strip("/\\")), 'files': info_files}
Expand Down

0 comments on commit 338198c

Please sign in to comment.