mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-25 09:03:41 +01:00
Use qbittorrentapi
This commit is contained in:
parent
1c4d3cd333
commit
61b057505a
@ -28,8 +28,8 @@ import subprocess
|
|||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import qbittorrentapi
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
from qbittorrent import Client
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
@ -53,11 +53,18 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
torrent_infohashes = []
|
torrent_infohashes = []
|
||||||
for item in auth_data["instances"]:
|
for item in auth_data["instances"]:
|
||||||
qb = Client(item["hostname"])
|
with qbittorrentapi.Client(
|
||||||
qb.login(username=item["username"], password=item["password"])
|
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():
|
for torrent in qbt_client.torrents_info():
|
||||||
torrent_infohashes.append(torrent.get("hash")) # type: ignore
|
torrent_infohashes.append(torrent.hash)
|
||||||
|
|
||||||
# Format the infohashes to have a \n at the end
|
# Format the infohashes to have a \n at the end
|
||||||
console.log("Formatting infohashes to have a newline 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
|
# Reannounce all torrents in each qBittorrent instance to their trackers
|
||||||
console.log("Reannouncing all torrents to their trackers.")
|
console.log("Reannouncing all torrents to their trackers.")
|
||||||
for item in auth_data["instances"]:
|
for item in auth_data["instances"]:
|
||||||
qb = Client(item["hostname"])
|
with qbittorrentapi.Client(
|
||||||
qb.login(username=item["username"], password=item["password"])
|
host=item["hostname"],
|
||||||
torrent_infohashes = [torrent.get("hash") for torrent in qb.torrents()] # type: ignore
|
username=item["username"],
|
||||||
qb.reannounce(torrent_infohashes)
|
password=item["password"],
|
||||||
|
) as qbt_client:
|
||||||
|
for torrent in qbt_client.torrents_info():
|
||||||
|
torrent.reannounce(torrent.hash)
|
||||||
|
|
||||||
console.log("Done!")
|
console.log("Done!")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user