Skip to content

Commit

Permalink
New option cat in trackers (#400)
Browse files Browse the repository at this point in the history
* New option cat in trackers

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: bobokun <[email protected]>
  • Loading branch information
3 people authored Oct 7, 2023
1 parent a02a066 commit 51a6f12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/core/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def category(self):
logger.separator("Updating Categories", space=False, border=False)
torrent_list = self.qbt.get_torrents({"category": "", "status_filter": "completed"})
for torrent in torrent_list:
new_cat = self.qbt.get_category(torrent.save_path)
new_cat = self.get_tracker_cat(torrent) or self.qbt.get_category(torrent.save_path)
if new_cat == self.uncategorized_mapping:
logger.print_line(f"{torrent.name} remains uncategorized.", self.config.loglevel)
continue
Expand All @@ -44,6 +44,10 @@ def category(self):
else:
logger.print_line("No new torrents to categorize.", self.config.loglevel)

def get_tracker_cat(self, torrent):
tracker = self.qbt.get_tags(torrent.trackers)
return tracker["cat"]

def update_cat(self, torrent, new_cat, cat_change):
"""Update category based on the torrent information"""
tracker = self.qbt.get_tags(torrent.trackers)
Expand Down
11 changes: 11 additions & 0 deletions modules/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def get_tags(self, trackers):
urls = [x.url for x in trackers if x.url.startswith("http")]
tracker = {}
tracker["tag"] = None
tracker["cat"] = None
tracker["notifiarr"] = None
tracker["url"] = None
tracker_other_tag = self.config.util.check_for_attribute(
Expand Down Expand Up @@ -238,6 +239,16 @@ def get_tags(self, trackers):
tracker["tag"] = self.config.util.check_for_attribute(
self.config.data, "tag", parent="tracker", subparent=tag_url, default=tag_url, var_type="list"
)
tracker["cat"] = self.config.util.check_for_attribute(
self.config.data,
"cat",
parent="tracker",
subparent=tag_url,
default_is_none=True,
var_type="str",
save=False,
do_print=False,
)
if tracker["tag"] == [tag_url]:
self.config.data["tracker"][tag_url]["tag"] = [tag_url]
if isinstance(tracker["tag"], str):
Expand Down

0 comments on commit 51a6f12

Please sign in to comment.