From 60b02fe011b6d148945322a8c6a9ac9bb0536f20 Mon Sep 17 00:00:00 2001 From: bobokun Date: Tue, 6 Dec 2022 22:14:55 -0500 Subject: [PATCH] bit a refactoring --- modules/config.py | 3 ++- modules/qbittorrent.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/config.py b/modules/config.py index 60ec3d4..a47a31c 100755 --- a/modules/config.py +++ b/modules/config.py @@ -433,7 +433,8 @@ class Config: raise Failed(e) # Get tags from config file based on keyword - def get_tags(self, urls): + def get_tags(self, trackers): + urls = [x.url for x in trackers if x.url.startswith("http")] tracker = {} tracker["tag"] = None tracker["max_ratio"] = None diff --git a/modules/qbittorrent.py b/modules/qbittorrent.py index 97d183c..4a65213 100755 --- a/modules/qbittorrent.py +++ b/modules/qbittorrent.py @@ -217,7 +217,7 @@ class Qbt: def update_cat(new_cat, cat_change): nonlocal torrent, num_cat - tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith("http")]) + tracker = self.config.get_tags(torrent.trackers) old_cat = torrent.category if not self.config.dry_run: try: @@ -284,7 +284,7 @@ class Qbt: for torrent in self.torrent_list: check_tags = util.get_list(torrent.tags) if torrent.tags == "" or (len([x for x in check_tags if x not in ignore_tags]) == 0): - tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith("http")]) + tracker = self.config.get_tags(torrent.trackers) if tracker["tag"]: num_tags += len(tracker["tag"]) body = [] @@ -520,7 +520,7 @@ class Qbt: logger.warning(e) continue for torrent in torrent_list: - tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith("http")]) + tracker = self.config.get_tags(torrent.trackers) if any(tag in torrent.tags for tag in nohardlinks[category]["exclude_tags"]): # Skip to the next torrent if we find any torrents that are in the exclude tag continue @@ -533,7 +533,7 @@ class Qbt: # Cleans up previously tagged noHL torrents # Determine min_seeding_time. noHl > Tracker w/ default 0 min_seeding_time = 0 - tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith("http")]) + tracker = self.config.get_tags(torrent.trackers) if nohardlinks[category]["min_seeding_time"]: min_seeding_time = nohardlinks[category]["min_seeding_time"] elif tracker["min_seeding_time"]: @@ -614,7 +614,7 @@ class Qbt: t_status = self.torrentinfo[t_name]["status"] # Double check that the content path is the same before we delete anything if torrent["content_path"].replace(root_dir, root_dir) == tdel_dict[t_name]["content_path"]: - tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith("http")]) + tracker = self.config.get_tags(torrent.trackers) body = [] body += logger.print_line(logger.insert_space(f"Torrent Name: {t_name}", 3), self.config.loglevel) body += logger.print_line( @@ -798,7 +798,7 @@ class Qbt: check_tags = util.get_list(torrent.tags) # Remove any error torrents Tags that are no longer unreachable. if tag_error in check_tags: - tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith("http")]) + tracker = self.config.get_tags(torrent.trackers) num_untag += 1 body = [] body += logger.print_line( @@ -969,7 +969,7 @@ class Qbt: and self.torrentinfo[t_name]["count"] > 1 and self.torrentinfo[t_name]["first_hash"] != torrent.hash ): - tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith("http")]) + tracker = self.config.get_tags(torrent.trackers) tagged += 1 body = logger.print_line( f"{'Not Adding' if self.config.dry_run else 'Adding'} 'cross-seed' tag to {t_name}", self.config.loglevel @@ -1015,7 +1015,7 @@ class Qbt: torrent_list = self.get_torrents({"status_filter": "paused", "sort": "size"}) if torrent_list: for torrent in torrent_list: - tracker = self.config.get_tags([x.url for x in torrent.trackers if x.url.startswith("http")]) + tracker = self.config.get_tags(torrent.trackers) # Resume torrent if completed if torrent.progress == 1: if torrent.max_ratio < 0 and torrent.max_seeding_time < 0: