Skip to content

Commit

Permalink
Merge pull request #92 from StuffAnThings/develop
Browse files Browse the repository at this point in the history
3.2.0
  • Loading branch information
bobokun committed Jan 17, 2022
2 parents e7b113d + 5fed8cd commit 5697021
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 158 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ ignore =
E272, # E272 Multiple spaces before keyword
C901 # C901 Function is too complex
E722 # E722 Do not use bare except, specify exception instead
W503 # W503 Line break occurred before a binary operator
max-line-length = 200
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.5
3.2.0
30 changes: 19 additions & 11 deletions config/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ qbt:
pass: "password"

settings:
force_auto_tmm: False # Will force qBittorrent to enable Automatic Torrent Management for each torrent.

force_auto_tmm: False # Will force qBittorrent to enable Automatic Torrent Management for each torrent.
tracker_error_tag: issue # Will set the tag of any torrents that do not have a working tracker.
ignoreTags_OnUpdate: # When running tag-update function, it will update torrent tags for a given torrent even if the torrent has one or more of the tags defined here.
- noHL
- issue
- cross-seed
directory:
# Do not remove these
# Cross-seed var: </your/path/here/> # Output directory of cross-seed
# root_dir var: </your/path/here/> # Root downloads directory used to check for orphaned files, noHL, and RecycleBin.
# <OPTIONAL> remote_dir var: </your/path/here/> # Path of docker host mapping of root_dir.
# Cross-seed var: </your/path/here/> # Output directory of cross-seed
# root_dir var: </your/path/here/> # Root downloads directory used to check for orphaned files, noHL, and RecycleBin.
# <OPTIONAL> remote_dir var: </your/path/here/> # Path of docker host mapping of root_dir.
# Must be set if you're running qbit_manage locally and qBittorrent/cross_seed is in a docker
# <OPTIONAL> recycle_bin var: </your/path/here/> # Path of the RecycleBin folder. Default location is set to remote_dir/.RecycleBin
# <OPTIONAL> torrents_dir var: </your/path/here/> # Path of the your qbittorrent torrents directory. Required for `save_torrents` attribute in recyclebin
# <OPTIONAL> recycle_bin var: </your/path/here/> # Path of the RecycleBin folder. Default location is set to remote_dir/.RecycleBin
# <OPTIONAL> torrents_dir var: </your/path/here/> # Path of the your qbittorrent torrents directory. Required for `save_torrents` attribute in recyclebin

cross_seed: "/your/path/here/"
root_dir: "/data/torrents/"
Expand All @@ -29,14 +33,14 @@ directory:

# Category & Path Parameters
cat:
# <Category Name> : <save_path> # Path of your save directory.
# <Category Name> : <save_path> # Path of your save directory.
movies: "/data/torrents/Movies"
tv: "/data/torrents/TV"

# Tag Parameters
tracker:
# <Tracker URL Keyword>: # <MANDATORY> This is the keyword in the tracker url
# <MANDATORY> Set tag name
# <MANDATORY> Set tag name. Can be a list of tags or a single tag
# tag: <Tag Name>
# <OPTIONAL> Will set the torrent Maximum share ratio until torrent is stopped from seeding/uploading. -2 means the global limit should be used, -1 means no limit.
# max_ratio: 5.0
Expand All @@ -50,13 +54,16 @@ tracker:
tag: AnimeBytes
notifiarr: animebytes
avistaz:
tag: Avistaz
tag:
- Avistaz
- tag2
- tag3
max_ratio: 5.0
max_seeding_time: 129600
limit_upload_speed: 150
notifiarr: avistaz
beyond-hd:
tag: Beyond-HD
tag: [Beyond-HD, tag2, tag3]
notifiarr: beyondhd
blutopia:
tag: Blutopia
Expand Down Expand Up @@ -186,6 +193,7 @@ webhooks:
cat_update: apprise
tag_update: notifiarr
rem_unregistered: notifiarr
tag_tracker_error: notifiarr
rem_orphaned: notifiarr
tag_nohardlinks: notifiarr
empty_recyclebin: notifiarr
Expand Down
46 changes: 33 additions & 13 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,31 @@ def hooks(attr):

self.settings = {
"force_auto_tmm": self.util.check_for_attribute(self.data, "force_auto_tmm", parent="settings", var_type="bool", default=False),
"tracker_error_tag": self.util.check_for_attribute(self.data, "tracker_error_tag", parent="settings", default='issue')
}
default_ignore_tags = ['noHL', self.settings["tracker_error_tag"], 'cross-seed']
self.settings["ignoreTags_OnUpdate"] = self.util.check_for_attribute(self.data, "ignoreTags_OnUpdate", parent="settings", default=default_ignore_tags, var_type="list")

default_function = {
'cross_seed': None,
'recheck': None,
'cat_update': None,
'tag_update': None,
'rem_unregistered': None,
'tag_tracker_error': None,
'rem_orphaned': None,
'tag_nohardlinks': None,
'empty_recyclebin': None}
'empty_recyclebin': None
}

self.webhooks = {
"error": self.util.check_for_attribute(self.data, "error", parent="webhooks", var_type="list", default_is_none=True),
"run_start": self.util.check_for_attribute(self.data, "run_start", parent="webhooks", var_type="list", default_is_none=True),
"run_end": self.util.check_for_attribute(self.data, "run_end", parent="webhooks", var_type="list", default_is_none=True),
"function": self.util.check_for_attribute(self.data, "function", parent="webhooks", var_type="list", default=default_function)
}
for func in default_function:
self.util.check_for_attribute(self.data, func, parent="webhooks", subparent="function", default_is_none=True)

