diff --git a/config.yaml b/config.yaml index eaa1f82..f7ea274 100644 --- a/config.yaml +++ b/config.yaml @@ -8,5 +8,5 @@ trackers: {} # - bgp.technology # - empirehost.me # - stackoverflow.tech -# required_seed_ratio: 1.05 +# required_seed_ratio: 1.05 # required_seed_days: 14.5 diff --git a/qbtools/commands/prune.py b/qbtools/commands/prune.py index e83097a..1e973c2 100644 --- a/qbtools/commands/prune.py +++ b/qbtools/commands/prune.py @@ -10,6 +10,7 @@ def __init__(app, logger): categories = list( filter(lambda c: any(fnmatch(c, p) for p in includes), categories) ) + if app.exclude_category: excludes = [i for s in app.exclude_category for i in s] categories = list( @@ -21,21 +22,21 @@ def __init__(app, logger): f"No torrents can be pruned since no categories were included based on selectors" ) - filtered_torrents = app.client.torrents.info() - filtered_torrents = list( - filter(lambda x: x.category in categories, filtered_torrents) + torrents = app.client.torrents.info() + 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: - filtered_torrents = list( - filter(lambda x: all(y in x.tags for y in include_tags), filtered_torrents) + 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: - filtered_torrents = list( + torrents = list( filter( - lambda x: not any(y in x.tags for y in exclude_tags), filtered_torrents + lambda x: not any(y in x.tags for y in exclude_tags), torrents ) ) @@ -43,14 +44,14 @@ def __init__(app, logger): f"Pruning torrents with tags [{' AND '.join(include_tags)}] but does not contain tags [{' OR '.join(exclude_tags)}]..." ) - for t in filtered_torrents: + 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'])}]" ) if not app.dry_run: t.delete(delete_files=app.with_data) - logger.info(f"Deleted {len(filtered_torrents)} torrents") + logger.info(f"Deleted {len(torrents)} torrents") def add_arguments(command, subparser): diff --git a/qbtools/commands/tagging.py b/qbtools/commands/tagging.py index 93f16e7..97d02aa 100755 --- a/qbtools/commands/tagging.py +++ b/qbtools/commands/tagging.py @@ -57,28 +57,30 @@ def __init__(app, logger): tag_sizes = collections.defaultdict(int) content_paths = [] - filtered_torrents = app.client.torrents.info() + 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: - filtered_torrents = list( - filter(lambda x: x.category not in exclude_categories, filtered_torrents) + torrents = list( + filter(lambda x: x.category not in exclude_categories, torrents) ) exclude_tags = [i for s in app.exclude_tag for i in s] if exclude_tags: - filtered_torrents = list( + torrents = list( filter( - lambda x: any(y not in x.tags for y in exclude_tags), filtered_torrents + lambda x: any(y not in x.tags for y in exclude_tags), torrents ) ) # Gather items to tag in qBittorrent - for t in filtered_torrents: + for t in torrents: tags_to_add = [] filtered_trackers = ( @@ -86,12 +88,14 @@ def __init__(app, logger): if t.properties.is_private else t.trackers ) + if not filtered_trackers: continue - domain = extractTLD( - sorted(filtered_trackers, key=lambda x: x.url)[0].url - ).registered_domain - tracker = utils.filter_tracker_by_domain(domain, trackers) + else: + filtered_trackers = sorted(filtered_trackers, key=lambda x: x.url) + + domain = extractTLD(filtered_trackers[0].url).registered_domain + tracker = trackers.get(domain) if app.added_on: added_on = datetime.fromtimestamp(t.added_on) @@ -189,7 +193,7 @@ def __init__(app, logger): ) ) if default_tags: - hashes = list(map(lambda t: t.hash, filtered_torrents)) + hashes = list(map(lambda t: t.hash, torrents)) app.client.torrents_remove_tags(tags=default_tags, torrent_hashes=hashes) empty_tags = list( filter( diff --git a/qbtools/utils.py b/qbtools/utils.py index d1609aa..317837f 100644 --- a/qbtools/utils.py +++ b/qbtools/utils.py @@ -13,12 +13,6 @@ def format_bytes(size): return f"{formatted} {power_labels[n]}" -def filter_tracker_by_domain(domain, trackers=[]): - for tracker in trackers: - if any(domain in url for url in tracker["urls"]): - return tracker - - def seconds(days: int) -> int: seconds_in_a_day = 86400 seconds = days * seconds_in_a_day