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
38ffe9e963
commit
70740ba949
@ -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,34 +52,39 @@ 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(
|
||||||
|
host="localhost", port=8080, username="", password=""
|
||||||
|
) as qbt_client:
|
||||||
|
sorted_torrents = sorted(
|
||||||
|
qbt_client.torrents_info(), key=lambda d: d.ratio, reverse=True
|
||||||
|
)
|
||||||
for torrent in sorted_torrents:
|
for torrent in sorted_torrents:
|
||||||
row = []
|
row = []
|
||||||
row.append(torrent["name"]) # type: ignore
|
row.append(torrent.name)
|
||||||
row.append(human_bytes(int(torrent["total_size"]))) # type: ignore
|
row.append(human_bytes(torrent.total_size))
|
||||||
row.append(torrent["trackers_count"]) # type: ignore
|
row.append(torrent.trackers_count)
|
||||||
row.append(torrent["ratio"]) # type: ignore
|
row.append(torrent.ratio)
|
||||||
row.append(human_bytes(int(torrent["uploaded"]))) # type: ignore
|
row.append(human_bytes(torrent.uploaded))
|
||||||
table.append(row)
|
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(
|
||||||
|
qbt_client.torrents_info(), key=lambda d: d.ratio, reverse=True
|
||||||
|
)
|
||||||
for torrent in sorted_torrents:
|
for torrent in sorted_torrents:
|
||||||
name = torrent["name"] # type: ignore
|
name = torrent.name
|
||||||
size = human_bytes(int(torrent["total_size"])) # type: ignore
|
size = human_bytes(torrent.total_size)
|
||||||
trackers = torrent["trackers_count"] # type: ignore
|
trackers = torrent.trackers_count
|
||||||
ratio = torrent["ratio"] # type: ignore
|
ratio = torrent.ratio
|
||||||
uploaded = human_bytes(int(torrent["uploaded"])) # type: ignore
|
uploaded = human_bytes(torrent.uploaded)
|
||||||
print(f"{name} {size} {trackers} {ratio} {uploaded}")
|
print(f"{name} {size} {trackers} {ratio} {uploaded}")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user