Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific torrent/nzb options for the process method. #9932

Merged
merged 4 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 8 additions & 0 deletions medusa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions medusa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions medusa/process_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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': {
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions medusa/schedulers/download_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions medusa/server/api/v2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions themes-default/slim/src/components/config-post-processing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<div class="row component-group">
<div class="component-group-desc col-xs-12 col-md-2">
<h3>Automated Download Handling</h3>
<a name="automated-download-handling" /><h3>Automated Download Handling</h3>
<p>Check clients directly through api's for completed or failed downloads.</p>
<p>The download handler will periodically connect to the nzb or torrent clients and check for completed and failed downloads.</p>
</div>
Expand Down Expand Up @@ -88,14 +88,36 @@
</config-template>

<config-template label-for="processing_method" label="Processing Method">
<select id="naming_multi_ep" name="naming_multi_ep" v-model="postprocessing.processMethod" class="form-control input-sm">
<select id="processing_method" name="processing_method" v-model="postprocessing.processMethod" class="form-control input-sm">
<option :value="option.value" v-for="option in processMethods" :key="option.value">{{ option.text }}</option>
</select>
<span>What method should be used to put files into the library?</span>
<p><b>Note:</b> If you keep seeding torrents after they finish, please avoid the 'move' processing method to prevent errors.</p>
<p v-if="postprocessing.processMethod == 'reflink'">To use reference linking, the <app-link href="http://www.dereferer.org/?https://pypi.python.org/pypi/reflink/0.1.4">reflink package</app-link> needs to be installed.</p>
</config-template>

<config-toggle-slider v-model="postprocessing.specificPostProcessing" label="Specific postprocessing methods" id="specific_post_processing">
<span>Enable this option if you want to use different processing methods (copy, move, etc..) for torrent and nzb downloads.</span>
<p><b>Note:</b>This option is only used by the <a href="config/postProcessing/#automated-download-handling">Automated Download Handling</a> option</p>
</config-toggle-slider>

<config-template v-if="postprocessing.specificPostProcessing" label-for="processing_method_torrent" label="Processing Method Torrent">
<select id="processing_method_torrent" name="processing_method_torrent" v-model="postprocessing.processMethodTorrent" class="form-control input-sm">
<option :value="option.value" v-for="option in processMethods" :key="option.value">{{ option.text }}</option>
</select>
<span>What method should be used to put files into the library?</span>
<p><b>Note:</b> If you keep seeding torrents after they finish, please avoid the 'move' processing method to prevent errors.</p>
<p v-if="postprocessing.processMethod == 'reflink'">To use reference linking, the <app-link href="http://www.dereferer.org/?https://pypi.python.org/pypi/reflink/0.1.4">reflink package</app-link> needs to be installed.</p>
</config-template>

<config-template v-if="postprocessing.specificPostProcessing" label-for="processing_method_nzb" label="Processing Method Nzb">
<select id="processing_method_nzb" name="processing_method_nzb" v-model="postprocessing.processMethodNzb" class="form-control input-sm">
<option :value="option.value" v-for="option in processMethods" :key="option.value">{{ option.text }}</option>
</select>
<span>What method should be used to put files into the library?</span>
<p v-if="postprocessing.processMethod == 'reflink'">To use reference linking, the <app-link href="http://www.dereferer.org/?https://pypi.python.org/pypi/reflink/0.1.4">reflink package</app-link> needs to be installed.</p>
</config-template>

<config-toggle-slider v-model="postprocessing.postponeIfSyncFiles" label="Postpone post-processing" id="postpone_if_sync_files">
<span>Wait to process a folder if sync files are present.</span>
</config-toggle-slider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ exports[`ConfigPostProcessing.test.js renders 1`] = `
<div
class="component-group-desc col-xs-12 col-md-2"
>
<a
name="automated-download-handling"
/>
<h3>
Automated Download Handling
</h3>
Expand Down Expand Up @@ -511,8 +514,8 @@ exports[`ConfigPostProcessing.test.js renders 1`] = `
>
<select
class="form-control input-sm"
id="naming_multi_ep"
name="naming_multi_ep"
id="processing_method"
name="processing_method"
>
<option
value="copy"
Expand Down Expand Up @@ -560,6 +563,66 @@ exports[`ConfigPostProcessing.test.js renders 1`] = `
</div>
</div>

<div
id="config-toggle-slider-content"
>
<div
class="form-group"
>
<div
class="row"
>
<div
class="col-sm-2"
>
<label
class="control-label"
for="specific_post_processing"
>
<span>
Specific postprocessing methods
</span>
</label>
</div>

<div
class="col-sm-10 content"
>
<toggle-button-stub
height="22"
id="specific_post_processing"
name="specific_post_processing"
sync=""
width="45"
/>

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

<p>
<b>
Note:
</b>
This option is only used by the
<a
href="config/postProcessing/#automated-download-handling"
>
Automated Download Handling
</a>
option
</p>

<!---->
</div>
</div>
</div>
</div>

<!---->

<!---->

<div
id="config-toggle-slider-content"
>
Expand Down
Loading