From 13aa5261cbdefb797f29c768d204014adea62aea Mon Sep 17 00:00:00 2001 From: p0ps Date: Sat, 9 Oct 2021 18:26:29 +0200 Subject: [PATCH] Add specific torrent/nzb options for the process method. (#9932) * Add specific torrent/nzb options for the process method. (only works with automated donwload handling) * update changelog * Pass param client_type * update snapshot --- CHANGELOG.md | 1 + medusa/__main__.py | 8 +++ medusa/app.py | 4 ++ medusa/process_tv.py | 26 +++++-- medusa/schedulers/download_handler.py | 9 ++- medusa/server/api/v2/config.py | 6 ++ .../src/components/config-post-processing.vue | 26 ++++++- .../config-post-processing.spec.js.snap | 67 ++++++++++++++++++- themes/dark/assets/js/medusa-runtime.js | 4 +- themes/light/assets/js/medusa-runtime.js | 4 +- 10 files changed, 139 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ce69a4e84..739fadb1f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased #### New Features +- Added separate configs for the process methods (copy, move, etc) for torrent and nzb. (only usuable with the download handler)([9932](https://github.com/pymedusa/Medusa/pull/9932)) #### Improvements diff --git a/medusa/__main__.py b/medusa/__main__.py index 90c6c394d6..95c1970a76 100755 --- a/medusa/__main__.py +++ b/medusa/__main__.py @@ -679,6 +679,11 @@ def initialize(self, console_logging=True): app.FILE_TIMESTAMP_TIMEZONE = check_setting_str(app.CFG, 'General', 'file_timestamp_timezone', 'network') app.KEEP_PROCESSED_DIR = bool(check_setting_int(app.CFG, 'General', 'keep_processed_dir', 1)) app.PROCESS_METHOD = check_setting_str(app.CFG, 'General', 'process_method', 'copy' if app.KEEP_PROCESSED_DIR else 'move') + + app.USE_SPECIFIC_PROCESS_METHOD = bool(check_setting_int(app.CFG, 'General', 'use_specific_process_method', 0)) + app.PROCESS_METHOD_TORRENT = check_setting_str(app.CFG, 'General', 'process_method', 'copy' if app.KEEP_PROCESSED_DIR else 'move') + app.PROCESS_METHOD_NZB = check_setting_str(app.CFG, 'General', 'process_method', 'copy' if app.KEEP_PROCESSED_DIR else 'move') + app.DELRARCONTENTS = bool(check_setting_int(app.CFG, 'General', 'del_rar_contents', 0)) app.MOVE_ASSOCIATED_FILES = bool(check_setting_int(app.CFG, 'General', 'move_associated_files', 0)) app.POSTPONE_IF_SYNC_FILES = bool(check_setting_int(app.CFG, 'General', 'postpone_if_sync_files', 1)) @@ -1687,6 +1692,9 @@ def save_config(): new_config['General']['tv_download_dir'] = app.TV_DOWNLOAD_DIR new_config['General']['keep_processed_dir'] = int(app.KEEP_PROCESSED_DIR) new_config['General']['process_method'] = app.PROCESS_METHOD + new_config['General']['use_specific_process_method'] = int(app.USE_SPECIFIC_PROCESS_METHOD) + new_config['General']['process_method_torrent'] = app.PROCESS_METHOD_TORRENT + new_config['General']['process_method_nzb'] = app.PROCESS_METHOD_NZB new_config['General']['del_rar_contents'] = int(app.DELRARCONTENTS) new_config['General']['move_associated_files'] = int(app.MOVE_ASSOCIATED_FILES) new_config['General']['sync_files'] = app.SYNC_FILES diff --git a/medusa/app.py b/medusa/app.py index 4e6d58f888..298ccaff5c 100644 --- a/medusa/app.py +++ b/medusa/app.py @@ -311,6 +311,10 @@ def __init__(self): self.NO_DELETE = False self.KEEP_PROCESSED_DIR = False self.PROCESS_METHOD = None + # The process methods for torrent and nzb are used by the download handler. + self.USE_SPECIFIC_PROCESS_METHOD = False + self.PROCESS_METHOD_TORRENT = None + self.PROCESS_METHOD_NZB = None self.DELRARCONTENTS = False self.MOVE_ASSOCIATED_FILES = False self.POSTPONE_IF_SYNC_FILES = True diff --git a/medusa/process_tv.py b/medusa/process_tv.py index 7847860f81..54e3c3193b 100644 --- a/medusa/process_tv.py +++ b/medusa/process_tv.py @@ -36,7 +36,7 @@ class PostProcessQueueItem(generic_queue.QueueItem): def __init__(self, path=None, info_hash=None, resource_name=None, force=False, is_priority=False, process_method=None, delete_on=False, failed=False, - proc_type='auto', ignore_subs=False, episodes=[]): + proc_type='auto', ignore_subs=False, episodes=[], client_type=None): """Initialize the class.""" generic_queue.QueueItem.__init__(self, u'Post Process') @@ -47,13 +47,17 @@ def __init__(self, path=None, info_hash=None, resource_name=None, force=False, self.resource_name = resource_name self.force = force self.is_priority = is_priority - self.process_method = process_method self.delete_on = delete_on self.failed = failed self.proc_type = proc_type self.ignore_subs = ignore_subs self.episodes = episodes + # torrent or nzb. Pass info on what sort of download we're processing. + # We might need this when determining the PROCESS_METHOD. + self.client_type = client_type + self.process_method = self.get_process_method(process_method, client_type) + self.to_json.update({ 'success': self.success, 'config': { @@ -70,6 +74,20 @@ def __init__(self, path=None, info_hash=None, resource_name=None, force=False, } }) + def get_process_method(self, process_method, client_type): + """Determine the correct process method. + + If client_type is provided (torrent/nzb) use that to get a + client specific process method. + """ + if process_method: + return process_method + + if self.client_type and app.USE_SPECIFIC_PROCESS_METHOD: + return app.PROCESS_METHOD_NZB if client_type == 'nzb' else app.PROCESS_METHOD_TORRENT + + return app.PROCESS_METHOD + def update_resource(self, status): """ Update the resource in db, depending on the postprocess result. @@ -114,9 +132,7 @@ def update_history_processed(self, process_results): def process_path(self): """Process for when we have a valid path.""" - process_method = self.process_method or app.PROCESS_METHOD - - process_results = ProcessResult(self.path, process_method, failed=self.failed, episodes=self.episodes) + process_results = ProcessResult(self.path, self.process_method, failed=self.failed, episodes=self.episodes) process_results.process( resource_name=self.resource_name, force=self.force, diff --git a/medusa/schedulers/download_handler.py b/medusa/schedulers/download_handler.py index 68669d085c..d33e68cbb0 100644 --- a/medusa/schedulers/download_handler.py +++ b/medusa/schedulers/download_handler.py @@ -242,7 +242,7 @@ def _check_postprocess(self, client): self._postprocess( status.destination, history_result['info_hash'], status.resource, - failed=str(status) == 'Failed' + failed=str(status) == 'Failed', client_type=client_type ) def _check_torrent_ratio(self, client): @@ -327,7 +327,7 @@ def _check_torrent_ratio(self, client): self.save_status_to_history(history_result, ClientStatus(status_string='SeededAction')) - def _postprocess(self, path, info_hash, resource_name, failed=False): + def _postprocess(self, path, info_hash, resource_name, failed=False, client_type=None): """Queue a postprocess action.""" # Use the info hash get a segment of episodes. history_items = self.main_db_con.select( @@ -344,7 +344,10 @@ def _postprocess(self, path, info_hash, resource_name, failed=False): continue episodes.append(show.get_episode(history_item['season'], history_item['episode'])) - queue_item = PostProcessQueueItem(path, info_hash, resource_name=resource_name, failed=failed, episodes=episodes) + queue_item = PostProcessQueueItem( + path, info_hash, resource_name=resource_name, + failed=failed, episodes=episodes, client_type=client_type + ) app.post_processor_queue_scheduler.action.add_item(queue_item) def _clean(self, client): diff --git a/medusa/server/api/v2/config.py b/medusa/server/api/v2/config.py index 1660ed7584..c59baf83cd 100644 --- a/medusa/server/api/v2/config.py +++ b/medusa/server/api/v2/config.py @@ -240,6 +240,9 @@ class ConfigHandler(BaseRequestHandler): 'postProcessing.showDownloadDir': StringField(app, 'TV_DOWNLOAD_DIR'), 'postProcessing.processAutomatically': BooleanField(app, 'PROCESS_AUTOMATICALLY'), 'postProcessing.processMethod': StringField(app, 'PROCESS_METHOD'), + 'postProcessing.specificProcessMethod': BooleanField(app, 'USE_SPECIFIC_PROCESS_METHOD'), + 'postProcessing.processMethodTorrent': StringField(app, 'PROCESS_METHOD_TORRENT'), + 'postProcessing.processMethodNzb': StringField(app, 'PROCESS_METHOD_NZB'), 'postProcessing.deleteRarContent': BooleanField(app, 'DELRARCONTENTS'), 'postProcessing.unpack': BooleanField(app, 'UNPACK'), 'postProcessing.noDelete': BooleanField(app, 'NO_DELETE'), @@ -1230,6 +1233,9 @@ def data_postprocessing(): section_data['deleteRarContent'] = bool(app.DELRARCONTENTS) section_data['noDelete'] = bool(app.NO_DELETE) section_data['processMethod'] = app.PROCESS_METHOD + section_data['specificProcessMethod'] = bool(app.USE_SPECIFIC_PROCESS_METHOD) + section_data['processMethodTorrent'] = app.PROCESS_METHOD_TORRENT + section_data['processMethodNzb'] = app.PROCESS_METHOD_NZB section_data['reflinkAvailable'] = bool(pkgutil.find_loader('reflink')) section_data['autoPostprocessorFrequency'] = int(app.AUTOPOSTPROCESSOR_FREQUENCY) section_data['syncFiles'] = app.SYNC_FILES diff --git a/themes-default/slim/src/components/config-post-processing.vue b/themes-default/slim/src/components/config-post-processing.vue index aee5a5dd51..9217858f2f 100644 --- a/themes-default/slim/src/components/config-post-processing.vue +++ b/themes-default/slim/src/components/config-post-processing.vue @@ -34,7 +34,7 @@
@@ -88,7 +88,7 @@ - What method should be used to put files into the library? @@ -96,6 +96,28 @@

To use reference linking, the reflink package needs to be installed.

+ + Enable this option if you want to use different processing methods (copy, move, etc..) for torrent and nzb downloads. +

Note:This option is only used by the Automated Download Handling option

+ + + + + What method should be used to put files into the library? +

Note: If you keep seeding torrents after they finish, please avoid the 'move' processing method to prevent errors.

+

To use reference linking, the reflink package needs to be installed.

+
+ + + + What method should be used to put files into the library? +

To use reference linking, the reflink package needs to be installed.

+
+ Wait to process a folder if sync files are present. diff --git a/themes-default/slim/test/specs/__snapshots__/config-post-processing.spec.js.snap b/themes-default/slim/test/specs/__snapshots__/config-post-processing.spec.js.snap index c98c1645fb..11f021327e 100644 --- a/themes-default/slim/test/specs/__snapshots__/config-post-processing.spec.js.snap +++ b/themes-default/slim/test/specs/__snapshots__/config-post-processing.spec.js.snap @@ -181,6 +181,9 @@ exports[`ConfigPostProcessing.test.js renders 1`] = `
+

Automated Download Handling

@@ -511,8 +514,8 @@ exports[`ConfigPostProcessing.test.js renders 1`] = ` >