From ec0e9acecbb4238b00c06c76a3da1a2d8474c114 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Mon, 29 Jul 2024 01:47:54 -0500 Subject: [PATCH] Add add_qbt_trackers.py --- bin/add_qbt_trackers.py | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 bin/add_qbt_trackers.py diff --git a/bin/add_qbt_trackers.py b/bin/add_qbt_trackers.py new file mode 100755 index 0000000..bc3f456 --- /dev/null +++ b/bin/add_qbt_trackers.py @@ -0,0 +1,47 @@ +#!/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__": + args = docopt(__doc__) + + # 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) + + combined_trackers_urls = [f"{x}\n" for x in combined_trackers_urls] + for torrent in qb.torrents(): + qb.add_trackers(torrent.get("hash"), combined_trackers_urls) # type: ignore + print(f"Added trackers to {torrent.get("name")}") # type: ignore \ No newline at end of file