rndusr / torf-cli

CLI tool for creating, reading and editing torrent files
GNU General Public License v3.0
134 stars 13 forks source link

Create Torrent From Magnet Link In CLI? #13

Closed HDVinnie closed 4 years ago

HDVinnie commented 4 years ago

Is this possible with CLI? Only seeing example to make torrent/magnet from existing files.

HDVinnie commented 4 years ago

Docs also seem to be down.

rndusr commented 4 years ago

No, that's not implemented yet. I've added it to my list.

I'll look into the docs issue, thanks.

rndusr commented 4 years ago

Now that I'm actually thinking about this, I don't see how this is feasible.

A magnet link doesn't contain the piece hashes that are used to check if a downloaded piece is corrupt. But a torrent file must have these piece hashes to be valid.

The only way to solve this would be to connect to the DHT and download the piece hashes, but that can take forever and would add a huge amount of code.

There are websites that do that for you, but I don't want to make this tool depend on some unknown third party.

Let me know if you have any ideas.

rndusr commented 4 years ago

OK, I did some research and there are actually several ways to get the missing information.

  1. The "xs" and "as" parameters specify torrent file download URLs. This should work now:

    torf -i 'magnet:?xt=urn:btih:e73108cbd628fee5cf203acdf668c5bf45d07810&xs=http%3A%2F%2Freleases.ubuntu.com%2F18.04%2Fubuntu-18.04.4-live-server-amd64.iso.torrent' -o ubuntu.torrent

  2. It looks like you can download the torrent by changing the announce URL from ".../announce" to ".../file?info_hash=...". I tried hard to find any documentation for this, but I failed. The only source I have is this answer on StackOverflow: https://stackoverflow.com/a/1019588

    I don't how widely it's supported, but this works:

    torf -i 'magnet:?xt=urn:btih:e73108cbd628fee5cf203acdf668c5bf45d07810&tr=https%3A%2F%2Ftorrent.ubuntu.com%2Fannounce' -o ubuntu.torrent

    Any further information would be appreciated.

  3. Downloading from UDP trackers. I don't know if this works as with HTTP trackers. According to the docs, trackers don't even have the "info" section, just it's hash.

  4. Downloading from DHT doesn't look trivial, even with a library. I have to play around and see how this works.