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
61b057505a
commit
af5873f37a
@ -18,8 +18,8 @@ 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
|
|
||||||
|
|
||||||
|
|
||||||
# convert byte units
|
# convert byte units
|
||||||
@ -48,21 +48,26 @@ def human_bytes(bites: int) -> str:
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = docopt(__doc__) # type: ignore
|
args = docopt(__doc__) # type: ignore
|
||||||
|
|
||||||
# Initialize client and login
|
|
||||||
qb = Client(args["HOSTNAME"])
|
|
||||||
qb.login(username=args["USERNAME"], password=args["PASSWORD"])
|
|
||||||
|
|
||||||
# get total_completed_bytes
|
|
||||||
completed_torrent_sizes = []
|
completed_torrent_sizes = []
|
||||||
for torrent in qb.torrents():
|
total_added_bytes = int()
|
||||||
if torrent["completion_on"] != 0: # type: ignore
|
|
||||||
completed_torrent_sizes.append(torrent["total_size"]) # type: ignore
|
with qbittorrentapi.Client(
|
||||||
|
host=args["HOSTNAME"], username=args["USERNAME"], password=args["PASSWORD"]
|
||||||
|
) as qbt_client:
|
||||||
|
try:
|
||||||
|
qbt_client.auth_log_in()
|
||||||
|
except qbittorrentapi.LoginFailed as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
for torrent in qbt_client.torrents_info():
|
||||||
|
if torrent.completion_on != 0:
|
||||||
|
completed_torrent_sizes.append(torrent.total_size)
|
||||||
|
|
||||||
|
total_added_bytes = sum(
|
||||||
|
[torrent.total_size for torrent in qbt_client.torrents_info()]
|
||||||
|
)
|
||||||
|
|
||||||
total_completed_bytes = sum(completed_torrent_sizes)
|
total_completed_bytes = sum(completed_torrent_sizes)
|
||||||
|
|
||||||
# get total_added_bytes
|
|
||||||
total_added_bytes = sum([torrent["total_size"] for torrent in qb.torrents()]) # type: ignore
|
|
||||||
|
|
||||||
# print the results
|
|
||||||
print(f"\nTotal completed size: {human_bytes(total_completed_bytes)}")
|
print(f"\nTotal completed size: {human_bytes(total_completed_bytes)}")
|
||||||
print(f"Total added size: {human_bytes(total_added_bytes)}\n")
|
print(f"Total added size: {human_bytes(total_added_bytes)}\n")
|
||||||
|
@ -39,9 +39,9 @@ Options:
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import qbittorrentapi
|
||||||
import requests
|
import requests
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
from qbittorrent import Client
|
|
||||||
|
|
||||||
|
|
||||||
def get_torrent_health_data() -> list[dict]:
|
def get_torrent_health_data() -> list[dict]:
|
||||||
@ -62,6 +62,8 @@ def convert_size_to_bytes(size: str) -> int:
|
|||||||
|
|
||||||
Example: 42G --> 45097156608 bytes
|
Example: 42G --> 45097156608 bytes
|
||||||
"""
|
"""
|
||||||
|
total_bytes = int()
|
||||||
|
|
||||||
if size.endswith("T"):
|
if size.endswith("T"):
|
||||||
total_bytes = int(size.split("T")[0]) * (1024**4)
|
total_bytes = int(size.split("T")[0]) * (1024**4)
|
||||||
|
|
||||||
@ -157,8 +159,14 @@ if __name__ == "__main__":
|
|||||||
dry_run = args["--dry-run"]
|
dry_run = args["--dry-run"]
|
||||||
|
|
||||||
# Initialize client and login
|
# Initialize client and login
|
||||||
qb = Client(hostname)
|
qbt_client = qbittorrentapi.Client(
|
||||||
qb.login(username=username, password=password)
|
host=hostname, username=username, password=password
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
qbt_client.auth_log_in()
|
||||||
|
except qbittorrentapi.LoginFailed as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
# Fill the knapsack
|
# Fill the knapsack
|
||||||
knapsack = fill_knapsack(max_seeders, knapsack_size, smaller)
|
knapsack = fill_knapsack(max_seeders, knapsack_size, smaller)
|
||||||
@ -183,13 +191,15 @@ if __name__ == "__main__":
|
|||||||
for torrent in knapsack:
|
for torrent in knapsack:
|
||||||
if "gen.lib.rus.ec" in torrent["link"]:
|
if "gen.lib.rus.ec" in torrent["link"]:
|
||||||
new_torrent = torrent["link"].replace("gen.lib.rus.ec", "libgen.is")
|
new_torrent = torrent["link"].replace("gen.lib.rus.ec", "libgen.is")
|
||||||
qb.download_from_link(new_torrent, category="scihub")
|
qbt_client.torrents_add(new_torrent, category="scihub")
|
||||||
|
|
||||||
if "libgen.rs" in torrent["link"]:
|
if "libgen.rs" in torrent["link"]:
|
||||||
new_torrent = torrent["link"].replace("libgen.rs", "libgen.is")
|
new_torrent = torrent["link"].replace("libgen.rs", "libgen.is")
|
||||||
qb.download_from_link(new_torrent, category="scihub")
|
qbt_client.torrents_add(new_torrent, category="scihub")
|
||||||
# print(f"Added {torrent['name']}")
|
# print(f"Added {torrent['name']}")
|
||||||
|
|
||||||
|
qbt_client.auth_log_out()
|
||||||
|
|
||||||
print("----------------")
|
print("----------------")
|
||||||
print(f"Count: {len(knapsack)} torrents")
|
print(f"Count: {len(knapsack)} torrents")
|
||||||
print(f"Total combined size: {get_knapsack_weight(knapsack)}")
|
print(f"Total combined size: {get_knapsack_weight(knapsack)}")
|
||||||
|
Loading…
Reference in New Issue
Block a user