From magnet link to .torrent
gpapin opened this issue · 1 comments
gpapin commented
Is it possible to save the content of a magnet link into a .torrent file ?
At the moment I do this:
var torrentObject = parseTorrent(torrent.url); // torrent.url is the magnet link
var buf = parseTorrent.toTorrentFile(torrentObject);
fs.writeFileSync(blackHole+'/'+torrentObject.name+'.torrent', buf);
It looks like there is a lot more information on the torrent file so this is probably not even possible ...
feross commented
It's not possible to convert a magnet link to a torrent file without a bit more information. Specifically, you need the pieces
key, which is an array of all the piece hashes. This info is retrieved by the torrent client from peers using the ut_metadata
extension, which is how magnet links work. So, if you're trying to solve this using webtorrent, for example, you can just wait until the 'metadata' or 'ready' event fires and all the necessary information will be there so that this code works:
parseTorrent.toTorrentFile(torrent) // where `torrent` is a webtorrent Torrent object