diff --git a/qbtools/commands/prune.py b/qbtools/commands/prune.py index d19cf17..ae3f71b 100644 --- a/qbtools/commands/prune.py +++ b/qbtools/commands/prune.py @@ -7,18 +7,18 @@ def __init__(args, logger): client = qbtools.qbit_client(args) categories = list(client.torrent_categories.categories.keys()) - if len(args.include_category) > 0: + if args.include_category: includes = [i for s in args.include_category for i in s] categories = list( filter(lambda c: any(fnmatch(c, p) for p in includes), categories) ) - if len(args.exclude_category) > 0: + if args.exclude_category: excludes = [i for s in args.exclude_category for i in s] categories = list( filter(lambda c: not any(fnmatch(c, p) for p in excludes), categories) ) - if len(categories) == 0: + if not categories: logger.info( f"No torrents can be pruned since no categories were included based on selectors" ) @@ -29,12 +29,12 @@ def __init__(args, logger): ) include_tags = [i for s in args.include_tag for i in s] - if len(include_tags): + if include_tags: filtered_torrents = list( filter(lambda x: all(y in x.tags for y in include_tags), filtered_torrents) ) exclude_tags = [i for s in args.exclude_tag for i in s] - if len(exclude_tags): + if exclude_tags: filtered_torrents = list( filter( lambda x: not any(y in x.tags for y in exclude_tags), filtered_torrents diff --git a/qbtools/commands/reannounce.py b/qbtools/commands/reannounce.py index da5b904..6c7ae7d 100755 --- a/qbtools/commands/reannounce.py +++ b/qbtools/commands/reannounce.py @@ -21,21 +21,21 @@ def process_torrents(status): torrents_retries.clear() for t in torrents: - invalid_trackers = list(filter(lambda s: s.status == 4, t.trackers)) - if not invalid_trackers: + not_working = list(filter(lambda s: s.status == 4, t.trackers)) + if not not_working: continue peers = t.num_seeds + t.num_leechs - if peers > 0: - logger.debug("Torrent %s already has %d peer(s) - not reannouncing", t.name, peers) + if peers: + logger.debug("Torrent %s (%s) has %d peer(s) - not reannouncing", t.name, t.hash, peers) continue torrent_retries = torrents_retries.get(t.hash, 0) if torrent_retries >= max_tries: - logger.debug("Torrent %s has reached %s reannounce tries - not reannouncing", t.name, retries) + logger.debug("Torrent %s (%s) has reached %s reannounce tries - not reannouncing", t.name, t.hash, retries) continue - logger.info("Reannouncing torrent %s (%s)", t.name, t.hash) + logger.info("Reannouncing torrent %s (%s) %s/%s ...", t.name, t.hash, torrent_retries, max_tries) t.reannounce() torrents_retries[t.hash] = torrent_retries + 1 diff --git a/qbtools/commands/tagging.py b/qbtools/commands/tagging.py index b6642a0..1692ebe 100755 --- a/qbtools/commands/tagging.py +++ b/qbtools/commands/tagging.py @@ -44,8 +44,6 @@ MAINTENANCE_MATCHES = ["tracker is down", "maintenance"] -DHT_MATCHES = ["** [DHT] **", "** [PeX] **", "** [LSD] **"] - def __init__(args, logger): logger.info(f"Tagging torrents in qBittorrent...") @@ -62,11 +60,11 @@ def __init__(args, logger): filtered_torrents = client.torrents.info() exclude_categories = [i for s in args.exclude_category for i in s] exclude_tags = [i for s in args.exclude_tag for i in s] - if len(exclude_categories): + if exclude_categories: filtered_torrents = list( filter(lambda x: x.category not in exclude_categories, filtered_torrents) ) - if len(exclude_tags): + if exclude_tags: filtered_torrents = list( filter( lambda x: any(y not in x.tags for y in exclude_tags), filtered_torrents @@ -77,8 +75,7 @@ def __init__(args, logger): for t in filtered_torrents: tags_to_add = [] - # TODO: Optimize - this slows down the script a lot - filtered_trackers = list(filter(lambda s: not s.url in DHT_MATCHES, t.trackers)) + filtered_trackers = list(filter(lambda s: not s.status == 0, t.trackers)) if not filtered_trackers: continue domain = extractTLD(