Skip to content

Commit

Permalink
feat: add ignore category arg to expired command
Browse files Browse the repository at this point in the history
Signed-off-by: Devin Buhl <[email protected]>
  • Loading branch information
onedr0p committed Aug 23, 2023
1 parent 157841b commit 7722e76
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions qbittools/commands/expired.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,27 @@ def __init__(args, logger):
client = qbittools.qbit_client(args)
indexers = [item for sublist in args.indexer for item in sublist]
filtered_indexer_list = filter_indexer_by_args(indexers)
ignore_categories = [item for sublist in args.ignore_category for item in sublist]

logger.info(f"Checking for expired torrents in qBittorrent")
logger.info(f"Using indexers '{' '.join(indexers)}'")
if args.dry_run:
logger.info(f"Dry run mode initiated, no torrents will be deleted")

extractTLD = tldextract.TLDExtract(cache_dir=None)

torrents_info = client.torrents.info()
for torrent in torrents_info:
if torrent['category'] in ignore_categories:
logger.debug(f"Skipping torrent {torrent['name']} due to ignore category {torrent['category']}")
continue

real_trackers = list(filter(lambda s: not s.url in DHT_MATCHES, torrent.trackers))
domain = tldextract.extract(sorted(real_trackers, key=lambda x: x.url)[0].url).registered_domain
domain = extractTLD(sorted(real_trackers, key=lambda x: x.url)[0].url).registered_domain

indexer = filter_indexer_by_url(filtered_indexer_list, domain)
if indexer:
if torrent['ratio'] >= indexer['required_seed_ratio']:
if torrent['ratio'] >= indexer['required_seed_ratio'] and torrent['ratio'] != 0:
logger.info(f"Removing torrent {torrent['name']} ({domain}) with matching indexer {indexer['name']} due to an expired ratio ({round(torrent['ratio'], 2)})")
if not args.dry_run:
torrent.delete(delete_files=False)
Expand All @@ -118,5 +125,6 @@ def add_arguments(subparser):
parser = subparser.add_parser('expired')
parser.add_argument('--dry-run', action='store_true', help='Do not delete the torrents only log them', required=False)
parser.add_argument('--indexer', nargs='*', action='append', metavar='myindexer', default=[], help='Indexer, can be repeated multiple times', required=False)
parser.add_argument('--ignore-category', nargs='*', action='append', metavar='mycategory', default=[], help='Ignore category, can be repeated multiple times', required=False)

qbittools.add_default_args(parser)

0 comments on commit 7722e76

Please sign in to comment.