Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get InfoHash before downloading torrent #816

Closed
HughIsaacs2 opened this issue May 25, 2016 · 2 comments
Closed

Get InfoHash before downloading torrent #816

HughIsaacs2 opened this issue May 25, 2016 · 2 comments
Labels

Comments

@HughIsaacs2
Copy link

@HughIsaacs2 HughIsaacs2 commented May 25, 2016

Unless I'm mistaken there doesn't appear to be any way to get the InfoHash of a .Torrent file or Magnet link before downloading the torrent.

I think this would be useful for building WebTorrent applications that sport offline storage.

Example: I'm building something that downloads the files and stores them offline in an array using LocalForage and sets the InfoHash as the key of that storage so when a user opens a link to that same torrent it'll just search to see if it's stored offline already and use the offline stored copies instead.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented May 25, 2016

You can listen to the 'infoHash' event:

var torrent = client.add(torrentId)
torrent.on('infoHash', function (infoHash) {
  // ...
})

Another way to customize the storage location based on the infoHash is to use the store option to client.add, but you need to follow the abstract-chunk-store interface:

function Store (chunkLength, opts) {
  console.log(opts.torrent.infoHash)
}
client.add(torrentId, {
  store: Store
})

Or, probably the simplest way is to use parse-torrent to get the info hash before passing it to WebTorrent in the first place:

var parseTorrent = require('parse-torrent')

var parsed = parseTorrent(torrentId)
console.log(parsed.infoHash)

client.add(torrentId, ...)
@feross feross closed this May 25, 2016
@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.