folz / bento

:bento: A fast, correct, pure-Elixir library for reading and writing Bencoded metainfo (.torrent) files.
Mozilla Public License 2.0
94 stars 14 forks source link

Adding support for magnet link generation #11

Open tchoutri opened 6 years ago

tchoutri commented 6 years ago

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 :)

folz commented 6 years ago

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 notifications@github.com 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 .

tchoutri commented 6 years ago

@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. :)

folz commented 6 years ago

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!

fire commented 3 years ago

Was this ever submitted?

folz commented 3 years ago

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.

tchoutri commented 3 years ago

Unfortunately I have lost said work. :/

folz commented 3 years ago

No worries :) just figured I'd ask.

fire commented 3 years ago

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.