admin-scripts/bin/add_qbt_trackers.py

48 lines
1.4 KiB
Python
Raw Normal View History

2024-07-29 08:47:54 +02:00
#!/usr/bin/env python3
"""add_qbt_trackers.py
Description:
This script fetches torrent tracker URLs from plaintext lists hosted on the web
and adds them to each torrent in a qBittorrent instance.
Usage:
add_qbt_trackers.py (HOSTNAME) (USERNAME) (PASSWORD)
add_qbt_trackers.py -h
Examples:
add_qbt_trackers.py "http://localhost:8080" "admin" "adminadmin"
Options:
-h, --help show this help message and exit
"""
import requests
from docopt import docopt
from qbittorrent import Client
if __name__ == "__main__":
2024-07-31 02:44:14 +02:00
args = docopt(__doc__) # type: ignore
2024-07-29 08:47:54 +02:00
# Initialize client and login
qb = Client(args["HOSTNAME"])
qb.login(username=args["USERNAME"], password=args["PASSWORD"])
live_trackers_list_urls = [
"https://newtrackon.com/api/stable",
"https://trackerslist.com/best.txt",
"https://trackerslist.com/http.txt",
"https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt",
]
combined_trackers_urls = []
for url in live_trackers_list_urls:
response = requests.get(url, timeout=60)
tracker_urls = [x for x in response.text.splitlines() if x != ""]
combined_trackers_urls.extend(tracker_urls)
for torrent in qb.torrents():
2024-07-30 21:00:24 +02:00
for tracker in combined_trackers_urls:
2024-07-31 02:44:14 +02:00
qb.add_trackers(torrent.get("hash"), f"{tracker}\n") # type: ignore
print(f"Added {tracker} to {torrent.get('name')}") # type: ignore