Skip to main content

BitTorrent tracker utilities for checking availability and querying

Project description

BT_TRACKER_UTILS

Introduction

This is a utility library for checking tracker status and querying tracker in different protocols.

Features

  • Check Tracker Status: Verify if a tracker is online and responsive.
  • Concurrent Queries: Perform multiple tracker queries simultaneously.
  • UDP and HTTP Protocols: Support for both UDP and HTTP tracker protocols.
  • Full Param Support: Allows for full parameter customization in tracker queries.

Installation

pip install bt_tracker_utils

Usage Example - Check status

from bt_tracker_utils import check_trackers, check_tracker, CheckTracker
timeout = 5  # seconds

# Check single tracker
CheckTracker.udp("udp://tracker.example.com:8080/announce", timeout=timeout)
CheckTracker.http("http://tracker.example.com:8080/announce", timeout=timeout)

check_tracker("http://tracker.example.com:8080/announce", timeout=timeout) # smart checking, identifies protocol automatically

 
# Check multiple trackers
with open("trackers.txt", "r") as f:
    urls = []
    for line in f:
        line = line.strip()
        urls.append(line)
check_trackers(urls, timeout=timeout)

Usage Example - Query Tracker:

import bt_tracker_utils as bt

seed = "8a19577fb5f690970ca43a57ff1011ae202244b8"
peer_id = "-robots-testing12345"

# specifying protocols
bt.Query.udp("udp://tracker.torrent.eu.org:451/announce",
         seed, peer_id,
         bt.TrackerEvent.STARTED,
         ip_addr = "66.35.68.60", port = 6885)

bt.Query.http("http://tracker.opentrackr.org:1337/announce",
         seed, peer_id,
         bt.TrackerEvent.STOPPED, timeout = 5,
         num_want = 100, key = "0327")

# Smart query with auto-detection
query("http://nyaa.tracker.wf:7777/announce",
      seed, peer_id,
      bt.TrackerEvent.NONE,
      left = 1145141919810, downloaded = 0, uploaded = 1048576)

Full parameters

def query(url: str,
            info_hash: str,
            peer_id: str,  
            event: TrackerEvent, 
            left = 0, downloaded = 0, uploaded = 0, 
            ip_addr: str|None = None,
            num_want = None, key = None,
            port: int|None = None, headers = None,
            timeout: int = 5) -> Dict[str, Any]:

Force:

  • info_hash: A 20-byte info hash of the torrent.
  • peer_id: A 20-byte peer ID of the client.
  • event(type: TrackerEvent): The status of download (NONE, STARTED, STOPPED, COMPLETED).

Recommended:

  • left: The number of bytes left to download.
  • downloaded: The number of bytes downloaded.
  • uploaded: The number of bytes uploaded.
  • ip_addr: The IP address of the client (for UDP).
  • port: The port number of the client (for UDP).

Optional:

  • num_want: The number of peers to return (default: 50).
  • key: A unique key for the request. Tracker can use this to recognize the client even if a different machine is used.
  • headers: Additional HTTP headers for the request. If UDP is used, this field will be ignored.
  • timeout: The timeout for the request in seconds (default: 5s).

Return Values:

The query function returns a dictionary containing the following. Note that values can be None(for required fields) or not present(for optional fields) if the response does not contain that field:

Optional fields:

  • failure reason: If this field is present, all the other fields will not exist.
  • warning message: This field do not affect the other fields.

Required fields:

  • interval: The interval in seconds for the next query.
  • min interval: The minimum interval in seconds for the next query, query should not be made more frequently than this.
  • leechers: The number of peers currently downloading the torrent.
  • seeders: The number of peers currently seeding the torrent.
  • peers: A list of tuple, storing (ip, port) for each peer.
  • peers6: A list of tuple, storing (ip, port) for each peer in IPv6 format.

Error Handling

The library raises specific exceptions for different error conditions:

from bt_tracker_utils import query, TrackerEvent, TrackerQueryException

try:
    result = query(url, info_hash, peer_id, TrackerEvent.STARTED)
except TrackerQueryException as e:
    print(f"Tracker error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Exception Types

  • TimeoutError: Request timed out
  • BadRequestError: Invalid request parameters
  • InvalidResponseError: Malformed tracker response
  • UnexpectedError: Network or other unexpected errors

References and Further Reading

Wikipedia CSDN Theory Wiki Concurrency Deep Dives XBTT

License

This project is licensed under the MIT License - see the LICENSE file for details.

Created by JackyHe398 穢 2025

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bt_tracker_utils-0.1.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bt_tracker_utils-0.1.1-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file bt_tracker_utils-0.1.1.tar.gz.

File metadata

  • Download URL: bt_tracker_utils-0.1.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for bt_tracker_utils-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b906256c9cbe593a1acefce23e3139a82ba41395b12f0563173c263816ecec4e
MD5 81aec08679a30f3174084805ec9811cd
BLAKE2b-256 a6776cfce0df71bcbd246739a69750cb0b75566bf8f03bf48bd93e191ee38942

See more details on using hashes here.

File details

Details for the file bt_tracker_utils-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bt_tracker_utils-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac777952181f1988acb2a52ac7ac4298081a2224df74cb935edadf486e135cde
MD5 3191549c7eed78da0b55c1a97b3103ec
BLAKE2b-256 0a1a4194f504ed3f76a41f2412cb537cf71dc5a869394d5a9fb5aff2852bc189

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page