diff --git a/qbtools/commands/orphaned.py b/qbtools/commands/orphaned.py index 951d069..4a601a7 100644 --- a/qbtools/commands/orphaned.py +++ b/qbtools/commands/orphaned.py @@ -5,7 +5,7 @@ def __init__(app, logger): - logger.info(f"Checking for orphaned files on disk not in qBittorrent...") + logger.info("Checking for orphaned files on disk not in qBittorrent...") completed_dir = app.client.application.preferences.save_path categories = [ @@ -57,7 +57,7 @@ def cleanup_dir(folder_path, owned_files): owned_subfiles = set( filter(lambda x: x.startswith(item_path), owned_files) ) - if len(owned_subfiles) == 0 and item_path not in categories: + if not owned_subfiles and item_path not in categories: delete(item_path) else: cleanup_dir(item_path, owned_subfiles) diff --git a/qbtools/commands/prune.py b/qbtools/commands/prune.py index 1e973c2..a3ea451 100644 --- a/qbtools/commands/prune.py +++ b/qbtools/commands/prune.py @@ -19,34 +19,34 @@ def __init__(app, logger): if not categories: logger.info( - f"No torrents can be pruned since no categories were included based on selectors" + "No torrents can be pruned since no categories were included based on selectors" ) torrents = app.client.torrents.info() - torrents = list( - filter(lambda x: x.category in categories, torrents) - ) + torrents = list(filter(lambda x: x.category in categories, torrents)) include_tags = [i for s in app.include_tag for i in s] if include_tags: torrents = list( filter(lambda x: all(y in x.tags for y in include_tags), torrents) ) + exclude_tags = [i for s in app.exclude_tag for i in s] if exclude_tags: torrents = list( - filter( - lambda x: not any(y in x.tags for y in exclude_tags), torrents - ) + filter(lambda x: not any(y in x.tags for y in exclude_tags), torrents) ) logger.info( - f"Pruning torrents with tags [{' AND '.join(include_tags)}] but does not contain tags [{' OR '.join(exclude_tags)}]..." + f"Pruning torrents with tags [{' AND '.join(include_tags)}] " + f"but does not contain tags [{' OR '.join(exclude_tags)}]..." ) for t in torrents: logger.info( - f"Pruned torrent {t['name']} with category [{t.category}] and tags [{t.tags}] and ratio [{round(t['ratio'], 2)}] and seeding time [{utils.dhms(t['seeding_time'])}]" + f"Pruned torrent {t['name']} with category [{t.category}] " + f"and tags [{t.tags}] and ratio [{round(t['ratio'], 2)}] " + f"and seeding time [{utils.dhms(t['seeding_time'])}]" ) if not app.dry_run: t.delete(delete_files=app.with_data) diff --git a/qbtools/commands/reannounce.py b/qbtools/commands/reannounce.py index 52c3b3e..8ad30c3 100755 --- a/qbtools/commands/reannounce.py +++ b/qbtools/commands/reannounce.py @@ -26,31 +26,21 @@ def process_torrents(status): peers = t.num_seeds + t.num_leechs if peers: logger.debug( - "Torrent %s (%s) has %d peer(s) - not reannouncing", - t.name, - t.hash, - peers, + f"Torrent {t.name} ({t.hash}) has {peers} peer(s) - not reannouncing" ) continue torrent_retries = torrents_retries.get(t.hash, 0) if torrent_retries >= max_tries: logger.debug( - "Torrent %s (%s) has reached %s reannounce tries - not reannouncing", - t.name, - t.hash, - retries, + f"Torrent {t.name} ({t.hash}) has reached {retries} reannounce tries - not reannouncing", ) continue t.reannounce() torrents_retries[t.hash] = torrent_retries + 1 logger.info( - "Reannounced torrent %s (%s) %s/%s", - t.name, - t.hash, - torrent_retries, - max_tries, + f"Reannounced torrent {t.name} ({t.hash}) {torrent_retries}/{max_tries}", ) retries[status] = torrents_retries diff --git a/qbtools/commands/tagging.py b/qbtools/commands/tagging.py index 5ef5c00..85ae4ce 100755 --- a/qbtools/commands/tagging.py +++ b/qbtools/commands/tagging.py @@ -47,20 +47,13 @@ def __init__(app, logger): - logger.info(f"Tagging torrents in qBittorrent...") - - tags = collections.defaultdict(list) - content_paths = [] + logger.info("Tagging torrents in qBittorrent...") today = datetime.today() - extractTLD = tldextract.TLDExtract(cache_dir=None) - + torrents = app.client.torrents.info() trackers = app.config.get("trackers", []) trackers = {y: x for x in trackers for y in x["urls"]} - unregistered_matches = app.config.get("unregistered_matches", UNREGISTERED_MATCHES) - maintenance_matches = app.config.get("maintenance_matches", MAINTENANCE_MATCHES) - exclude_categories = [i for s in app.exclude_category for i in s] if exclude_categories: torrents = list( @@ -70,12 +63,12 @@ def __init__(app, logger): exclude_tags = [i for s in app.exclude_tag for i in s] if exclude_tags: torrents = list( - filter( - lambda x: any(y not in x.tags for y in exclude_tags), torrents - ) + filter(lambda x: any(y not in x.tags for y in exclude_tags), torrents) ) - torrents = app.client.torrents.info() + extractTLD = tldextract.TLDExtract(cache_dir=None) + tags = collections.defaultdict(list) + paths = [] for t in torrents: tags_to_add = [] @@ -83,7 +76,7 @@ def __init__(app, logger): url = t.tracker if not url: - filtered = [s for s in t.trackers if s.tier >= 0] # Expensive + filtered = [s for s in t.trackers if s.tier >= 0] # Expensive if not filtered: continue url = filtered[0].url @@ -92,7 +85,7 @@ def __init__(app, logger): if app.added_on: tags_to_add.append(calculate_date_tags("added", t.added_on, today)) - + if app.last_activity: tags_to_add.append(calculate_date_tags("activity", t.last_activity, today)) @@ -103,13 +96,13 @@ def __init__(app, logger): tags_to_add.append(f"site:unmapped") if (app.unregistered or app.tracker_down or app.not_working) and filtered: - tracker_messages = [z.msg.upper() for z in filtered] + messages = [z.msg.upper() for z in filtered] if app.unregistered and any( - x in msg for msg in tracker_messages for x in unregistered_matches + match in msg for msg in messages for match in UNREGISTERED_MATCHES ): tags_to_add.append("unregistered") elif app.tracker_down and any( - x in msg for msg in tracker_messages for x in maintenance_matches + match in msg for msg in messages for match in MAINTENANCE_MATCHES ): tags_to_add.append("tracker-down") elif app.not_working: @@ -117,19 +110,20 @@ def __init__(app, logger): if app.expired and tracker and t.state_enum.is_complete: if ( - tracker["required_seed_ratio"] != 0 + tracker["required_seed_ratio"] and t.ratio >= tracker["required_seed_ratio"] ): tags_to_add.append("expired") - elif tracker["required_seed_days"] != 0 and t.seeding_time >= utils.seconds( + elif tracker["required_seed_days"] and t.seeding_time >= utils.seconds( tracker["required_seed_days"] ): tags_to_add.append("expired") if app.duplicates: - if t.content_path in content_paths and not t.content_path == t.save_path: + if t.content_path in paths and not t.content_path == t.save_path: tags_to_add.append("dupe") - content_paths.append(t.content_path) + else: + paths.append(t.content_path) if app.not_linked and not utils.is_linked(t.content_path): tags_to_add.append("not-linked") @@ -139,8 +133,9 @@ def __init__(app, logger): empty_tags = list( filter( - lambda tag: tag not in tags and any(tag.lower().startswith(x.lower()) for x in DEFAULT_TAGS), - app.client.torrents_tags() + lambda tag: tag not in tags + and any(tag.lower().startswith(x.lower()) for x in DEFAULT_TAGS), + app.client.torrents_tags(), ) ) if empty_tags: @@ -235,7 +230,9 @@ def add_arguments(command, subparser): help="Tag torrents with not working tracker status", ) parser.add_argument( - "--sites", action="store_true", help="Tag torrents with site names (defined in config.yaml)" + "--sites", + action="store_true", + help="Tag torrents with site names (defined in config.yaml)", ) parser.add_argument( "--tracker-down",