From 61b057505a3cace7175375fbdb78cb95a6f2afd5 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio Date: Tue, 5 Nov 2024 17:59:30 -0600 Subject: [PATCH] Use qbittorrentapi --- update_tracker.py | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/update_tracker.py b/update_tracker.py index 958ec69..49a4f37 100755 --- a/update_tracker.py +++ b/update_tracker.py @@ -28,8 +28,8 @@ import subprocess import tempfile from pathlib import Path +import qbittorrentapi from docopt import docopt -from qbittorrent import Client from rich.console import Console from rich.text import Text @@ -53,11 +53,18 @@ if __name__ == "__main__": ) torrent_infohashes = [] for item in auth_data["instances"]: - qb = Client(item["hostname"]) - qb.login(username=item["username"], password=item["password"]) + with qbittorrentapi.Client( + host=item["hostname"], + username=item["username"], + password=item["password"], + ) as qbt_client: + try: + qbt_client.auth_log_in() + except qbittorrentapi.LoginFailed as e: + print(e) - for torrent in qb.torrents(): - torrent_infohashes.append(torrent.get("hash")) # type: ignore + for torrent in qbt_client.torrents_info(): + torrent_infohashes.append(torrent.hash) # Format the infohashes to have a \n at the end console.log("Formatting infohashes to have a newline at the end.") @@ -97,28 +104,16 @@ if __name__ == "__main__": ] ) - # Ensure {tracker_domain}:6969/announce is added to each torrent's - # tracker list. - if tracker_domain: - console.log( - f"Ensuring {tracker_domain}:6969/announce is added to each torrent's tracker list." - ) - for item in auth_data["instances"]: - qb = Client(item["hostname"]) - qb.login(username=item["username"], password=item["password"]) - for torrent in qb.torrents(): - qb.add_trackers( - torrent.get("hash"), # type: ignore - f"http://{tracker_domain}:6969/announce\nudp://{tracker_domain}:6969/announce", - ) - # Reannounce all torrents in each qBittorrent instance to their trackers console.log("Reannouncing all torrents to their trackers.") for item in auth_data["instances"]: - qb = Client(item["hostname"]) - qb.login(username=item["username"], password=item["password"]) - torrent_infohashes = [torrent.get("hash") for torrent in qb.torrents()] # type: ignore - qb.reannounce(torrent_infohashes) + with qbittorrentapi.Client( + host=item["hostname"], + username=item["username"], + password=item["password"], + ) as qbt_client: + for torrent in qbt_client.torrents_info(): + torrent.reannounce(torrent.hash) console.log("Done!")