mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 10:36:52 -07:00
Fix quotes - standardize to single-quoted strings
This commit is contained in:
parent
85b4e22046
commit
c5343889fb
30 changed files with 1257 additions and 1257 deletions
|
@ -15,34 +15,34 @@ from core.utils import convert_to_ascii, list_media_files, remote_dir, remove_di
|
|||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
||||
def process(section, dir_name, input_name=None, status=0, client_agent="manual", input_category=None):
|
||||
def process(section, dir_name, input_name=None, status=0, client_agent='manual', input_category=None):
|
||||
status = int(status)
|
||||
|
||||
cfg = dict(core.CFG[section][input_category])
|
||||
|
||||
host = cfg["host"]
|
||||
port = cfg["port"]
|
||||
apikey = cfg["apikey"]
|
||||
wait_for = int(cfg["wait_for"])
|
||||
ssl = int(cfg.get("ssl", 0))
|
||||
delete_failed = int(cfg["delete_failed"])
|
||||
web_root = cfg.get("web_root", "")
|
||||
remote_path = int(cfg.get("remote_path", 0))
|
||||
protocol = "https://" if ssl else "http://"
|
||||
host = cfg['host']
|
||||
port = cfg['port']
|
||||
apikey = cfg['apikey']
|
||||
wait_for = int(cfg['wait_for'])
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
delete_failed = int(cfg['delete_failed'])
|
||||
web_root = cfg.get('web_root', '')
|
||||
remote_path = int(cfg.get('remote_path', 0))
|
||||
protocol = 'https://' if ssl else 'http://'
|
||||
status = int(status)
|
||||
if status > 0 and core.NOEXTRACTFAILED:
|
||||
extract = 0
|
||||
else:
|
||||
extract = int(cfg.get("extract", 0))
|
||||
extract = int(cfg.get('extract', 0))
|
||||
|
||||
if section == "Lidarr":
|
||||
url = "{0}{1}:{2}{3}/api/v1".format(protocol, host, port, web_root)
|
||||
if section == 'Lidarr':
|
||||
url = '{0}{1}:{2}{3}/api/v1'.format(protocol, host, port, web_root)
|
||||
else:
|
||||
url = "{0}{1}:{2}{3}/api".format(protocol, host, port, web_root)
|
||||
url = '{0}{1}:{2}{3}/api'.format(protocol, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error("Server did not respond. Exiting", section)
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - {0} did not respond.".format(section),
|
||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
|
@ -51,7 +51,7 @@ def process(section, dir_name, input_name=None, status=0, client_agent="manual",
|
|||
|
||||
specific_path = os.path.join(dir_name, str(input_name))
|
||||
clean_name = os.path.splitext(specific_path)
|
||||
if clean_name[1] == ".nzb":
|
||||
if clean_name[1] == '.nzb':
|
||||
specific_path = clean_name[0]
|
||||
if os.path.isdir(specific_path):
|
||||
dir_name = specific_path
|
||||
|
@ -65,14 +65,14 @@ def process(section, dir_name, input_name=None, status=0, client_agent="manual",
|
|||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
|
||||
# if listMediaFiles(dir_name, media=False, audio=True, meta=False, archives=False) and status:
|
||||
# logger.info("Status shown as failed from Downloader, but valid video files found. Setting as successful.", section)
|
||||
# logger.info('Status shown as failed from Downloader, but valid video files found. Setting as successful.', section)
|
||||
# status = 0
|
||||
|
||||
if status == 0 and section == "HeadPhones":
|
||||
if status == 0 and section == 'HeadPhones':
|
||||
|
||||
params = {
|
||||
'apikey': apikey,
|
||||
'cmd': "forceProcess",
|
||||
'cmd': 'forceProcess',
|
||||
'dir': remote_dir(dir_name) if remote_path else dir_name
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ def process(section, dir_name, input_name=None, status=0, client_agent="manual",
|
|||
|
||||
params = {
|
||||
'apikey': apikey,
|
||||
'cmd': "forceProcess",
|
||||
'cmd': 'forceProcess',
|
||||
'dir': os.path.split(remote_dir(dir_name))[0] if remote_path else os.path.split(dir_name)[0]
|
||||
}
|
||||
|
||||
|
@ -91,29 +91,29 @@ def process(section, dir_name, input_name=None, status=0, client_agent="manual",
|
|||
return res
|
||||
|
||||
# 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(
|
||||
message="{0}: Failed to post-process - No change in wanted status".format(section),
|
||||
message='{0}: Failed to post-process - No change in wanted status'.format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
elif status == 0 and section == "Lidarr":
|
||||
url = "{0}{1}:{2}{3}/api/v1/command".format(protocol, host, port, web_root)
|
||||
headers = {"X-Api-Key": apikey}
|
||||
elif status == 0 and section == 'Lidarr':
|
||||
url = '{0}{1}:{2}{3}/api/v1/command'.format(protocol, host, port, web_root)
|
||||
headers = {'X-Api-Key': apikey}
|
||||
if remote_path:
|
||||
logger.debug("remote_path: {0}".format(remote_dir(dir_name)), section)
|
||||
data = {"name": "Rename", "path": remote_dir(dir_name)}
|
||||
logger.debug('remote_path: {0}'.format(remote_dir(dir_name)), section)
|
||||
data = {'name': 'Rename', 'path': remote_dir(dir_name)}
|
||||
else:
|
||||
logger.debug("path: {0}".format(dir_name), section)
|
||||
data = {"name": "Rename", "path": dir_name}
|
||||
logger.debug('path: {0}'.format(dir_name), section)
|
||||
data = {'name': 'Rename', 'path': dir_name}
|
||||
data = json.dumps(data)
|
||||
try:
|
||||
logger.debug("Opening URL: {0} with data: {1}".format(url, data), section)
|
||||
logger.debug('Opening URL: {0} with data: {1}'.format(url, data), section)
|
||||
r = requests.post(url, data=data, headers=headers, stream=True, verify=False, timeout=(30, 1800))
|
||||
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(
|
||||
message="{0}: Failed to post-process - Unable to connect to {0}".format(section),
|
||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
|
@ -123,20 +123,20 @@ def process(section, dir_name, input_name=None, status=0, client_agent="manual",
|
|||
try:
|
||||
res = json.loads(r.content)
|
||||
scan_id = int(res['id'])
|
||||
logger.debug("Scan started with id: {0}".format(scan_id), section)
|
||||
logger.debug('Scan started with id: {0}'.format(scan_id), section)
|
||||
started = True
|
||||
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)
|
||||
scan_id = None
|
||||
started = False
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Unable to start scan".format(section),
|
||||
message='{0}: Failed to post-process - Unable to start scan'.format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
n = 0
|
||||
params = {}
|
||||
url = "{0}/{1}".format(url, scan_id)
|
||||
url = '{0}/{1}'.format(url, scan_id)
|
||||
while n < 6: # set up wait_for minutes to see if command completes..
|
||||
time.sleep(10 * wait_for)
|
||||
command_status = command_complete(url, params, headers, section)
|
||||
|
@ -144,64 +144,64 @@ def process(section, dir_name, input_name=None, status=0, client_agent="manual",
|
|||
break
|
||||
n += 1
|
||||
if command_status:
|
||||
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):
|
||||
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(
|
||||
message="{0}: Successfully post-processed {1}".format(section, input_name),
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
)
|
||||
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(
|
||||
message="{0}: Successfully post-processed {1}".format(section, input_name),
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
)
|
||||
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(
|
||||
# message="{0}: Failed to post-process {1}".format(section, input_name),
|
||||
# message='{0}: Failed to post-process {1}'.format(section, input_name),
|
||||
# status_code=1,
|
||||
# )
|
||||
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(
|
||||
message="{0}: Passing back to {0} to attempt Complete Download Handling".format(section),
|
||||
message='{0}: Passing back to {0} to attempt Complete Download Handling'.format(section),
|
||||
status_code=status,
|
||||
)
|
||||
|
||||
else:
|
||||
if section == "Lidarr":
|
||||
logger.postprocess("FAILED: The download failed. Sending failed download to {0} for CDH processing".format(section), section)
|
||||
if section == 'Lidarr':
|
||||
logger.postprocess('FAILED: The download failed. Sending failed download to {0} for CDH processing'.format(section), section)
|
||||
return ProcessResult(
|
||||
message="{0}: Download Failed. Sending back to {0}".format(section),
|
||||
message='{0}: Download Failed. Sending back to {0}'.format(section),
|
||||
status_code=1, # Return as failed to flag this in the downloader.
|
||||
)
|
||||
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:
|
||||
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)
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process. {0} does not support failed downloads".format(section),
|
||||
message='{0}: Failed to post-process. {0} does not support failed downloads'.format(section),
|
||||
status_code=1, # Return as failed to flag this in the downloader.
|
||||
)
|
||||
|
||||
|
||||
def get_status(url, apikey, dir_name):
|
||||
logger.debug("Attempting to get current status for release:{0}".format(os.path.basename(dir_name)))
|
||||
logger.debug('Attempting to get current status for release:{0}'.format(os.path.basename(dir_name)))
|
||||
|
||||
params = {
|
||||
'apikey': apikey,
|
||||
'cmd': "getHistory"
|
||||
'cmd': 'getHistory'
|
||||
}
|
||||
|
||||
logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params))
|
||||
logger.debug('Opening URL: {0} with PARAMS: {1}'.format(url, params))
|
||||
|
||||
try:
|
||||
r = requests.get(url, params=params, verify=False, timeout=(30, 120))
|
||||
except requests.RequestException:
|
||||
logger.error("Unable to open URL")
|
||||
logger.error('Unable to open URL')
|
||||
return None
|
||||
|
||||
try:
|
||||
|
@ -212,39 +212,39 @@ def get_status(url, apikey, dir_name):
|
|||
|
||||
for album in result:
|
||||
if os.path.basename(dir_name) == album['FolderName']:
|
||||
return album["Status"].lower()
|
||||
return album['Status'].lower()
|
||||
|
||||
|
||||
def force_process(params, url, apikey, input_name, dir_name, section, wait_for):
|
||||
release_status = get_status(url, apikey, dir_name)
|
||||
if not release_status:
|
||||
logger.error("Could not find a status for {0}, is it in the wanted list ?".format(input_name), section)
|
||||
logger.error('Could not find a status for {0}, is it in the wanted list ?'.format(input_name), section)
|
||||
|
||||
logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params), section)
|
||||
logger.debug('Opening URL: {0} with PARAMS: {1}'.format(url, params), section)
|
||||
|
||||
try:
|
||||
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
||||
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(
|
||||
message="{0}: Failed to post-process - Unable to connect to {0}".format(section),
|
||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
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]:
|
||||
logger.error("Server returned status {0}".format(r.status_code), section)
|
||||
logger.error('Server returned status {0}'.format(r.status_code), section)
|
||||
return ProcessResult(
|
||||
message="{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code),
|
||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
||||
status_code=1,
|
||||
)
|
||||
elif r.text == "OK":
|
||||
logger.postprocess("SUCCESS: Post-Processing started for {0} in folder {1} ...".format(input_name, dir_name), section)
|
||||
elif r.text == 'OK':
|
||||
logger.postprocess('SUCCESS: Post-Processing started for {0} in folder {1} ...'.format(input_name, dir_name), section)
|
||||
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(
|
||||
message="{0}: Failed to post-process - Returned log from {0} was not as expected.".format(section),
|
||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
||||
status_code=1,
|
||||
)
|
||||
|
||||
|
@ -253,20 +253,20 @@ def force_process(params, url, apikey, input_name, dir_name, section, wait_for):
|
|||
while time.time() < timeout:
|
||||
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.
|
||||
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(
|
||||
message="{0}: Successfully post-processed {1}".format(section, input_name),
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
)
|
||||
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(
|
||||
message="{0}: Successfully post-processed {1}".format(section, input_name),
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
)
|
||||
time.sleep(10 * wait_for)
|
||||
# The status hasn't changed.
|
||||
return ProcessResult(
|
||||
message="no change",
|
||||
message='no change',
|
||||
status_code=2,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue