From 74ee1948d271ff5cf0962c25051d5fe07646bb31 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Wed, 26 Jan 2022 21:35:36 +0100 Subject: [PATCH] Warden as main handler for current simple selection logic --- src/warden.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/warden.py diff --git a/src/warden.py b/src/warden.py new file mode 100644 index 0000000..ba80239 --- /dev/null +++ b/src/warden.py @@ -0,0 +1,42 @@ +from pprint import pprint + +def acceptableSeedCount(torrent): + return int(torrent.seed) > 1 + +def unacceptable4K(torrent): + name = torrent.name.lower() + return '2160p' in name or '4k' in name + +def unacceptableSmall(torrent): + cutoff = 6500000000 # 6.5 GB + return torrent.bytes < cutoff + +def unacceptableLarge(torrent): + cutoff = 25000000000 # 25 GB + return torrent.bytes > cutoff + +def findBest(torrents): + if len(torrents) == 0: + return None + + startingLength = len(torrents) + candidates = torrents.copy() + + for torrent in torrents: + if not acceptableSeedCount(torrent): + candidates.remove(torrent) + elif unacceptable4K(torrent): + candidates.remove(torrent) + elif unacceptableSmall(torrent): + candidates.remove(torrent) + elif unacceptableLarge(torrent): + candidates.remove(torrent) + + + candidates = sorted(candidates, reverse=True) + + print('Found {} candidates from {} torrents'.format(len(candidates), startingLength)) + + pprint(candidates) + + return candidates[0] \ No newline at end of file