mafintosh / torrent-stream

The low level streaming torrent engine that peerflix uses
MIT License
1.94k stars 228 forks source link

question: send js blob to torrent-stream #86

Closed smolleyes closed 9 years ago

smolleyes commented 9 years ago

hi

i have some difficulties to download and write torrents from a private tracker to file (or buffer) and pass it to torrent-stream...

i can get a blob of my torrent thru $ajax

Blob {type: "application/x-bittorrent", size: 14462, slice: function}

how can i do to convert / use this blob with torrent-stream :/ ?

thanks

mafintosh commented 9 years ago

Try downloading it with {responseType:'arraybuffer'} and then converting it to aUInt8Array`

jaruba commented 9 years ago

How did you ever get this working @smolleyes ?

I think I tried all I can think of.. tried decoding iso-8859-1 to utf-8 with iconv-lite, saving to files, sending as array buffer, UInt8Array buffer, tried XMLHttpRequest, node-request and node-http.

If it's a UInt8Array I get the error that it's not a torrent or magnet link. Otherwise, if it's a buffer I get the error that some character at point ... is wrong. If I save it to a binary or ascii encoded file or string it gets the wrong torrent hash and never finds any peers.

I tested with multiple torrent files from torcache.net (all torrents are encoded with iso-8859-1 on their server)

mafintosh commented 9 years ago

@jaruba torrents are binary files. if you have trouble getting this to work you can generate a magnet link instead by doing magnet:?xt=urn:sha1:{infohash}

jaruba commented 9 years ago

Then shouldn't this work:

var request = require("request");
var requestOptions  = { encoding: null, url: torLink };

request(requestOptions, function(error, response, body) {
    peerflix("magnet:\?xt=urn:sha1:"+require('crypto').createHash('sha1').update(body).digest('hex'));  
});

But I'm getting: Uncaught Error: You must pass a valid torrent or magnet link - peerflix/node_modules/torrent-stream/index.js:69

asapach commented 9 years ago

Shouldn't it be magnet:?xt=urn:btih:{infoHash} instead of magnet:?xt=urn:sha1:{infohash}?

asapach commented 9 years ago

Also @jaruba, you should probably use read-torrent for what you're trying to do.

jaruba commented 9 years ago

This worked great:

var readTorrent = require('read-torrent');

readTorrent(torLink, function(err, torrent) {
    peerflix("magnet:\?xt=urn:btih:"+torrent["infoHash"]);
});

If I only knew about this 24 hours ago.. Thanks a lot. :)

asapach commented 9 years ago

You can just pass the torrent:

var readTorrent = require('read-torrent');

readTorrent(torLink, function(err, torrent) {
    peerflix(torrent);
});
jaruba commented 9 years ago

Even better, thanks. :)