To accomplish this task, we need to interact with the qBittorrent Web API. The plan involves:
- Authenticating with the qBittorrent Web API.
- Retrieving the list of torrents.
- Identifying torrents with the tracker message "unregistered torrent".
- Pausing those specific torrents.
Here's a Python script to do this using the requests library:
import requests
# Configuration
QB_API_BASE_URL = 'http://localhost:8080/api/v2'
QB_USERNAME = 'your_username'
QB_PASSWORD = 'your_password'
# Authenticate and get session
def authenticate():
login_url = f"{QB_API_BASE_URL}/auth/login"
data = {
'username': QB_USERNAME,
'password': QB_PASSWORD
}
session = requests.Session()
response = session.post(login_url, data=data)
if response.status_code == 200:
return session
else:
raise Exception("Failed to authenticate with qBittorrent API")
# Get list of torrents
def get_torrents(session):
torrents_url = f"{QB_API_BASE_URL}/torrents/info"
response = session.get(torrents_url)
response.raise_for_status()
return response.json()
# Pause a specific torrent by hash
def pause_torrent(session, torrent_hash):
pause_url = f"{QB_API_BASE_URL}/torrents/pause"
response = session.post(pause_url, data={'hashes': torrent_hash})
response.raise_for_status()
# Main function
def main():
session = authenticate()
torrents = get_torrents(session)
for torrent in torrents:
for tracker in torrent['trackers']:
if tracker['msg'] == 'unregistered torrent':
print(f"Pausing torrent: {torrent['name']} (Hash: {torrent['hash']})")
pause_torrent(session, torrent['hash'])
break
if __name__ == "__main__":
main()
Instructions to Run the Script:
- Make sure qBittorrent is running with the Web API enabled (default port 8080).
- Replace
your_username and your_password with your actual qBittorrent Web API credentials.
- Ensure you have the
requests library installed. You can install it via pip:
pip install requests
- Run the script with Python:
python pause_unregistered_torrents.py
This script first authenticates with the qBittorrent Web API. It then retrieves the list of torrents and checks the tracker messages. If a torrent has the tracker message "unregistered torrent", it pauses that torrent by sending a request to the qBittorrent API.
Note: Ensure your qBittorrent WebUI is correctly configured to allow access, and handle any security considerations, such as using HTTPS and securing passwords, to protect your instance from unauthorized access.