self.AppriseFactory = None
if "apprise" in self.data:
Expand Down Expand Up @@ -192,7 +199,17 @@ def hooks(attr):
self.cross_seed_dir = self.util.check_for_attribute(self.data, "cross_seed", parent="directory", var_type="path")
else:
self.cross_seed_dir = self.util.check_for_attribute(self.data, "cross_seed", parent="directory", default_is_none=True)
self.recycle_dir = self.util.check_for_attribute(self.data, "recycle_bin", parent="directory", var_type="path", default=os.path.join(self.remote_dir, '.RecycleBin'), make_dirs=True)
if self.recyclebin['enabled']:
if "recycle_bin" in self.data["directory"]:
default_recycle = os.path.join(self.remote_dir, os.path.basename(self.data['directory']['recycle_bin'].rstrip('/')))
else:
default_recycle = os.path.join(self.remote_dir, '.RecycleBin')
if self.recyclebin['split_by_category']:
self.recycle_dir = self.util.check_for_attribute(self.data, "recycle_bin", parent="directory", default=default_recycle)
else:
self.recycle_dir = self.util.check_for_attribute(self.data, "recycle_bin", parent="directory", var_type="path", default=default_recycle, make_dirs=True)
else:
self.recycle_dir = None
if self.recyclebin['enabled'] and self.recyclebin['save_torrents']:
self.torrents_dir = self.util.check_for_attribute(self.data, "torrents_dir", parent="directory", var_type="path")
if not any(File.endswith(".torrent") for File in os.listdir(self.torrents_dir)):
Expand All @@ -207,10 +224,11 @@ def hooks(attr):
raise Failed(e)

# Add Orphaned
exclude_recycle = f"**/{os.path.basename(self.recycle_dir.rstrip('/'))}/*"
self.orphaned = {}
self.orphaned['exclude_patterns'] = self.util.check_for_attribute(self.data, "exclude_patterns", parent="orphaned", var_type="list", default_is_none=True, do_print=False)
self.orphaned['exclude_patterns'].append(exclude_recycle) if exclude_recycle not in self.orphaned['exclude_patterns'] else self.orphaned['exclude_patterns']
if self.recyclebin['enabled']:
exclude_recycle = f"**/{os.path.basename(self.recycle_dir.rstrip('/'))}/*"
self.orphaned['exclude_patterns'].append(exclude_recycle) if exclude_recycle not in self.orphaned['exclude_patterns'] else self.orphaned['exclude_patterns']

# Connect to Qbittorrent
self.qbt = None
Expand Down Expand Up @@ -255,17 +273,18 @@ def get_tags(self, urls):
logger.debug(e)
# If using Format 1 convert to format 2
if isinstance(tag_details, str):
tracker['tag'] = self.util.check_for_attribute(self.data, tag_url, parent="tracker", default=default_tag)
self.util.check_for_attribute(self.data, "tag", parent="tracker", subparent=tag_url, default=tracker['tag'], do_print=False)
tracker['tag'] = self.util.check_for_attribute(self.data, tag_url, parent="tracker", default=default_tag, var_type="list")
self.util.check_for_attribute(self.data, "tag", parent="tracker", subparent=tag_url, default=tracker['tag'], do_print=False, var_type="list")
if tracker['tag'] == default_tag:
try:
self.data['tracker'][tag_url]['tag'] = default_tag
self.data['tracker'][tag_url]['tag'] = [default_tag]
except Exception:
self.data['tracker'][tag_url] = {'tag': default_tag}
self.data['tracker'][tag_url] = {'tag': [default_tag]}
# Using Format 2
else:
tracker['tag'] = self.util.check_for_attribute(self.data, "tag", parent="tracker", subparent=tag_url, default=tag_url)
if tracker['tag'] == tag_url: self.data['tracker'][tag_url]['tag'] = tag_url
tracker['tag'] = self.util.check_for_attribute(self.data, "tag", parent="tracker", subparent=tag_url, default=tag_url, var_type="list")
if tracker['tag'] == [tag_url]: self.data['tracker'][tag_url]['tag'] = [tag_url]
if isinstance(tracker['tag'], str): tracker['tag'] = [tracker['tag']]
tracker['max_ratio'] = self.util.check_for_attribute(self.data, "max_ratio", parent="tracker", subparent=tag_url,
var_type="float", default_int=-2, default_is_none=True, do_print=False, save=False)
tracker['max_seeding_time'] = self.util.check_for_attribute(self.data, "max_seeding_time", parent="tracker", subparent=tag_url,
Expand All @@ -276,11 +295,12 @@ def get_tags(self, urls):
return (tracker)
if tracker['url']:
default_tag = tracker['url'].split('/')[2].split(':')[0]
tracker['tag'] = self.util.check_for_attribute(self.data, "tag", parent="tracker", subparent=default_tag, default=default_tag)
tracker['tag'] = self.util.check_for_attribute(self.data, "tag", parent="tracker", subparent=default_tag, default=default_tag, var_type="list")
if isinstance(tracker['tag'], str): tracker['tag'] = [tracker['tag']]
try:
self.data['tracker'][default_tag]['tag'] = default_tag
self.data['tracker'][default_tag]['tag'] = [default_tag]
except Exception:
self.data['tracker'][default_tag] = {'tag': default_tag}
self.data['tracker'][default_tag] = {'tag': [default_tag]}
e = (f'No tags matched for {tracker["url"]}. Please check your config.yml file. Setting tag to {default_tag}')
self.notify(e, 'Tag', False)
logger.warning(e)
Expand Down
Loading

0 comments on commit 5697021

Please sign in to comment.