mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-22 06:13:19 -07:00
Standardize auto-processors
This commit is contained in:
parent
457f2a1061
commit
08104ed18d
6 changed files with 148 additions and 177 deletions
|
@ -36,9 +36,8 @@ def process(
|
||||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||||
if not server_responding(url):
|
if not server_responding(url):
|
||||||
logger.error('Server did not respond. Exiting', section)
|
logger.error('Server did not respond. Exiting', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
f'{section}: Failed to post-process - {section} did not respond.'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||||
|
@ -54,28 +53,27 @@ def process(
|
||||||
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error('Unable to open URL')
|
logger.error('Unable to open URL')
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to connect to {1}'.format(section, section),
|
f'{section}: Failed to post-process - Unable to connect to '
|
||||||
status_code=1,
|
f'{section}'
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.postprocess('{0}'.format(r.text), section)
|
logger.postprocess('{0}'.format(r.text), section)
|
||||||
|
|
||||||
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
||||||
logger.error('Server returned status {0}'.format(r.status_code), section)
|
logger.error('Server returned status {0}'.format(r.status_code), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
f'{section}: Failed to post-process - Server returned status '
|
||||||
status_code=1,
|
f'{r.status_code}'
|
||||||
)
|
)
|
||||||
elif r.text == 'OK':
|
elif r.text == 'OK':
|
||||||
logger.postprocess('SUCCESS: ForceProcess for {0} has been started in LazyLibrarian'.format(dir_name), section)
|
logger.postprocess('SUCCESS: ForceProcess for {0} has been started in LazyLibrarian'.format(dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.error('FAILED: ForceProcess of {0} has Failed in LazyLibrarian'.format(dir_name), section)
|
logger.error('FAILED: ForceProcess of {0} has Failed in LazyLibrarian'.format(dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
f'{section}: Failed to post-process - Returned log from {section} '
|
||||||
status_code=1,
|
f'was not as expected.'
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,9 +34,8 @@ def process(
|
||||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||||
if not server_responding(url):
|
if not server_responding(url):
|
||||||
logger.error('Server did not respond. Exiting', section)
|
logger.error('Server did not respond. Exiting', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
f'{section}: Failed to post-process - {section} did not respond.'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||||
|
@ -63,15 +62,15 @@ def process(
|
||||||
r = requests.post(url, params=params, stream=True, verify=False, timeout=(30, 300))
|
r = requests.post(url, params=params, stream=True, verify=False, timeout=(30, 300))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error('Unable to open URL', section)
|
logger.error('Unable to open URL', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
f'{section}: Failed to post-process - Unable to connect to '
|
||||||
status_code=1,
|
f'{section}'
|
||||||
)
|
)
|
||||||
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
||||||
logger.error('Server returned status {0}'.format(r.status_code), section)
|
logger.error('Server returned status {0}'.format(r.status_code), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
f'{section}: Failed to post-process - Server returned status '
|
||||||
status_code=1,
|
f'{r.status_code}'
|
||||||
)
|
)
|
||||||
|
|
||||||
result = r.text
|
result = r.text
|
||||||
|
@ -85,13 +84,12 @@ def process(
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
logger.postprocess('SUCCESS: This issue has been processed successfully', section)
|
logger.postprocess('SUCCESS: This issue has been processed successfully', section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning('The issue does not appear to have successfully processed. Please check your Logs', section)
|
logger.warning('The issue does not appear to have successfully processed. Please check your Logs', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
f'{section}: Failed to post-process - Returned log from '
|
||||||
status_code=1,
|
f'{section} was not as expected.'
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,9 +34,8 @@ def process(
|
||||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||||
if not server_responding(url):
|
if not server_responding(url):
|
||||||
logger.error('Server did not respond. Exiting', section)
|
logger.error('Server did not respond. Exiting', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
f'{section}: Failed to post-process - {section} did not respond.'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||||
|
@ -60,9 +59,9 @@ def process(
|
||||||
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error('Unable to open URL')
|
logger.error('Unable to open URL')
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to connect to {1}'.format(section, section),
|
f'{section}: Failed to post-process - Unable to connect to '
|
||||||
status_code=1,
|
f'{section}'
|
||||||
)
|
)
|
||||||
|
|
||||||
result = r.json()
|
result = r.json()
|
||||||
|
@ -73,32 +72,30 @@ def process(
|
||||||
shutil.move(dir_name, os.path.join(library, input_name))
|
shutil.move(dir_name, os.path.join(library, input_name))
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error('Unable to move {0} to {1}'.format(dir_name, os.path.join(library, input_name)), section)
|
logger.error('Unable to move {0} to {1}'.format(dir_name, os.path.join(library, input_name)), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to move files'.format(section),
|
f'{section}: Failed to post-process - Unable to move files'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.error('No library specified to move files to. Please edit your configuration.', section)
|
logger.error('No library specified to move files to. Please edit your configuration.', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - No library defined in {0}'.format(section),
|
f'{section}: Failed to post-process - No library defined in '
|
||||||
status_code=1,
|
f'{section}'
|
||||||
)
|
)
|
||||||
|
|
||||||
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
||||||
logger.error('Server returned status {0}'.format(r.status_code), section)
|
logger.error('Server returned status {0}'.format(r.status_code), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
f'{section}: Failed to post-process - Server returned status '
|
||||||
status_code=1,
|
f'{r.status_code}'
|
||||||
)
|
)
|
||||||
elif result['success']:
|
elif result['success']:
|
||||||
logger.postprocess('SUCCESS: Status for {0} has been set to {1} in Gamez'.format(gamez_id, download_status), section)
|
logger.postprocess('SUCCESS: Status for {0} has been set to {1} in Gamez'.format(gamez_id, download_status), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.error('FAILED: Status for {0} has NOT been updated in Gamez'.format(gamez_id), section)
|
logger.error('FAILED: Status for {0} has NOT been updated in Gamez'.format(gamez_id), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
f'{section}: Failed to post-process - Returned log from {section} '
|
||||||
status_code=1,
|
f'was not as expected.'
|
||||||
)
|
)
|
||||||
|
|
|
@ -88,9 +88,8 @@ def process(
|
||||||
release = None
|
release = None
|
||||||
else:
|
else:
|
||||||
logger.error('Server did not respond. Exiting', section)
|
logger.error('Server did not respond. Exiting', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
f'{section}: Failed to post-process - {section} did not respond.'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# pull info from release found if available
|
# pull info from release found if available
|
||||||
|
@ -368,29 +367,28 @@ def process(
|
||||||
r = requests.get(url, params={'media_id': media_id}, verify=False, timeout=(30, 600))
|
r = requests.get(url, params={'media_id': media_id}, verify=False, timeout=(30, 600))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error('Unable to open URL {0}'.format(url), section)
|
logger.error('Unable to open URL {0}'.format(url), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
f'{section}: Failed to post-process - Unable to connect to '
|
||||||
status_code=1,
|
f'{section}'
|
||||||
)
|
)
|
||||||
|
|
||||||
result = r.json()
|
result = r.json()
|
||||||
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
||||||
logger.error('Server returned status {0}'.format(r.status_code), section)
|
logger.error('Server returned status {0}'.format(r.status_code), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
f'{section}: Failed to post-process - Server returned status '
|
||||||
status_code=1,
|
f'{r.status_code}'
|
||||||
)
|
)
|
||||||
elif result['success']:
|
elif result['success']:
|
||||||
logger.postprocess('SUCCESS: Snatched the next highest release ...', section)
|
logger.postprocess('SUCCESS: Snatched the next highest release ...', section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully snatched next highest release'.format(section),
|
f'{section}: Successfully snatched next highest release'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.postprocess('SUCCESS: Unable to find a new release to snatch now. CP will keep searching!', section)
|
logger.postprocess('SUCCESS: Unable to find a new release to snatch now. CP will keep searching!', section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
status_code=0,
|
f'{section}: No new release found now. '
|
||||||
message='{0}: No new release found now. {0} will keep searching'.format(section),
|
f'{section} will keep searching'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Added a release that was not in the wanted list so confirm rename successful by finding this movie media.list.
|
# Added a release that was not in the wanted list so confirm rename successful by finding this movie media.list.
|
||||||
|
@ -398,9 +396,9 @@ def process(
|
||||||
download_id = None # we don't want to filter new releases based on this.
|
download_id = None # we don't want to filter new releases based on this.
|
||||||
|
|
||||||
if no_status_check:
|
if no_status_check:
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
status_code=0,
|
f'{section}: Successfully processed but no change in status '
|
||||||
message='{0}: Successfully processed but no change in status confirmed'.format(section),
|
f'confirmed'
|
||||||
)
|
)
|
||||||
|
|
||||||
# we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing.
|
# we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing.
|
||||||
|
@ -420,17 +418,15 @@ def process(
|
||||||
title = release[release_id]['title']
|
title = release[release_id]['title']
|
||||||
logger.postprocess('SUCCESS: Movie {0} has now been added to CouchPotato with release status of [{1}]'.format(
|
logger.postprocess('SUCCESS: Movie {0} has now been added to CouchPotato with release status of [{1}]'.format(
|
||||||
title, str(release_status_new).upper()), section)
|
title, str(release_status_new).upper()), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if release_status_new != release_status_old:
|
if release_status_new != release_status_old:
|
||||||
logger.postprocess('SUCCESS: Release {0} has now been marked with a status of [{1}]'.format(
|
logger.postprocess('SUCCESS: Release {0} has now been marked with a status of [{1}]'.format(
|
||||||
release_id, str(release_status_new).upper()), section)
|
release_id, str(release_status_new).upper()), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
@ -441,9 +437,8 @@ def process(
|
||||||
logger.debug('The Scan command return status: {0}'.format(command_status), section)
|
logger.debug('The Scan command return status: {0}'.format(command_status), section)
|
||||||
if command_status in ['completed']:
|
if command_status in ['completed']:
|
||||||
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
elif command_status in ['failed']:
|
elif command_status in ['failed']:
|
||||||
logger.debug('The Scan command has failed. Renaming was not successful.', section)
|
logger.debug('The Scan command has failed. Renaming was not successful.', section)
|
||||||
|
@ -455,17 +450,15 @@ def process(
|
||||||
if not os.path.isdir(dir_name):
|
if not os.path.isdir(dir_name):
|
||||||
logger.postprocess('SUCCESS: Input Directory [{0}] has been processed and removed'.format(
|
logger.postprocess('SUCCESS: Input Directory [{0}] has been processed and removed'.format(
|
||||||
dir_name), section)
|
dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
status_code=0,
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
elif not list_media_files(dir_name, media=True, audio=False, meta=False, archives=True):
|
elif not list_media_files(dir_name, media=True, audio=False, meta=False, archives=True):
|
||||||
logger.postprocess('SUCCESS: Input Directory [{0}] has no remaining media files. This has been fully processed.'.format(
|
logger.postprocess('SUCCESS: Input Directory [{0}] has no remaining media files. This has been fully processed.'.format(
|
||||||
dir_name), section)
|
dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# pause and let CouchPotatoServer/Radarr catch its breath
|
# pause and let CouchPotatoServer/Radarr catch its breath
|
||||||
|
@ -474,18 +467,17 @@ def process(
|
||||||
# The status hasn't changed. we have waited wait_for minutes which is more than enough. uTorrent can resume seeding now.
|
# The status hasn't changed. we have waited wait_for minutes which is more than enough. uTorrent can resume seeding now.
|
||||||
if section == 'Radarr' and completed_download_handling(url2, headers, section=section):
|
if section == 'Radarr' and completed_download_handling(url2, headers, section=section):
|
||||||
logger.debug('The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.'.format(section), section)
|
logger.debug('The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.'.format(section), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Complete DownLoad Handling is enabled. Passing back to {0}'.format(section),
|
f'{section}: Complete DownLoad Handling is enabled. Passing back '
|
||||||
status_code=status,
|
f'to {section}'
|
||||||
)
|
)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
'{0} does not appear to have changed status after {1} minutes, Please check your logs.'.format(input_name, wait_for),
|
'{0} does not appear to have changed status after {1} minutes, Please check your logs.'.format(input_name, wait_for),
|
||||||
section,
|
section,
|
||||||
)
|
)
|
||||||
|
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
status_code=1,
|
f'{section}: Failed to post-process - No change in status'
|
||||||
message='{0}: Failed to post-process - No change in status'.format(section),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,8 @@ def process(
|
||||||
url = core.utils.common.create_url(scheme, host, port, route)
|
url = core.utils.common.create_url(scheme, host, port, route)
|
||||||
if not server_responding(url):
|
if not server_responding(url):
|
||||||
logger.error('Server did not respond. Exiting', section)
|
logger.error('Server did not respond. Exiting', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
f'{section}: Failed to post-process - {section} did not respond.'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not os.path.isdir(dir_name) and os.path.isfile(dir_name): # If the input directory is a file, assume single file download and split dir/name.
|
if not os.path.isdir(dir_name) and os.path.isfile(dir_name): # If the input directory is a file, assume single file download and split dir/name.
|
||||||
|
@ -95,9 +94,8 @@ def process(
|
||||||
|
|
||||||
# The status hasn't changed. uTorrent can resume seeding now.
|
# The status hasn't changed. uTorrent can resume seeding now.
|
||||||
logger.warning('The music album does not appear to have changed status after {0} minutes. Please check your Logs'.format(wait_for), section)
|
logger.warning('The music album does not appear to have changed status after {0} minutes. Please check your Logs'.format(wait_for), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - No change in wanted status'.format(section),
|
f'{section}: Failed to post-process - No change in wanted status'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
elif status == 0 and section == 'Lidarr':
|
elif status == 0 and section == 'Lidarr':
|
||||||
|
@ -116,9 +114,9 @@ def process(
|
||||||
r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800))
|
r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error('Unable to open URL: {0}'.format(url), section)
|
logger.error('Unable to open URL: {0}'.format(url), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
f'{section}: Failed to post-process - Unable to connect to '
|
||||||
status_code=1,
|
f'{section}'
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -127,9 +125,8 @@ def process(
|
||||||
logger.debug('Scan started with id: {0}'.format(scan_id), section)
|
logger.debug('Scan started with id: {0}'.format(scan_id), section)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning('No scan id was returned due to: {0}'.format(e), section)
|
logger.warning('No scan id was returned due to: {0}'.format(e), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to start scan'.format(section),
|
f'{section}: Failed to post-process - Unable to start scan'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
n = 0
|
n = 0
|
||||||
|
@ -145,44 +142,43 @@ def process(
|
||||||
logger.debug('The Scan command return status: {0}'.format(command_status), section)
|
logger.debug('The Scan command return status: {0}'.format(command_status), section)
|
||||||
if not os.path.exists(dir_name):
|
if not os.path.exists(dir_name):
|
||||||
logger.debug('The directory {0} has been removed. Renaming was successful.'.format(dir_name), section)
|
logger.debug('The directory {0} has been removed. Renaming was successful.'.format(dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
elif command_status and command_status in ['completed']:
|
elif command_status and command_status in ['completed']:
|
||||||
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
elif command_status and command_status in ['failed']:
|
elif command_status and command_status in ['failed']:
|
||||||
logger.debug('The Scan command has failed. Renaming was not successful.', section)
|
logger.debug('The Scan command has failed. Renaming was not successful.', section)
|
||||||
# return ProcessResult(
|
# return ProcessResult.failure(
|
||||||
# message='{0}: Failed to post-process {1}'.format(section, input_name),
|
# f'{section}: Failed to post-process {input_name}'
|
||||||
# status_code=1,
|
|
||||||
# )
|
# )
|
||||||
else:
|
else:
|
||||||
logger.debug('The Scan command did not return status completed. Passing back to {0} to attempt complete download handling.'.format(section), section)
|
logger.debug('The Scan command did not return status completed. Passing back to {0} to attempt complete download handling.'.format(section), section)
|
||||||
return ProcessResult(
|
return ProcessResult(
|
||||||
message='{0}: Passing back to {0} to attempt Complete Download Handling'.format(section),
|
message=f'{section}: Passing back to {section} to attempt '
|
||||||
|
f'Complete Download Handling',
|
||||||
status_code=status,
|
status_code=status,
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if section == 'Lidarr':
|
if section == 'Lidarr':
|
||||||
logger.postprocess('FAILED: The download failed. Sending failed download to {0} for CDH processing'.format(section), section)
|
logger.postprocess('FAILED: The download failed. Sending failed download to {0} for CDH processing'.format(section), section)
|
||||||
return ProcessResult(
|
# Return as failed to flag this in the downloader.
|
||||||
message='{0}: Download Failed. Sending back to {0}'.format(section),
|
return ProcessResult.failure(
|
||||||
status_code=1, # Return as failed to flag this in the downloader.
|
f'{section}: Download Failed. Sending back to {section}'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning('FAILED DOWNLOAD DETECTED', section)
|
logger.warning('FAILED DOWNLOAD DETECTED', section)
|
||||||
if delete_failed and os.path.isdir(dir_name) and not os.path.dirname(dir_name) == dir_name:
|
if delete_failed and os.path.isdir(dir_name) and not os.path.dirname(dir_name) == dir_name:
|
||||||
logger.postprocess('Deleting failed files and folder {0}'.format(dir_name), section)
|
logger.postprocess('Deleting failed files and folder {0}'.format(dir_name), section)
|
||||||
remove_dir(dir_name)
|
remove_dir(dir_name)
|
||||||
return ProcessResult(
|
# Return as failed to flag this in the downloader.
|
||||||
message='{0}: Failed to post-process. {0} does not support failed downloads'.format(section),
|
return ProcessResult.failure(
|
||||||
status_code=1, # Return as failed to flag this in the downloader.
|
f'{section}: Failed to post-process. {section} does not '
|
||||||
|
f'support failed downloads'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,26 +220,25 @@ def force_process(params, url, apikey, input_name, dir_name, section, wait_for):
|
||||||
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error('Unable to open URL {0}'.format(url), section)
|
logger.error('Unable to open URL {0}'.format(url), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
f'{section}: Failed to post-process - Unable to connect to '
|
||||||
status_code=1,
|
f'{section}'
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug('Result: {0}'.format(r.text), section)
|
logger.debug('Result: {0}'.format(r.text), section)
|
||||||
|
|
||||||
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
||||||
logger.error('Server returned status {0}'.format(r.status_code), section)
|
logger.error('Server returned status {0}'.format(r.status_code), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
f'{section}: Failed to post-process - Server returned status {r.status_code}'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
elif r.text == 'OK':
|
elif r.text == 'OK':
|
||||||
logger.postprocess('SUCCESS: Post-Processing started for {0} in folder {1} ...'.format(input_name, dir_name), section)
|
logger.postprocess('SUCCESS: Post-Processing started for {0} in folder {1} ...'.format(input_name, dir_name), section)
|
||||||
else:
|
else:
|
||||||
logger.error('FAILED: Post-Processing has NOT started for {0} in folder {1}. exiting!'.format(input_name, dir_name), section)
|
logger.error('FAILED: Post-Processing has NOT started for {0} in folder {1}. exiting!'.format(input_name, dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
f'{section}: Failed to post-process - Returned log from {section} '
|
||||||
status_code=1,
|
f'was not as expected.'
|
||||||
)
|
)
|
||||||
|
|
||||||
# we will now wait for this album to be processed before returning to TorrentToMedia and unpausing.
|
# we will now wait for this album to be processed before returning to TorrentToMedia and unpausing.
|
||||||
|
@ -252,15 +247,13 @@ def force_process(params, url, apikey, input_name, dir_name, section, wait_for):
|
||||||
current_status = get_status(url, apikey, dir_name)
|
current_status = get_status(url, apikey, dir_name)
|
||||||
if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie.
|
if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie.
|
||||||
logger.postprocess('SUCCESS: This release is now marked as status [{0}]'.format(current_status), section)
|
logger.postprocess('SUCCESS: This release is now marked as status [{0}]'.format(current_status), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
if not os.path.isdir(dir_name):
|
if not os.path.isdir(dir_name):
|
||||||
logger.postprocess('SUCCESS: The input directory {0} has been removed Processing must have finished.'.format(dir_name), section)
|
logger.postprocess('SUCCESS: The input directory {0} has been removed Processing must have finished.'.format(dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
time.sleep(10 * wait_for)
|
time.sleep(10 * wait_for)
|
||||||
# The status hasn't changed.
|
# The status hasn't changed.
|
||||||
|
|
|
@ -71,9 +71,8 @@ def process(
|
||||||
fork, fork_params = 'None', {}
|
fork, fork_params = 'None', {}
|
||||||
else:
|
else:
|
||||||
logger.error('Server did not respond. Exiting', section)
|
logger.error('Server did not respond. Exiting', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
status_code=1,
|
f'{section}: Failed to post-process - {section} did not respond.'
|
||||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
delete_failed = int(cfg.get('delete_failed', 0))
|
delete_failed = int(cfg.get('delete_failed', 0))
|
||||||
|
@ -161,10 +160,8 @@ def process(
|
||||||
failure_link += '&corrupt=true'
|
failure_link += '&corrupt=true'
|
||||||
elif client_agent == 'manual':
|
elif client_agent == 'manual':
|
||||||
logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section)
|
logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section)
|
||||||
return ProcessResult(
|
# Success (as far as this script is concerned)
|
||||||
message='',
|
return ProcessResult.success()
|
||||||
status_code=0, # Success (as far as this script is concerned)
|
|
||||||
)
|
|
||||||
elif nzb_extraction_by == 'Destination':
|
elif nzb_extraction_by == 'Destination':
|
||||||
logger.info('Check for media files ignored because nzbExtractionBy is set to Destination.')
|
logger.info('Check for media files ignored because nzbExtractionBy is set to Destination.')
|
||||||
if int(failed) == 0:
|
if int(failed) == 0:
|
||||||
|
@ -195,9 +192,8 @@ def process(
|
||||||
core.rchmod(dir_name, chmod_directory)
|
core.rchmod(dir_name, chmod_directory)
|
||||||
else:
|
else:
|
||||||
logger.error('FAILED: Transcoding failed for files in {0}'.format(dir_name), section)
|
logger.error('FAILED: Transcoding failed for files in {0}'.format(dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Transcoding failed'.format(section),
|
f'{section}: Failed to post-process - Transcoding failed'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Part of the refactor
|
# Part of the refactor
|
||||||
|
@ -272,9 +268,8 @@ def process(
|
||||||
if status == 0:
|
if status == 0:
|
||||||
if section == 'NzbDrone' and not apikey:
|
if section == 'NzbDrone' and not apikey:
|
||||||
logger.info('No Sonarr apikey entered. Processing completed.')
|
logger.info('No Sonarr apikey entered. Processing completed.')
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
logger.postprocess('SUCCESS: The download succeeded, sending a post-process request', section)
|
logger.postprocess('SUCCESS: The download succeeded, sending a post-process request', section)
|
||||||
else:
|
else:
|
||||||
|
@ -285,18 +280,19 @@ def process(
|
||||||
logger.postprocess('FAILED: The download failed. Sending \'failed\' process request to {0} branch'.format(fork), section)
|
logger.postprocess('FAILED: The download failed. Sending \'failed\' process request to {0} branch'.format(fork), section)
|
||||||
elif section == 'NzbDrone':
|
elif section == 'NzbDrone':
|
||||||
logger.postprocess('FAILED: The download failed. Sending failed download to {0} for CDH processing'.format(fork), section)
|
logger.postprocess('FAILED: The download failed. Sending failed download to {0} for CDH processing'.format(fork), section)
|
||||||
return ProcessResult(
|
# Return as failed to flag this in the downloader.
|
||||||
message='{0}: Download Failed. Sending back to {0}'.format(section),
|
return ProcessResult.failure(
|
||||||
status_code=1, # Return as failed to flag this in the downloader.
|
f'{section}: Download Failed. Sending back to {section}'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.postprocess('FAILED: The download failed. {0} branch does not handle failed downloads. Nothing to process'.format(fork), section)
|
logger.postprocess('FAILED: The download failed. {0} branch does not handle failed downloads. Nothing to process'.format(fork), section)
|
||||||
if delete_failed and os.path.isdir(dir_name) and not os.path.dirname(dir_name) == dir_name:
|
if delete_failed and os.path.isdir(dir_name) and not os.path.dirname(dir_name) == dir_name:
|
||||||
logger.postprocess('Deleting failed files and folder {0}'.format(dir_name), section)
|
logger.postprocess('Deleting failed files and folder {0}'.format(dir_name), section)
|
||||||
remove_dir(dir_name)
|
remove_dir(dir_name)
|
||||||
return ProcessResult(
|
# Return as failed to flag this in the downloader.
|
||||||
message='{0}: Failed to post-process. {0} does not support failed downloads'.format(section),
|
return ProcessResult.failure(
|
||||||
status_code=1, # Return as failed to flag this in the downloader.
|
f'{section}: Failed to post-process. {section} does not '
|
||||||
|
f'support failed downloads'
|
||||||
)
|
)
|
||||||
|
|
||||||
route = ''
|
route = ''
|
||||||
|
@ -376,16 +372,16 @@ def process(
|
||||||
r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800))
|
r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800))
|
||||||
except requests.ConnectionError:
|
except requests.ConnectionError:
|
||||||
logger.error('Unable to open URL: {0}'.format(url), section)
|
logger.error('Unable to open URL: {0}'.format(url), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
f'{section}: Failed to post-process - Unable to connect to '
|
||||||
status_code=1,
|
f'{section}'
|
||||||
)
|
)
|
||||||
|
|
||||||
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
|
||||||
logger.error('Server returned status {0}'.format(r.status_code), section)
|
logger.error('Server returned status {0}'.format(r.status_code), section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
f'{section}: Failed to post-process - Server returned status '
|
||||||
status_code=1,
|
f'{r.status_code}'
|
||||||
)
|
)
|
||||||
|
|
||||||
success = False
|
success = False
|
||||||
|
@ -431,9 +427,8 @@ def process(
|
||||||
remove_dir(dir_name)
|
remove_dir(dir_name)
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
elif section == 'NzbDrone' and started:
|
elif section == 'NzbDrone' and started:
|
||||||
n = 0
|
n = 0
|
||||||
|
@ -449,21 +444,18 @@ def process(
|
||||||
logger.debug('The Scan command return status: {0}'.format(command_status), section)
|
logger.debug('The Scan command return status: {0}'.format(command_status), section)
|
||||||
if not os.path.exists(dir_name):
|
if not os.path.exists(dir_name):
|
||||||
logger.debug('The directory {0} has been removed. Renaming was successful.'.format(dir_name), section)
|
logger.debug('The directory {0} has been removed. Renaming was successful.'.format(dir_name), section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
elif command_status and command_status in ['completed']:
|
elif command_status and command_status in ['completed']:
|
||||||
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
||||||
return ProcessResult(
|
return ProcessResult.success(
|
||||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
f'{section}: Successfully post-processed {input_name}'
|
||||||
status_code=0,
|
|
||||||
)
|
)
|
||||||
elif command_status and command_status in ['failed']:
|
elif command_status and command_status in ['failed']:
|
||||||
logger.debug('The Scan command has failed. Renaming was not successful.', section)
|
logger.debug('The Scan command has failed. Renaming was not successful.', section)
|
||||||
# return ProcessResult(
|
# return ProcessResult.failure(
|
||||||
# message='{0}: Failed to post-process {1}'.format(section, input_name),
|
# f'{section}: Failed to post-process {input_name}'
|
||||||
# status_code=1,
|
|
||||||
# )
|
# )
|
||||||
|
|
||||||
url2 = core.utils.common.create_url(scheme, host, port, route)
|
url2 = core.utils.common.create_url(scheme, host, port, route)
|
||||||
|
@ -471,17 +463,18 @@ def process(
|
||||||
logger.debug('The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.'.format(section),
|
logger.debug('The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.'.format(section),
|
||||||
section)
|
section)
|
||||||
return ProcessResult(
|
return ProcessResult(
|
||||||
message='{0}: Complete DownLoad Handling is enabled. Passing back to {0}'.format(section),
|
message=f'{section}: Complete DownLoad Handling is enabled. '
|
||||||
|
f'Passing back to {section}',
|
||||||
status_code=status,
|
status_code=status,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning('The Scan command did not return a valid status. Renaming was not successful.', section)
|
logger.warning('The Scan command did not return a valid status. Renaming was not successful.', section)
|
||||||
return ProcessResult(
|
return ProcessResult.failure(
|
||||||
message='{0}: Failed to post-process {1}'.format(section, input_name),
|
f'{section}: Failed to post-process {input_name}'
|
||||||
status_code=1,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return ProcessResult(
|
# We did not receive Success confirmation.
|
||||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
return ProcessResult.failure(
|
||||||
status_code=1, # We did not receive Success confirmation.
|
f'{section}: Failed to post-process - Returned log from {section} '
|
||||||
|
f'was not as expected.'
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue