简体   繁体   English

从 URL 下载 Torrent 文件

[英]Download Torrent File from URL

I am in the beginning stages of learning node.js and I wanted create simple command line program to download the .torrent file from a URL given.我正处于学习 node.js 的开始阶段,我想创建简单的命令行程序来从给定的 URL 下载 .torrent 文件。

Let's say I have the following torrent URL假设我有以下种子 URL

https://torcache.net/torrent/3F19B149F53A50E14FC0B79926A391896EABAB6F.torrent?title=[kat.cr]ubuntu.15.10.desktop.64.bit https://torcache.net/torrent/3F19B149F53A50E14FC0B79926A391896EABAB6F.torrent?title=[kat.cr]ubuntu.15.10.desktop.64.bit

I have the following code that I can get the contents but when I save the file, it is not the same as the file downloaded from the browser.我有以下代码可以获取内容,但是当我保存文件时,它与从浏览器下载的文件不同。

var fs = require('fs');
var request = require('request');

var url = "https://torcache.net/torrent/3F19B149F53A50E14FC0B79926A391896EABAB6F.torrent?title=[kat.cr]ubuntu.15.10.desktop.64.bit";
var file = fs.createWriteStream("c:\\test\\test.torrent");

var r = request(url);

r.on('response', function(res){
    res.pipe(file);
});

Result is something like this:结果是这样的:

1f8b 0800 0000 0000 0203 94b6 63ac 3040
b3ad b96d dbb6 6ddb b66d dbb6 6ddb b66d
dbb6 f96e ef3d dfdc 73cf cce4 6492 c9fc
ecea 67ad ae54 2ad5 65c2 c165 6867 67ef
6a67 6cca c2cc e56a e2c0 454f efe2 6468
6c6d ea44 676c efe0 60ea e4ec ea64 f69f
838b 3517 1b27 1b27 fd7f d38c ccff 9790
d6c6 d2d9 c5c6 e6ff 9fde d486 85e5 7ff0
f60e a676 4696 2e2e f64e 4ea6 762e ff91
db72 7130 fc3f 04cc ff2d 30b7 b1ff df90
339d 83fb fff4 65e6 f81f be0e ae46 3696
c646 ff2f 8eff 49c1 c2c5 e5ff 642d 1ddc
d8e8 fefb 6557 2357 3b17 d7ff 85ff 4f6f
ceff 16fc 7fb2 a6ec 5cff 09da fe87 6163
e452 f92f 9ac0 c4de ddce c6de d0c4 d484
c0cc c9de 96e0 7fbb 1018 1b1a 5b98 1218
ba10 fcdf eeff 2b44 6767 ea42 ff9f 521b
3b99 1aba 58da db11 9818 ba98 5a32 b2b0
b0b2 32b0 3371 729a b270 59da 99d9 9bb0
71d9 98da 99bb 5858 3232 b273 3073 b0b1
3033 fde7 cace d0d6 9499 81eb bf52 a465
64a5 6364 a035 3175 b676 b177 a035 b435
6163 a1b3 74b6 6764 e272 b034 3536 25f8
df0e ac4c 2c4c 1c1c a66c ff15 7566 61e1
6463 e0b2 cca2 dd20 bad2 6bd2 5939 9118
bd80 53ee 5a6d b4b9 8173 2c57 5576 ffd9
457f 86e8 4bab b57f ff93 6ace 5608 8696

Am I doing thing wrong?我做错了吗?

Result from browser download (partial):浏览器下载结果(部分):

d8:announce43:udp://tracker.coppersurfer.tk:6969/announce13:announce-listll43:udp://tracker.coppersurfer.tk:6969/announceel44:udp://tracker.openbittorrent.com:80/announceel34:udp://glotorrents.pw:6969/announceel38:udp://tracker.publicbt.com:80/announceel44:http://ipv6.torrent.ubuntu.com:6969/announceel39:http://torrent.ubuntu.com:6969/announceee7:comment61:Torrent downloaded from torrent cache at http://torcache.net/13:creation datei1445507299e4:infod6:lengthi1178386432e4:name30:ubuntu-15.10-desktop-amd64.iso12:piece lengthi524288e6:pieces44960:iš-Ø"ê^²\ÔäHÅèSºÕ±lìq§USwýÝó¾–­oøÿJ³›PƒIIYd¹©ÝÈûäÐ

You're piping Buffer object (bytes array, res ), that's why you have a long hexadecimal chain in your output file. 您正在传递Buffer对象(字节数组, res ),这就是为什么输出文件中有一个十六进制长链的原因。 Also, when you pipe to a file, it overwrites it, what you have is the last chunk downloaded. 同样,当您通过管道传输到文件时,文件将覆盖它,您拥有的是最后下载的块。 Try like this: 尝试这样:

request.get({
    url: url,
    // very important, it tells request to NOT try to parse the data, useful for binary data
    encoding: null,
    // torcache gzip the torrent file. When piping, request doesn't decompress automically the response
    gzip: true
}).pipe(file); // you can pipe directly to your file, no need to listen to an event

d8:announce42:udp://tracker.opentrackr.org:1337/announce13:announce-listll42:udp://tracker.opentrackr.org:1337/announceel49:udp://tracker.leechers-paradise.org:6969/ notifyel30:udp://9.rarbg.to:2710/announceel34:udp://p4p.arenabg.ch:1337/announceel38:udp://tracker.cyberia.is:6969/announceel36: http://p4p. areabg.com:1337/announceel48:udp://tracker.internetwarriors.net:1337/announceee7:comment70:Torrent下载自https://yts.mx (前 yts.Lt/yts.am/yts.ag)10:创建者 64:Torrent RW PHP 类 - http://github.com/adriengibrat/torrent-rw13:creation datei1636087493e4:infod5:filesld6:lengthi1846226632e4:pathl60:Hachi.A.Dogs.Tale.2009.1080p.BluRay.x264.AAC5。 1-[YTS.MX].mp4eed6:lengthi358e4:pathl18:YTSProxies.com.txteed6:lengthi53226e4:pathl14: www.YTS.MX.jpgeee4:name56:Hachi A Dogs Tale (2009) [1080p] [BluRay] [5.1] [YTS.MX]12:piece lengthi1802240e6:pieces20500:[衵5F鄏=籘eW兊B

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM