bento icon indicating copy to clipboard operation
bento copied to clipboard

Adding support for magnet link generation

Open tchoutri opened this issue 7 years ago • 8 comments

Hi! I'm already using Bento to parse torrent files, and I would like to know if you'd accept a PR that implements magnet link generation from a torrent file.

Happy holidays :)

tchoutri avatar Dec 24 '17 15:12 tchoutri

Glad to hear it's useful for you! Magnet support sounds great, I'm happy to see that as a PR.

Your comment reminded me about something you may want to address when writing this PR: the encoder alphabetically orders Map keys when encoding but the parser doesn't validate that bencoded dicts have alphabetical keys when parsing. This means the hash of a torrent file with unsorted dict keys will not equal the hash of decoding and reencoding that torrent with Bento. It's my understanding that magnet links address content by hash value, so this could cause two separate links for what is effectively the same content.

Since the bencode spec requires that dict keys be alphabetically ordered, you'll only come across this issue if you're working with noncompliant torrent files. If the files you work with are all spec-compliant, or if you don't care about the above issue, don't worry about it :)

Happy holidays!

On Sun, Dec 24, 2017, 10:19 Théophile Choutri [email protected] wrote:

Hi! I'm already using Bento to parse torrent files, and I would like to know if you'd accept a PR that implements magnet link generation from a torrent file.

Happy holidays :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/folz/bento/issues/11, or mute the thread https://github.com/notifications/unsubscribe-auth/AASREfyOgjMIHuVFTOOJ096I4CIdnuYsks5tDmt2gaJpZM4RL8zK .

folz avatar Dec 24 '17 19:12 folz

@folz Okay, I'm almost done implementing it. Before I open a PR, do you have any opinion about the API I should provide? I understand that I should provide a ! and non-! of my magnet function, but should I leave the file reading to the user?

Thanks for your support. :)

tchoutri avatar Jan 24 '18 17:01 tchoutri

Yep, like .torrent!?() you should have one version that raises and one that returns ok/error, and the user should handle reading a file or otherwise loading the iodata that you pass to Bento.magnet!?(), and they should also handle saving/persisting the response. You just need to accept and return some iodata.

Thanks for working on this. I'm looking forward to the PR!

folz avatar Jan 24 '18 18:01 folz

Was this ever submitted?

fire avatar Nov 10 '20 02:11 fire

No, it wasn't. If you want to submit a PR, or if @tchoutri is interested in finding their old work, I'd be happy to get it merged in.

folz avatar Nov 10 '20 04:11 folz

Unfortunately I have lost said work. :/

tchoutri avatar Nov 10 '20 08:11 tchoutri

No worries :) just figured I'd ask.

folz avatar Nov 11 '20 04:11 folz

My plan is to use c libtorrent wrapped via Unifex to support the webtorrent protocol, however that's not this library. Thanks for all the replies.

fire avatar Nov 11 '20 15:11 fire