From d8e7086d3528cfafd22147d31d8c09cb1495c989 Mon Sep 17 00:00:00 2001 From: AJ Date: Tue, 3 May 2022 17:43:49 -0400 Subject: [PATCH] Limit seeding by changing ratio. This way all torrents have a minimum seed ratio of 2.0 --- start-seeding.py | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/start-seeding.py b/start-seeding.py index 29b8455..07a49d5 100644 --- a/start-seeding.py +++ b/start-seeding.py @@ -10,46 +10,44 @@ qbt_client = qbittorrentapi.Client( password='adminadmin', ) -max_seeds = 25 +unlimited_seed_threshold = 25 def login(): - # the Client will automatically acquire/maintain a logged-in state - # in line with any request. therefore, this is not strictly necessary; - # however, you may want to test the provided login credentials. try: qbt_client.auth_log_in() except qbittorrentapi.LoginFailed as e: print(e) - # display qBittorrent info print(f'qBittorrent: {qbt_client.app.version}') print(f'qBittorrent Web API: {qbt_client.app.web_api_version}') - # for k,v in qbt_client.app.build_info.items(): print(f'{k}: {v}') -def dostuff(): +def set_ratio_limits(): for torrent in qbt_client.torrents.info.all(): if torrent.state_enum.is_downloading: continue - if torrent.num_complete > max_seeds: - torrent.pause() - else: - torrent.resume() + # -2 = use the global value + # -1 = no limit + x = -2 -def update_seed_count(): - qbt_client.torrents.resume.all() - print('Waiting 30 seconds for seeds to update...') - time.sleep(30) + if torrent.num_complete <= unlimited_seed_threshold: + x = -1 -logfile = open(r"log.txt", "a") + if x == torrent.ratio_limit: + continue + + torrent.set_share_limits(ratio_limit=x, seeding_time_limit=-2) + torrent.resume() + + log(f'{torrent.name}: set ratio limit to \'{torrent.ratio_limit}\'') + + +logfile = open(r"C:\Tools\qbittorrent\log.txt", "a") def log(msg): - logfile.write('[{}] {}\n'.format(datetime.datetime.now(), msg)) + logfile.write(f'[{datetime.datetime.now()}] {msg}\n') logfile.flush() print(msg) -log("starting") login() -update_seed_count() -dostuff() -log("done") +set_ratio_limits()