Created
October 12, 2021 02:21
-
-
Save MewX/b51455cf8bb19806b57fcca306a51b1c to your computer and use it in GitHub Desktop.
deluge jump car
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
import deluge_client | |
import time | |
import logging | |
import traceback | |
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" | |
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) | |
client = deluge_client.DelugeRPCClient("10.0.0.1", 53274, "xxxxxxx", "xxxxxxxxxx") | |
client.connect() | |
logging.info("is connected: {}".format(client.connected)) | |
assert client.connected | |
def check(t, tracker): | |
return t[:len(tracker)] == tracker | |
def get_self_progress(torrent): | |
return torrent[b"progress"] / 100 | |
def get_global_progress(torrent): | |
progress_lists = sorted([p[b"progress"] for p in torrent[b"peers"]]) | |
return 0 if len(progress_lists) <= 2 else progress_lists[-3] | |
def is_lagged(torrent): | |
return get_self_progress(torrent) + 0.04 < get_global_progress(torrent) | |
tlist = list(client.core.get_torrents_status({"state":"Downloading"}, | |
["hash", "download_payload_rate", "upload_payload_rate", "peers", "progress", "name", "total_uploaded", "total_done"]).values()) | |
dl_speed = sum([t[b"download_payload_rate"] for t in tlist]) / (1024**2) | |
up_speed = sum([t[b"upload_payload_rate"] for t in tlist]) / (1024**2) | |
free_space = client.core.get_free_space() | |
logging.info("global speed: DL %.3f MB/s UL %.3f MB/s %.3f GB space left on disk" % (dl_speed, up_speed, free_space/1024**3)) | |
delete_seeds = [] | |
for t in tlist: | |
print("self: {:.3f} global {:.3f} {}".format(get_self_progress(t), get_global_progress(t), t[b"name"].decode("utf-8"))) | |
lagged = list(filter(is_lagged, tlist)) | |
if len(lagged) >= 2: | |
delete_seeds += lagged | |
if len(delete_seeds) > 0: | |
return_v = client.core.pause_torrent([t[b"hash"] for t in delete_seeds]) | |
logging.info("num of paused seeds: {}".format(len(delete_seeds))) | |
for t in delete_seeds: | |
logging.info("pause {} ratio {:.3f} {:.3f} GB / {:.3f} GB".format(t[b"name"].decode("utf-8"), | |
t[b"total_uploaded"] / t[b"total_done"], | |
t[b"total_uploaded"]/(1024**3), t[b"total_done"]/(1024**3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment