Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upHow can I get total number of seeders and leechers in a swarm. #1529
Comments
This comment has been minimized.
This comment has been minimized.
|
Hey @bubundas17, Unlike trackers which support the scrape extension, you will need to connect to every peer in the swarm in order to gather the total number of active peers and weather a peer is a seeder or leecher. An easy way to gather weather a peer is a seeder or leecher is checking the bitfield against the total number of pieces in the torrent. You can achieve that by doing the following: client.on('torrent', (torrent)=>{
torrent.on('wire', (wire)=>{
wire.on('bitfield', (bitfield)=>{
// Bits set in the bitfield.
var setBits = 0
// Maximum number of bits available to be set with the current field size.
var maxBits = bitfield.buffer.length << 3
// The maximum number of bits which constitutes the whole torrent.
var fullBits = torrent.pieces.length
for(i=0; i<=maxBits; i++){
if(bitfield.get(i)) setBits++
}
var state = fullBits === setBits ? "SEEDER" : "LEECHER";
console.log(`[${torrent.infoHash}][${wire.peerId}] Pieces ${setBits}/${fullBits} - ${state}`)
})
})
})
I personally wouldn't recommend using WebTorrent, instead using the components which WebTorrent uses under the hood ( If you need any more help, feel free to continue to ask here, but as this is a question and not an issue, I'm going to close this. |
This comment has been minimized.
This comment has been minimized.
|
Well, Can you please share the code example with using underlying modules? I wanna extract the total number of seeders and leechers of a magnet link. basically, I am trying to make a torrent crawler using nodejs. which basically index torrent information. |
This comment has been minimized.
This comment has been minimized.
|
Hey @bubundas17, Here's an example which I've thrown together quickly, it can be found here. It works with multiple info hashes but only relies on bitfield information which not all clients provide, you can manually iterate through all the pieces using Hope it helps! |
This comment has been minimized.
This comment has been minimized.
Thank You So much! It helped a lot! |
This comment has been minimized.
This comment has been minimized.
|
well a personal thought. |
This comment has been minimized.
This comment has been minimized.
|
Hey @bubundas17, If a tracker supports the scrape extension, it allows a client to request the number of downloading and complete peers it's tracking. As you asked for a solution to scrape the DHT, not trackers, the DHT does not have a built in way to determine the number of leeches or seeds without individually connecting to each peer returned by the DHT and calculating if they are a seed or leech, which will take a long time to iterate through all the peers returned. If you could give me the infohash of the torrent you're having issues with (assuming it's legal) I'll happily help you troubleshoot it. I had no issues with the sintel infohash or any others I tested it with. All the best, |
This comment has been minimized.
This comment has been minimized.
|
Actually I am trying to make a torrent search engine. I work is almost done. Except the seeder and leechers information. |
This comment has been minimized.
This comment has been minimized.
|
@SlientBot1 How can I get total number of seeders and leechers of a infohash from a tracker with using nodejs? |
How can I get total number of seeders and leechers of a torrent file with webtorrent. I am trying to make a torrent DHT crawler.