Use qbittorrentapi

This commit is contained in:
Jeffrey Serio 2024-11-05 17:59:30 -06:00
parent 1c4d3cd333
commit 61b057505a

View File

@ -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!")