How to create torrent file from magnet link using java?

荒凉一梦 提交于 2019-11-29 23:59:39

问题


So I wanted to work on a new Java project that converts magnet URIs into .torrent files, however I can't find a way to do that, basically I broke a magnet URI into pieces :

The used URI :

magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=udp%3A%2F%2Ftracker.example4.com%3A80&tr=udp%3A%2F%2Ftracker.example5.com%3A80&tr=udp%3A%2F%2Ftracker.example3.com%3A6969&tr=udp%3A%2F%2Ftracker.example2.com%3A80&tr=udp%3A%2F%2Ftracker.example1.com%3A1337

The breaking down :

magnet:?

xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36

dn=Leaves+of+Grass+by+Walt+Whitman.epub

tr=udp%3A%2F%2Ftracker.example4.com%3A80

tr=udp%3A%2F%2Ftracker.example5.com%3A80

tr=udp%3A%2F%2Ftracker.example3.com%3A6969

tr=udp%3A%2F%2Ftracker.example2.com%3A80

tr=udp%3A%2F%2Ftracker.example1.com%3A1337

from what I gathered using this link, The torrent file contains the files , lengths and paths of the required files but I can't seem to get that from the magnet URI.

Thanks in advance.


回答1:


It's impossible to recreate the .torrent file from the magnet link alone.

The way torrent clients gets the .torrent file from a magnet link is:

  • Get a peer list from the tracker(s) and/or from the DHT.
  • Connect to peers and download the .torrent metadata using
    BEP9 - Extension for Peers to Send Metadata Files.



回答2:


not really clean but..

Runtime.getRuntime().exec(new String[]{"cmd", "/c","start firefox " + mag});

// needs firefox and a default torrent handler. // mag = magnet string



来源:https://stackoverflow.com/questions/48873300/how-to-create-torrent-file-from-magnet-link-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!