mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-05 20:51:11 -07:00
Fixes for user_script categories (#1645)
Fixes for user_script categories. #1643
This commit is contained in:
parent
5714540949
commit
bde5a15f66
2 changed files with 39 additions and 19 deletions
|
@ -76,16 +76,19 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
|
||||
# auto-detect section
|
||||
section = core.CFG.findsection(input_category).isenabled()
|
||||
if section is None:
|
||||
section = core.CFG.findsection('ALL').isenabled()
|
||||
if section is None:
|
||||
logger.error('Category:[{0}] is not defined or is not enabled. '
|
||||
'Please rename it or ensure it is enabled for the appropriate section '
|
||||
'in your autoProcessMedia.cfg and try again.'.format
|
||||
(input_category))
|
||||
return [-1, '']
|
||||
if section is None: #Check for user_scripts for 'ALL' and 'UNCAT'
|
||||
if usercat in core.CATEGORIES:
|
||||
section = core.CFG.findsection('ALL').isenabled()
|
||||
usercat = 'ALL'
|
||||
else:
|
||||
usercat = 'ALL'
|
||||
section = core.CFG.findsection('UNCAT').isenabled()
|
||||
usercat = 'UNCAT'
|
||||
if section is None: # We haven't found any categories to process.
|
||||
logger.error('Category:[{0}] is not defined or is not enabled. '
|
||||
'Please rename it or ensure it is enabled for the appropriate section '
|
||||
'in your autoProcessMedia.cfg and try again.'.format
|
||||
(input_category))
|
||||
return [-1, '']
|
||||
|
||||
if len(section) > 1:
|
||||
logger.error('Category:[{0}] is not unique, {1} are using it. '
|
||||
|
@ -108,7 +111,7 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
torrent_no_link = int(section.get('Torrent_NoLink', 0))
|
||||
keep_archive = int(section.get('keep_archive', 0))
|
||||
extract = int(section.get('extract', 0))
|
||||
extensions = section.get('user_script_mediaExtensions', '').lower().split(',')
|
||||
extensions = section.get('user_script_mediaExtensions', '')
|
||||
unique_path = int(section.get('unique_path', 1))
|
||||
|
||||
if client_agent != 'manual':
|
||||
|
@ -278,7 +281,7 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
|||
replace_links(os.path.join(dirpath, file))
|
||||
core.remove_torrent(client_agent, input_hash, input_id, input_name)
|
||||
|
||||
if not section_name == 'UserScript':
|
||||
if section_name != 'UserScript':
|
||||
# for user script, we assume this is cleaned by the script or option USER_SCRIPT_CLEAN
|
||||
# cleanup our processing folders of any misc unwanted files and empty directories
|
||||
core.clean_dir(output_destination, section_name, input_category)
|
||||
|
|
|
@ -14,33 +14,46 @@ import core
|
|||
from core import logger, transcoder
|
||||
from core.plugins.subtitles import import_subs
|
||||
from core.utils import list_media_files, remove_dir
|
||||
from core.auto_process.common import (
|
||||
ProcessResult,
|
||||
)
|
||||
|
||||
|
||||
|
||||
def external_script(output_destination, torrent_name, torrent_label, settings):
|
||||
final_result = 0 # start at 0.
|
||||
num_files = 0
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS = settings.get('user_script_mediaExtensions', '')
|
||||
try:
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS = settings['user_script_mediaExtensions'].lower()
|
||||
if isinstance(core.USER_SCRIPT_MEDIAEXTENSIONS, str):
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS = core.USER_SCRIPT_MEDIAEXTENSIONS.split(',')
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS = core.USER_SCRIPT_MEDIAEXTENSIONS.lower().split(',')
|
||||
except Exception:
|
||||
logger.error('user_script_mediaExtensions could not be set', 'USERSCRIPT')
|
||||
core.USER_SCRIPT_MEDIAEXTENSIONS = []
|
||||
|
||||
core.USER_SCRIPT = settings.get('user_script_path')
|
||||
core.USER_SCRIPT = settings.get('user_script_path', '')
|
||||
|
||||
if not core.USER_SCRIPT or core.USER_SCRIPT == 'None': # do nothing and return success.
|
||||
return [0, '']
|
||||
if not core.USER_SCRIPT or core.USER_SCRIPT == 'None':
|
||||
# do nothing and return success. This allows the user an option to Link files only and not run a script.
|
||||
return ProcessResult(
|
||||
status_code=0,
|
||||
message='No user script defined',
|
||||
)
|
||||
|
||||
core.USER_SCRIPT_PARAM = settings.get('user_script_param', '')
|
||||
try:
|
||||
core.USER_SCRIPT_PARAM = settings['user_script_param']
|
||||
if isinstance(core.USER_SCRIPT_PARAM, str):
|
||||
core.USER_SCRIPT_PARAM = core.USER_SCRIPT_PARAM.split(',')
|
||||
except Exception:
|
||||
logger.error('user_script_params could not be set', 'USERSCRIPT')
|
||||
core.USER_SCRIPT_PARAM = []
|
||||
|
||||
core.USER_SCRIPT_SUCCESSCODES = settings.get('user_script_successCodes', 0)
|
||||
try:
|
||||
core.USER_SCRIPT_SUCCESSCODES = settings['user_script_successCodes']
|
||||
if isinstance(core.USER_SCRIPT_SUCCESSCODES, str):
|
||||
core.USER_SCRIPT_SUCCESSCODES = core.USER_SCRIPT_SUCCESSCODES.split(',')
|
||||
except Exception:
|
||||
logger.error('user_script_successCodes could not be set', 'USERSCRIPT')
|
||||
core.USER_SCRIPT_SUCCESSCODES = 0
|
||||
|
||||
core.USER_SCRIPT_CLEAN = int(settings.get('user_script_clean', 1))
|
||||
|
@ -59,6 +72,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
|||
|
||||
file_path = core.os.path.join(dirpath, file)
|
||||
file_name, file_extension = os.path.splitext(file)
|
||||
logger.debug('Checking file {0} to see if this should be processed.'.format(file), 'USERSCRIPT')
|
||||
|
||||
if file_extension in core.USER_SCRIPT_MEDIAEXTENSIONS or 'all' in core.USER_SCRIPT_MEDIAEXTENSIONS:
|
||||
num_files += 1
|
||||
|
@ -122,4 +136,7 @@ def external_script(output_destination, torrent_name, torrent_label, settings):
|
|||
elif core.USER_SCRIPT_CLEAN == int(1) and num_files_new != 0:
|
||||
logger.info('{0} files were processed, but {1} still remain. outputDirectory will not be cleaned.'.format(
|
||||
num_files, num_files_new))
|
||||
return [final_result, '']
|
||||
return ProcessResult(
|
||||
status_code=final_result,
|
||||
message='User Script Completed',
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue