简体   繁体   中英

How to know the number of seeds/peers for a torrent in PHP

当您将.torrent文件放置在您的网站上以供下载时,您如何获得该 Torrent 的种子和对等点的数量并通知用户?

You have to contact the tracker(s) that is shown in the torrentfile. If the tracker support "scraping" that is probably the request you want. Otherwise its up to the tracker to decide how many peers it wants to return to you, and you have no idea if those peers is a seed or leech before contacting them.

The torrentfile is in bencoded format, look for the bdecode php library to easily parse the info.

Provide the infohash you get from the pieces information in the metadata and the tracker will respond if you follow the protocol, read http://en.wikipedia.org/wiki/BitTorrent_%28protocol%29 for more information

You would scrape the tracker by sending an HTTP GET request to it with a URL formed as described at http://wiki.theory.org/BitTorrentSpecification#Tracker_.27scrape.27_Convention -- the scrape URL is derived from the announce URL(s) in the metainfo's "announce" and "announce-list" keys.

The tracker's response is described in that same wiki.theory.org link. It includes the seeder/leecher counts that you're looking for.

Note that modern .torrent files typically have several trackers included in their announce-list, so you may want to scrape more than one for better information. However you've got no way of knowing which peers overlap from tracker A to tracker B, so the best you can really do from scraping multiple trackers is to come up with a range of the minimum/maximum number of leechers and seeders in the swarm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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