BitTorrent tracker utilities for checking availability and querying
Project description
BT_TRACKER_UTILS
DEPRECATED: This package has been renamed to and replaced by torrentlib Please use
pip install torrentliband update your imports. This package will be removed in a future version.Migration:
# Old from bt_tracker_utils import Torrent, Tracker # New from torrentlib import Torrent, Tracker
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(seed, "udp://tracker.torrent.eu.org:451/announce",
peer_id, bt.TrackerEvent.STARTED,
ip_addr = "66.35.68.60", port = 6885)
bt.Query.http(seed, "http://tracker.opentrackr.org:1337/announce",
peer_id, bt.TrackerEvent.STOPPED, timeout = 5,
num_want = 100, key = "0327")
# Smart query with auto-detection
bt.Query.single(seed, "udp://tracker.torrent.eu.org:451/announce",
peer_id, bt.TrackerEvent.STARTED,
ip_addr = "66.35.68.60", port = 6885)
bt.Query.single(seed, "http://nyaa.tracker.wf:7777/announce",
peer_id, bt.TrackerEvent.NONE,
left = 1145141919810, downloaded = 0, uploaded = 1048576)
Full parameters
class query
def single(info_hash: str,
url: 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 outBadRequestError: Invalid request parametersInvalidResponseError: Malformed tracker responseUnexpectedError: Network or other unexpected errors
References and Further Reading
License
This project is licensed under the MIT License - see the LICENSE file for details.
Created by JackyHe398 穢 2025
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bt_tracker_utils-0.1.3.tar.gz.
File metadata
- Download URL: bt_tracker_utils-0.1.3.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bd84e18945b8e7a86181e717b10a2283f32148e9b0d7462b60efd036b2b2562
|
|
| MD5 |
b27d88278020ca5b77a4ea88a3e8208a
|
|
| BLAKE2b-256 |
1136c60210f363c0bcb2e91183714c40d72ef91b74289746116a4029a3ab1e14
|
File details
Details for the file bt_tracker_utils-0.1.3-py3-none-any.whl.
File metadata
- Download URL: bt_tracker_utils-0.1.3-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
049bc9ed61685257c8cdd9d698bd11d019a9c52e38b613c01fc0fd8157646623
|
|
| MD5 |
7bed61fa6ff8af10037a8bfc8f509f95
|
|
| BLAKE2b-256 |
87e62bb62373031c94223755e785ea31a8b1c2b4a14446a3fb26a7fea24ea8ec
|