rndusr / torf

Python module to create, parse and edit torrent files and magnet links
GNU General Public License v3.0
180 stars 17 forks source link

How do I set piece_size_min, piece_size_max? #13

Closed PyR8zdl closed 4 years ago

PyR8zdl commented 4 years ago

I'm having issues creating large torrents due to max piece size limits.

torf._errors.PieceSizeError: Piece size must be between 16384 and 16777216: 67108864

My piece size calc code can use piece sizes from 16KB to 256MB

The above error was trying to create a torrent with a 64MB piece size

I saw in the docs that the values can be set here... https://torf.readthedocs.io/en/latest/#torf.Torrent.piece_size_min

But I guess I'm not implementing it correctly.

My code...

torrent = torf.Torrent(path=path,
trackers=torrent_announce,
private=True,
comment='This is a comment',
piece_size=piece_size,
piece_size_min='16384',
piece_size_max='268435456',
created_by='torf/3.0.0',
source=torrent_source)

But get TypeError: __init__() got an unexpected keyword argument 'piece_size_min'

How am I supposed to set piece_size_min, piece_size_max?

Thanks for bearing with my ignorance and for any help you can provide.

rndusr commented 4 years ago

Those are class attributes. Notice how "piece_size_min" and "piece_size_max" are not arguments for torf.Torrent: https://torf.readthedocs.io/en/latest/#torf.Torrent

This is how you're supposed to set these.

torf.Torrent.piece_size_max = ...

Or, if you're already subclassing torf.Torrent for custom piece size calculation:

class LargeTorrent(torf.Torrent):
    piece_size_max = 268435456

    @classmethod
    def calculate_piece_size(cls, size):
        return <the result of your piece size calculation>

Can I ask why you're passing "created_by='torf/3.0.0'"? That version is out of date (current is 3.0.1) and you can just not pass the "create_by" argument for the same effect.