Last active
January 12, 2021 14:45
-
-
Save xNihil0/d656a642640d66b623fadfd8491af92a to your computer and use it in GitHub Desktop.
批量强制汇报下载中种子
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
import qbittorrentapi | |
import psutil | |
import time | |
# host 填写你的 qBittorrent WebUI 地址, 默认本地 localhost | |
# port 填写你的 qBittorrent WebUI 端口 | |
# username 填写你的 qBittorrent WebUI 用户名 | |
# password 填写你的 qBittorrent WebUI 密码 | |
# ul_threshold 填写上行阈值 (单位: KiB/s) | |
# interval 填写测速采样间隔 (单位: sec) | |
host = r'localhost' | |
port = 5100 | |
username = r'' | |
password = r'' | |
ul_threshold = 81920 | |
interval = 5 | |
def get_rate(): | |
last = psutil.net_io_counters() | |
time.sleep(interval) | |
now = psutil.net_io_counters() | |
ul = (now.bytes_sent - last.bytes_sent) / interval / 1024 | |
dl = (now.bytes_recv - last.bytes_recv) / interval / 1024 | |
return ul, dl | |
if __name__ == "__main__": | |
qbt_client = qbittorrentapi.Client(host, port, username, password) | |
try: | |
qbt_client.auth_log_in() | |
except qbittorrentapi.LoginFailed as e: | |
print(e) | |
cnt = 0 | |
ul, dl = get_rate() | |
print(f"Current rate: DL {dl} KiB/s, UL {ul} KiB/s.") | |
for torrent in qbt_client.torrents_info(): | |
if torrent.state_enum.is_downloading: | |
torrent.reannounce() | |
print(f"{torrent.hash} reannounced.") | |
cnt += 1 | |
if torrent.state_enum.is_uploading and ul < ul_threshold: | |
torrent.reannounce() | |
print(f"{torrent.hash} reannounced.") | |
cnt += 1 | |
print() | |
print(f"{cnt} torrent(s) reannounced.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment