Use qbittorrentapi

This commit is contained in:
Jeffrey Serio 2024-11-05 16:46:23 -06:00
parent 38ffe9e963
commit 70740ba949

View File

@ -15,10 +15,18 @@ Options:
-h, --help show this help message and exit -h, --help show this help message and exit
""" """
import qbittorrentapi
from docopt import docopt from docopt import docopt
from qbittorrent import Client
from tabulate import tabulate from tabulate import tabulate
try:
with qbittorrentapi.Client(
host="localhost", port=8080, username="", password=""
) as qbt_client:
qbt_client.auth_log_in()
except qbittorrentapi.LoginFailed as e:
print(e)
# convert byte units # convert byte units
def human_bytes(input_bytes: int) -> str: def human_bytes(input_bytes: int) -> str:
@ -44,35 +52,40 @@ def human_bytes(input_bytes: int) -> str:
def print_table(): def print_table():
qb = Client("http://localhost:8080/")
qb.login()
table = [] table = []
headers = ["Name", "Total Size", "Trackers Count", "Ratio", "Uploaded"] headers = ["Name", "Total Size", "Trackers Count", "Ratio", "Uploaded"]
sorted_torrents = sorted(qb.torrents(), key=lambda d: d["ratio"], reverse=True) # type: ignore with qbittorrentapi.Client(
for torrent in sorted_torrents: host="localhost", port=8080, username="", password=""
row = [] ) as qbt_client:
row.append(torrent["name"]) # type: ignore sorted_torrents = sorted(
row.append(human_bytes(int(torrent["total_size"]))) # type: ignore qbt_client.torrents_info(), key=lambda d: d.ratio, reverse=True
row.append(torrent["trackers_count"]) # type: ignore )
row.append(torrent["ratio"]) # type: ignore for torrent in sorted_torrents:
row.append(human_bytes(int(torrent["uploaded"]))) # type: ignore row = []
table.append(row) row.append(torrent.name)
row.append(human_bytes(torrent.total_size))
row.append(torrent.trackers_count)
row.append(torrent.ratio)
row.append(human_bytes(torrent.uploaded))
table.append(row)
print(tabulate(table, headers, tablefmt="grid")) print(tabulate(table, headers, tablefmt="grid"))
def print_ssv(): def print_ssv():
qb = Client("http://localhost:8080/") with qbittorrentapi.Client(
qb.login() host="localhost", port=8080, username="", password=""
sorted_torrents = sorted(qb.torrents(), key=lambda d: d["ratio"], reverse=True) # type: ignore ) as qbt_client:
print("Name Size Trackers Ratio Uploaded") sorted_torrents = sorted(
for torrent in sorted_torrents: qbt_client.torrents_info(), key=lambda d: d.ratio, reverse=True
name = torrent["name"] # type: ignore )
size = human_bytes(int(torrent["total_size"])) # type: ignore for torrent in sorted_torrents:
trackers = torrent["trackers_count"] # type: ignore name = torrent.name
ratio = torrent["ratio"] # type: ignore size = human_bytes(torrent.total_size)
uploaded = human_bytes(int(torrent["uploaded"])) # type: ignore trackers = torrent.trackers_count
print(f"{name} {size} {trackers} {ratio} {uploaded}") ratio = torrent.ratio
uploaded = human_bytes(torrent.uploaded)
print(f"{name} {size} {trackers} {ratio} {uploaded}")
if __name__ == "__main__": if __name__ == "__main__":