From 0977b12fe1861865cb11e8645c71f1539cd7b06b Mon Sep 17 00:00:00 2001 From: jblu Date: Fri, 2 Sep 2022 20:22:04 -0500 Subject: [PATCH 1/2] #15 added tag whitelisting --- ignored_tags copy.json.example | 5 +++++ qbit-maid.py | 2 ++ qlist.py | 9 ++++++++- test_qbitmaid.py | 8 +++++++- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 ignored_tags copy.json.example diff --git a/ignored_tags copy.json.example b/ignored_tags copy.json.example new file mode 100644 index 0000000..16477a0 --- /dev/null +++ b/ignored_tags copy.json.example @@ -0,0 +1,5 @@ +{ +"first":"first", +"second":"second", +"third":"third" +} \ No newline at end of file diff --git a/qbit-maid.py b/qbit-maid.py index 2b47055..dca066f 100644 --- a/qbit-maid.py +++ b/qbit-maid.py @@ -20,6 +20,8 @@ class Qbt: self.config = load(c) w = open('./category-whitelist.json') self.cat_whitelist = load(w) + tg = open('./ignored_tags.json') + self.ignored_tags = load(tg) # Create the api object self.qbt_client = qbittorrentapi.Client( host=self.config["host"], diff --git a/qlist.py b/qlist.py index 93cf50b..3c535fb 100644 --- a/qlist.py +++ b/qlist.py @@ -9,6 +9,9 @@ def buildtorlist(self): torrent = self.torrentlist.pop() if self.use_log: self.tl.debug(f'["{torrent["name"][0:20]}..."] {torrent["infohash_v1"]}') + if isignoredtag(self.ignored_tags.values(),torrent['tags']): + self.ignored_counter += 1 + continue # if torrent['added_on'] + self.minimum_age >= self.t.time(): if ispreme(torrent['added_on'], self.minimum_age, self.t.time()): self.preme_tor_counter += 1 @@ -63,4 +66,8 @@ def isnotprotectedtracker(tracker, trackerlist): def istagblank(tag): if tag == '': return True - \ No newline at end of file + +def isignoredtag(igtags, tortags): + for igt in igtags: + if igt in tortags: + return True \ No newline at end of file diff --git a/test_qbitmaid.py b/test_qbitmaid.py index a2874a6..a87e09b 100644 --- a/test_qbitmaid.py +++ b/test_qbitmaid.py @@ -1,5 +1,5 @@ import unittest -from qlist import ispreme,iscatignored,istrackerblank,isprotectedtracker,isnotprotectedtracker,istagblank +from qlist import ispreme,iscatignored,istrackerblank,isprotectedtracker,isnotprotectedtracker,istagblank,isignoredtag from qprocess import isdownloading,isprotectedunderratio,isoldtor,isprotectedoverratio,isnonprotectedtor class TestQbitmaid(unittest.TestCase): @@ -87,6 +87,12 @@ class TestQbitmaid(unittest.TestCase): def test_isnonprotectedtor(self): pass + def test_isignoredtag_sanity(self): + self.assertTrue(isignoredtag(['a','b','c'], 'first,second,third,a')) + + def test_isignoredtag_sanity(self): + self.assertTrue(isignoredtag(['a','b','c'], 'first,second,third,a')) + # def test__sanity(self): # pass From 8c8aff9b09816dff7d6c12c4ddb47a5c97ab8613 Mon Sep 17 00:00:00 2001 From: jblu Date: Sat, 3 Sep 2022 14:04:03 -0500 Subject: [PATCH 2/2] Changed the config files and updated the readme --- README.md | 61 +++++++++++++------ ...example => ignored_categories.json.example | 0 ...on.example => ignored_domains.json.example | 0 ....json.example => ignored_tags.json.example | 0 qbit-maid.py | 4 +- 5 files changed, 43 insertions(+), 22 deletions(-) rename category-whitelist.json.example => ignored_categories.json.example (100%) rename tracker-whitelist.json.example => ignored_domains.json.example (100%) rename ignored_tags copy.json.example => ignored_tags.json.example (100%) diff --git a/README.md b/README.md index d3b77a7..f176f20 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # qbit-maid -Warning: This application removes torrents that aren't downloading and that aren't from iptorrents. Age in the config.json only controls the age for torrents from iptorrents. +## Warning: This application removes torrents that are over the minimum age and that are not part of the ignored categories, domains or tags. Please use the delete_torrents feature set to false when first testing its functionality. The objective is to remove torrents based on the following criteria: - tracker domain name @@ -24,9 +24,32 @@ graph TD; | qlist.py | Builds out torrent lists | | qlogging.py | Logging and push notification communication | | qprocess.py | Submits qualifying torrents for deletion | +| test_qbitmaid.py | Unit tests | +| ignored_categories.json | whitelist for categorys to ignore | +| ignored_tags.json | whitelist for torrent tags to ignore | +| ignored_trackers.json | whitelist of fqdn names to ignore | You will need a config.json in the root directory. +| Key | Value | +| --- | --- | +| host | string, ip or hostname of qbittorrent server | +| port | number, port of admin gui(used for api aswell) | +| username | admin account for qbittorrent | +| password | password for admin account | +| loglevel | is what log messages are written to the log file. INFO or DEBUG are valid entries(case sensitive) | +| protected_tag | used to mark torrents to handle with care | +| non_protected_tag | we don't care about these torrents | +| logpath | will write a log in root directory if left as is other wise specify other path using forward slashes | +| age | number, seconds for how long we keep torrents from IPTORRENTS | +| minimum_age | age in seconds torrents should reached before they are removed | +| use_pushover | true or false to enable or disable pushover notification summary | +| use_log | true or false to enable or disable writing to alog file | +| po_key | pushover key | +| po_token | pushover api token | +| delete_torrents | true or false to enable or disable deletion. Useful for dry-runs | +| enable_dragnet | true or false to enable dragnet functionality. Useful for debugging | + It should look something like this: Config.json ``` @@ -51,7 +74,7 @@ Config.json } ``` -You will need a category-whitelist.json in the root directory. This will ignore any of the categories found in the values of the entries. +You will need a ignored_categories.json in the root directory. This will ignore any of the categories found in the values of the entries. ``` { "example": "general", @@ -59,22 +82,20 @@ You will need a category-whitelist.json in the root directory. This will ignore } ``` +You will need a ignored_domains.json in the root directory. This will ignore any torrents from these trackers. +``` +{ +"iptorrents-empirehost": "ssl.empirehost.me", +"iptorrents-stackoverflow": "localhost.stackoverflow.tech", +"iptorrents-bgp": "routing.bgp.technology" +} +``` -| Key | Value | -| --- | --- | -| host | string, ip or hostname of qbittorrent server | -| port | number, port of admin gui(used for api aswell) | -| username | admin account for qbittorrent | -| password | password for admin account | -| loglevel | is what log messages are written to the log file. INFO or DEBUG are valid entries(case sensitive) | -| protected_tag | used to mark torrents to handle with care | -| non_protected_tag | we don't care about these torrents | -| logpath | will write a log in root directory if left as is other wise specify other path using forward slashes | -| age | number, seconds for how long we keep torrents from IPTORRENTS | -| minimum_age | age in seconds torrents should reached before they are removed | -| use_pushover | true or false to enable or disable pushover notification summary | -| use_log | true or false to enable or disable writing to alog file | -| po_key | pushover key | -| po_token | pushover api token | -| delete_torrents | true or false to enable or disable deletion. Useful for dry-runs | -| enable_dragnet | true or false to enable dragnet functionality. Useful for debugging | \ No newline at end of file +You will need a ignored_tags.json in the root directory. This will ignore any torrents with these tags. +``` +{ +"first":"first", +"second":"second", +"third":"third" +} +``` \ No newline at end of file diff --git a/category-whitelist.json.example b/ignored_categories.json.example similarity index 100% rename from category-whitelist.json.example rename to ignored_categories.json.example diff --git a/tracker-whitelist.json.example b/ignored_domains.json.example similarity index 100% rename from tracker-whitelist.json.example rename to ignored_domains.json.example diff --git a/ignored_tags copy.json.example b/ignored_tags.json.example similarity index 100% rename from ignored_tags copy.json.example rename to ignored_tags.json.example diff --git a/qbit-maid.py b/qbit-maid.py index dca066f..32e2a89 100644 --- a/qbit-maid.py +++ b/qbit-maid.py @@ -18,7 +18,7 @@ class Qbt: self.st = datetime.datetime.now() c = open('./config.json') self.config = load(c) - w = open('./category-whitelist.json') + w = open('./ignored_categories.json') self.cat_whitelist = load(w) tg = open('./ignored_tags.json') self.ignored_tags = load(tg) @@ -52,7 +52,7 @@ class Qbt: tornotify(self) self.t = time # Pulling domain names to treat carefully - f = open('./tracker-whitelist.json') + f = open('./ignored_domains.json') self.tracker_whitelist = load(f) self.tracker_list = [] self.up_tor_counter = 0