Skip to content

Commit

Permalink
fix: optimize tracker lookup logic
Browse files Browse the repository at this point in the history
Signed-off-by: Devin Buhl <[email protected]>
  • Loading branch information
onedr0p committed Aug 30, 2024
1 parent 5fcde29 commit 7d36f8e
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions qbtools/commands/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@
"002: invalid infohash",
]

MAINTENANCE_MATCHES = ["tracker is down", "maintenance"]

DHT_MATCHES = ["** [DHT] **", "** [PeX] **", "** [LSD] **"]
MAINTENANCE_MATCHES = [
"down",
"maintenance",
"unreachable",
"bad gateway",
"unavailable",
]

DHT_MATCHES = {
"** [DHT] **",
"** [PeX] **",
"** [LSD] **"
}

def __init__(args, logger):
logger.info(f"Tagging torrents in qBittorrent...")
Expand Down Expand Up @@ -77,14 +86,13 @@ 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))
if not filtered_trackers:
continue
domain = extractTLD(
sorted(filtered_trackers, key=lambda x: x.url)[0].url
).registered_domain
tracker = qbtools.utils.filter_tracker_by_domain(domain, trackers)
for t in trackers:
filtered_trackers = (s for s in t.trackers if s.url not in DHT_MATCHES)
first_filtered_tracker = next(filtered_trackers, None)
if not first_filtered_tracker:
continue
domain = extractTLD(first_filtered_tracker.url).registered_domain
tracker = qbtools.utils.filter_tracker_by_domain(domain, trackers)

if args.added_on:
added_on = datetime.fromtimestamp(t.added_on)
Expand Down

0 comments on commit 7d36f8e

Please sign in to comment.