mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-03-12 12:35:28 -07:00
commit
3388768fb1
@ -235,26 +235,35 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
|
||||
if core.TORRENT_CHMOD_DIRECTORY:
|
||||
core.rchmod(output_destination, core.TORRENT_CHMOD_DIRECTORY)
|
||||
|
||||
result = ProcessResult(
|
||||
message='',
|
||||
status_code=0,
|
||||
)
|
||||
if section_name == 'UserScript':
|
||||
result = external_script(output_destination, input_name, input_category, section)
|
||||
elif section_name in ['CouchPotato', 'Radarr', 'Watcher3']:
|
||||
result = movies.process(section_name, output_destination, input_name, status, client_agent, input_hash, input_category)
|
||||
elif section_name in ['SickBeard', 'SiCKRAGE', 'NzbDrone', 'Sonarr']:
|
||||
if input_hash:
|
||||
else:
|
||||
process_map = {
|
||||
'CouchPotato': movies.process,
|
||||
'Radarr': movies.process,
|
||||
'Watcher3': movies.process,
|
||||
'SickBeard': tv.process,
|
||||
'SiCKRAGE': tv.process,
|
||||
'NzbDrone': tv.process,
|
||||
'Sonarr': tv.process,
|
||||
'LazyLibrarian': books.process,
|
||||
'HeadPhones': music.process,
|
||||
'Lidarr': music.process,
|
||||
'Mylar': comics.process,
|
||||
'Gamez': games.process,
|
||||
}
|
||||
if input_hash and section_name in ['SickBeard', 'SiCKRAGE', 'NzbDrone', 'Sonarr']:
|
||||
input_hash = input_hash.upper()
|
||||
result = tv.process(section_name, output_destination, input_name, status, client_agent, input_hash, input_category)
|
||||
elif section_name in ['HeadPhones', 'Lidarr']:
|
||||
result = music.process(section_name, output_destination, input_name, status, client_agent, input_category)
|
||||
elif section_name == 'Mylar':
|
||||
result = comics.process(section_name, output_destination, input_name, status, client_agent, input_category)
|
||||
elif section_name == 'Gamez':
|
||||
result = games.process(section_name, output_destination, input_name, status, client_agent, input_category)
|
||||
elif section_name == 'LazyLibrarian':
|
||||
result = books.process(section_name, output_destination, input_name, status, client_agent, input_category)
|
||||
processor = process_map[section_name]
|
||||
result = processor(
|
||||
section=section_name,
|
||||
dir_name=output_destination,
|
||||
input_name=input_name,
|
||||
status=status,
|
||||
client_agent=client_agent,
|
||||
download_id=input_hash,
|
||||
input_category=input_category,
|
||||
)
|
||||
|
||||
plex_update(input_category)
|
||||
|
||||
|
@ -1,11 +1,33 @@
|
||||
import copy
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
import requests
|
||||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core import logger, transcoder
|
||||
from core.auto_process.common import (
|
||||
ProcessResult,
|
||||
command_complete,
|
||||
completed_download_handling,
|
||||
)
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs, rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils import (
|
||||
convert_to_ascii,
|
||||
find_download,
|
||||
find_imdbid,
|
||||
flatten,
|
||||
list_media_files,
|
||||
remote_dir,
|
||||
remove_dir,
|
||||
server_responding,
|
||||
)
|
||||
|
||||
@ -14,31 +36,41 @@ requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
||||
def process(
|
||||
section,
|
||||
dir_name,
|
||||
input_name=None,
|
||||
status=0,
|
||||
client_agent='manual',
|
||||
input_category=None,
|
||||
*,
|
||||
section: str,
|
||||
dir_name: str,
|
||||
input_name: str = '',
|
||||
status: int = 0,
|
||||
failed: bool = False,
|
||||
client_agent: str = 'manual',
|
||||
download_id: str = '',
|
||||
input_category: str = '',
|
||||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
status = int(status)
|
||||
|
||||
cfg = dict(core.CFG[section][input_category])
|
||||
# Get configuration
|
||||
cfg = core.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
scheme = 'https' if ssl else 'http'
|
||||
host = cfg['host']
|
||||
port = cfg['port']
|
||||
apikey = cfg['apikey']
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
web_root = cfg.get('web_root', '')
|
||||
scheme = 'https' if ssl else 'http'
|
||||
|
||||
# Authentication
|
||||
apikey = cfg.get('apikey', '')
|
||||
|
||||
# Params
|
||||
remote_path = int(cfg.get('remote_path', 0))
|
||||
|
||||
# Misc
|
||||
|
||||
# Begin processing
|
||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - {section} did not respond.'
|
||||
)
|
||||
|
||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
@ -48,34 +80,34 @@ def process(
|
||||
'cmd': 'forceProcess',
|
||||
'dir': remote_dir(dir_name) if remote_path else dir_name,
|
||||
}
|
||||
|
||||
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')
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Unable to connect to {1}'.format(section, section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to connect to '
|
||||
f'{section}'
|
||||
)
|
||||
|
||||
logger.postprocess('{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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Server returned status '
|
||||
f'{r.status_code}'
|
||||
)
|
||||
elif r.text == 'OK':
|
||||
logger.postprocess('SUCCESS: ForceProcess for {0} has been started in LazyLibrarian'.format(dir_name), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
else:
|
||||
logger.error('FAILED: ForceProcess of {0} has Failed in LazyLibrarian'.format(dir_name), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Returned log from {section} '
|
||||
f'was not as expected.'
|
||||
)
|
||||
|
@ -1,42 +1,78 @@
|
||||
import copy
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
import requests
|
||||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.utils import convert_to_ascii, remote_dir, server_responding
|
||||
from core import logger, transcoder
|
||||
from core.auto_process.common import (
|
||||
ProcessResult,
|
||||
command_complete,
|
||||
completed_download_handling,
|
||||
)
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs, rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils import (
|
||||
convert_to_ascii,
|
||||
find_download,
|
||||
find_imdbid,
|
||||
flatten,
|
||||
list_media_files,
|
||||
remote_dir,
|
||||
remove_dir,
|
||||
server_responding,
|
||||
)
|
||||
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
||||
def process(
|
||||
section,
|
||||
dir_name,
|
||||
input_name=None,
|
||||
status=0,
|
||||
client_agent='manual',
|
||||
input_category=None,
|
||||
*,
|
||||
section: str,
|
||||
dir_name: str,
|
||||
input_name: str = '',
|
||||
status: int = 0,
|
||||
failed: bool = False,
|
||||
client_agent: str = 'manual',
|
||||
download_id: str = '',
|
||||
input_category: str = '',
|
||||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
# Get configuration
|
||||
cfg = core.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
scheme = 'https' if ssl else 'http'
|
||||
host = cfg['host']
|
||||
port = cfg['port']
|
||||
web_root = cfg.get('web_root', '')
|
||||
|
||||
# Authentication
|
||||
apikey = cfg.get('apikey', '')
|
||||
|
||||
# Params
|
||||
remote_path = int(cfg.get('remote_path', 0))
|
||||
|
||||
# Misc
|
||||
apc_version = '2.04'
|
||||
comicrn_version = '1.01'
|
||||
|
||||
cfg = dict(core.CFG[section][input_category])
|
||||
|
||||
host = cfg['host']
|
||||
port = cfg['port']
|
||||
apikey = cfg['apikey']
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
web_root = cfg.get('web_root', '')
|
||||
remote_path = int(cfg.get('remote_path'), 0)
|
||||
scheme = 'https' if ssl else 'http'
|
||||
|
||||
# Begin processing
|
||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - {section} did not respond.'
|
||||
)
|
||||
|
||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
@ -63,15 +99,15 @@ def process(
|
||||
r = requests.post(url, params=params, stream=True, verify=False, timeout=(30, 300))
|
||||
except requests.ConnectionError:
|
||||
logger.error('Unable to open URL', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to connect to '
|
||||
f'{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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Server returned status '
|
||||
f'{r.status_code}'
|
||||
)
|
||||
|
||||
result = r.text
|
||||
@ -85,13 +121,12 @@ def process(
|
||||
|
||||
if success:
|
||||
logger.postprocess('SUCCESS: This issue has been processed successfully', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
else:
|
||||
logger.warning('The issue does not appear to have successfully processed. Please check your Logs', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Returned log from '
|
||||
f'{section} was not as expected.'
|
||||
)
|
||||
|
@ -1,42 +1,76 @@
|
||||
import copy
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
import requests
|
||||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import ProcessResult
|
||||
from core.utils import convert_to_ascii, server_responding
|
||||
from core import logger, transcoder
|
||||
from core.auto_process.common import (
|
||||
ProcessResult,
|
||||
command_complete,
|
||||
completed_download_handling,
|
||||
)
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs, rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils import (
|
||||
convert_to_ascii,
|
||||
find_download,
|
||||
find_imdbid,
|
||||
flatten,
|
||||
list_media_files,
|
||||
remote_dir,
|
||||
remove_dir,
|
||||
server_responding,
|
||||
)
|
||||
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
||||
def process(
|
||||
section,
|
||||
dir_name,
|
||||
input_name=None,
|
||||
status=0,
|
||||
client_agent='manual',
|
||||
input_category=None,
|
||||
*,
|
||||
section: str,
|
||||
dir_name: str,
|
||||
input_name: str = '',
|
||||
status: int = 0,
|
||||
failed: bool = False,
|
||||
client_agent: str = 'manual',
|
||||
download_id: str = '',
|
||||
input_category: str = '',
|
||||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
status = int(status)
|
||||
|
||||
cfg = dict(core.CFG[section][input_category])
|
||||
# Get configuration
|
||||
cfg = core.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
scheme = 'https' if ssl else 'http'
|
||||
host = cfg['host']
|
||||
port = cfg['port']
|
||||
apikey = cfg['apikey']
|
||||
library = cfg.get('library')
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
web_root = cfg.get('web_root', '')
|
||||
scheme = 'https' if ssl else 'http'
|
||||
|
||||
# Authentication
|
||||
apikey = cfg.get('apikey', '')
|
||||
|
||||
# Params
|
||||
|
||||
# Misc
|
||||
library = cfg.get('library')
|
||||
|
||||
# Begin processing
|
||||
url = core.utils.common.create_url(scheme, host, port, web_root)
|
||||
if not server_responding(url):
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - {section} did not respond.'
|
||||
)
|
||||
|
||||
input_name, dir_name = convert_to_ascii(input_name, dir_name)
|
||||
@ -60,9 +94,9 @@ def process(
|
||||
r = requests.get(url, params=params, verify=False, timeout=(30, 300))
|
||||
except requests.ConnectionError:
|
||||
logger.error('Unable to open URL')
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Unable to connect to {1}'.format(section, section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to connect to '
|
||||
f'{section}'
|
||||
)
|
||||
|
||||
result = r.json()
|
||||
@ -73,32 +107,30 @@ def process(
|
||||
shutil.move(dir_name, os.path.join(library, input_name))
|
||||
except Exception:
|
||||
logger.error('Unable to move {0} to {1}'.format(dir_name, os.path.join(library, input_name)), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Unable to move files'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to move files'
|
||||
)
|
||||
else:
|
||||
logger.error('No library specified to move files to. Please edit your configuration.', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - No library defined in {0}'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - No library defined in '
|
||||
f'{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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Server returned status '
|
||||
f'{r.status_code}'
|
||||
)
|
||||
elif result['success']:
|
||||
logger.postprocess('SUCCESS: Status for {0} has been set to {1} in Gamez'.format(gamez_id, download_status), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
else:
|
||||
logger.error('FAILED: Status for {0} has NOT been updated in Gamez'.format(gamez_id), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Returned log from {section} '
|
||||
f'was not as expected.'
|
||||
)
|
||||
|
@ -1,8 +1,13 @@
|
||||
import copy
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
import requests
|
||||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger, transcoder
|
||||
@ -11,6 +16,7 @@ from core.auto_process.common import (
|
||||
command_complete,
|
||||
completed_download_handling,
|
||||
)
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs, rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
@ -18,53 +24,63 @@ from core.utils import (
|
||||
convert_to_ascii,
|
||||
find_download,
|
||||
find_imdbid,
|
||||
flatten,
|
||||
list_media_files,
|
||||
remote_dir,
|
||||
remove_dir,
|
||||
server_responding,
|
||||
)
|
||||
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
||||
def process(
|
||||
section,
|
||||
dir_name,
|
||||
input_name=None,
|
||||
status=0,
|
||||
client_agent='manual',
|
||||
download_id='',
|
||||
input_category=None,
|
||||
failure_link=None,
|
||||
*,
|
||||
section: str,
|
||||
dir_name: str,
|
||||
input_name: str = '',
|
||||
status: int = 0,
|
||||
failed: bool = False,
|
||||
client_agent: str = 'manual',
|
||||
download_id: str = '',
|
||||
input_category: str = '',
|
||||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
cfg = dict(core.CFG[section][input_category])
|
||||
# Get configuration
|
||||
cfg = core.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
scheme = 'https' if ssl else 'http'
|
||||
host = cfg['host']
|
||||
port = cfg['port']
|
||||
apikey = cfg['apikey']
|
||||
if section == 'CouchPotato':
|
||||
method = cfg['method']
|
||||
else:
|
||||
method = None
|
||||
# added importMode for Radarr config
|
||||
if section == 'Radarr':
|
||||
import_mode = cfg.get('importMode', 'Move')
|
||||
else:
|
||||
import_mode = None
|
||||
delete_failed = int(cfg['delete_failed'])
|
||||
wait_for = int(cfg['wait_for'])
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
web_root = cfg.get('web_root', '')
|
||||
remote_path = int(cfg.get('remote_path', 0))
|
||||
scheme = 'https' if ssl else 'http'
|
||||
|
||||
# Authentication
|
||||
apikey = cfg.get('apikey', '')
|
||||
omdbapikey = cfg.get('omdbapikey', '')
|
||||
no_status_check = int(cfg.get('no_status_check', 0))
|
||||
status = int(status)
|
||||
|
||||
# Params
|
||||
delete_failed = int(cfg.get('delete_failed', 0))
|
||||
remote_path = int(cfg.get('remote_path', 0))
|
||||
wait_for = int(cfg.get('wait_for', 2))
|
||||
|
||||
# Misc
|
||||
if status > 0 and core.NOEXTRACTFAILED:
|
||||
extract = 0
|
||||
else:
|
||||
extract = int(cfg.get('extract', 0))
|
||||
chmod_directory = int(str(cfg.get('chmodDirectory', '0')), 8)
|
||||
import_mode = cfg.get('importMode', 'Move')
|
||||
if section != 'Radarr':
|
||||
import_mode = None
|
||||
no_status_check = int(cfg.get('no_status_check', 0))
|
||||
method = cfg.get('method', None)
|
||||
if section != 'CouchPotato':
|
||||
method = None
|
||||
|
||||
# Begin processing
|
||||
imdbid = find_imdbid(dir_name, input_name, omdbapikey)
|
||||
if section == 'CouchPotato':
|
||||
route = f'{web_root}/api/{apikey}/'
|
||||
@ -88,9 +104,8 @@ def process(
|
||||
release = None
|
||||
else:
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - {section} did not respond.'
|
||||
)
|
||||
|
||||
# pull info from release found if available
|
||||
@ -172,7 +187,6 @@ def process(
|
||||
logger.debug('Transcoding succeeded for files in {0}'.format(dir_name), section)
|
||||
dir_name = new_dir_name
|
||||
|
||||
chmod_directory = int(str(cfg.get('chmodDirectory', '0')), 8)
|
||||
logger.debug('Config setting \'chmodDirectory\' currently set to {0}'.format(oct(chmod_directory)), section)
|
||||
if chmod_directory:
|
||||
logger.info('Attempting to set the octal permission of \'{0}\' on directory \'{1}\''.format(oct(chmod_directory), dir_name), section)
|
||||
@ -368,29 +382,28 @@ def process(
|
||||
r = requests.get(url, params={'media_id': media_id}, verify=False, timeout=(30, 600))
|
||||
except requests.ConnectionError:
|
||||
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),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to connect to '
|
||||
f'{section}'
|
||||
)
|
||||
|
||||
result = r.json()
|
||||
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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Server returned status '
|
||||
f'{r.status_code}'
|
||||
)
|
||||
elif result['success']:
|
||||
logger.postprocess('SUCCESS: Snatched the next highest release ...', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully snatched next highest release'.format(section),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully snatched next highest release'
|
||||
)
|
||||
else:
|
||||
logger.postprocess('SUCCESS: Unable to find a new release to snatch now. CP will keep searching!', section)
|
||||
return ProcessResult(
|
||||
status_code=0,
|
||||
message='{0}: No new release found now. {0} will keep searching'.format(section),
|
||||
return ProcessResult.success(
|
||||
f'{section}: No new release found now. '
|
||||
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.
|
||||
@ -398,9 +411,9 @@ def process(
|
||||
download_id = None # we don't want to filter new releases based on this.
|
||||
|
||||
if no_status_check:
|
||||
return ProcessResult(
|
||||
status_code=0,
|
||||
message='{0}: Successfully processed but no change in status confirmed'.format(section),
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully processed but no change in status '
|
||||
f'confirmed'
|
||||
)
|
||||
|
||||
# we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing.
|
||||
@ -420,17 +433,15 @@ def process(
|
||||
title = release[release_id]['title']
|
||||
logger.postprocess('SUCCESS: Movie {0} has now been added to CouchPotato with release status of [{1}]'.format(
|
||||
title, str(release_status_new).upper()), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
|
||||
if release_status_new != release_status_old:
|
||||
logger.postprocess('SUCCESS: Release {0} has now been marked with a status of [{1}]'.format(
|
||||
release_id, str(release_status_new).upper()), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
@ -441,9 +452,8 @@ def process(
|
||||
logger.debug('The Scan command return status: {0}'.format(command_status), section)
|
||||
if command_status in ['completed']:
|
||||
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
elif command_status in ['failed']:
|
||||
logger.debug('The Scan command has failed. Renaming was not successful.', section)
|
||||
@ -455,17 +465,15 @@ def process(
|
||||
if not os.path.isdir(dir_name):
|
||||
logger.postprocess('SUCCESS: Input Directory [{0}] has been processed and removed'.format(
|
||||
dir_name), section)
|
||||
return ProcessResult(
|
||||
status_code=0,
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
|
||||
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(
|
||||
dir_name), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
|
||||
# pause and let CouchPotatoServer/Radarr catch its breath
|
||||
@ -474,18 +482,17 @@ def process(
|
||||
# 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):
|
||||
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(
|
||||
message='{0}: Complete DownLoad Handling is enabled. Passing back to {0}'.format(section),
|
||||
status_code=status,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Complete DownLoad Handling is enabled. Passing back '
|
||||
f'to {section}'
|
||||
)
|
||||
logger.warning(
|
||||
'{0} does not appear to have changed status after {1} minutes, Please check your logs.'.format(input_name, wait_for),
|
||||
section,
|
||||
)
|
||||
|
||||
return ProcessResult(
|
||||
status_code=1,
|
||||
message='{0}: Failed to post-process - No change in status'.format(section),
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - No change in status'
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,52 +1,83 @@
|
||||
import copy
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
import requests
|
||||
from oauthlib.oauth2 import LegacyApplicationClient
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
from core.auto_process.common import command_complete, ProcessResult
|
||||
from core import logger, transcoder
|
||||
from core.auto_process.common import (
|
||||
ProcessResult,
|
||||
command_complete,
|
||||
completed_download_handling,
|
||||
)
|
||||
from core.auto_process.managers.sickbeard import InitSickBeard
|
||||
from core.plugins.downloaders.nzb.utils import report_nzb
|
||||
from core.plugins.subtitles import import_subs, rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils import convert_to_ascii, list_media_files, remote_dir, remove_dir, server_responding
|
||||
from core.utils import (
|
||||
convert_to_ascii,
|
||||
find_download,
|
||||
find_imdbid,
|
||||
flatten,
|
||||
list_media_files,
|
||||
remote_dir,
|
||||
remove_dir,
|
||||
server_responding,
|
||||
)
|
||||
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
||||
def process(
|
||||
section,
|
||||
dir_name,
|
||||
input_name=None,
|
||||
status=0,
|
||||
client_agent='manual',
|
||||
input_category=None,
|
||||
*,
|
||||
section: str,
|
||||
dir_name: str,
|
||||
input_name: str = '',
|
||||
status: int = 0,
|
||||
failed: bool = False,
|
||||
client_agent: str = 'manual',
|
||||
download_id: str = '',
|
||||
input_category: str = '',
|
||||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
status = int(status)
|
||||
|
||||
cfg = dict(core.CFG[section][input_category])
|
||||
# Get configuration
|
||||
cfg = core.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
scheme = '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', '')
|
||||
|
||||
# Authentication
|
||||
apikey = cfg.get('apikey', '')
|
||||
|
||||
# Params
|
||||
delete_failed = int(cfg.get('delete_failed', 0))
|
||||
remote_path = int(cfg.get('remote_path', 0))
|
||||
scheme = 'https' if ssl else 'http'
|
||||
status = int(status)
|
||||
wait_for = int(cfg.get('wait_for', 2))
|
||||
|
||||
# Misc
|
||||
if status > 0 and core.NOEXTRACTFAILED:
|
||||
extract = 0
|
||||
else:
|
||||
extract = int(cfg.get('extract', 0))
|
||||
|
||||
# Begin processing
|
||||
route = f'{web_root}/api/v1' if section == 'Lidarr' else f'{web_root}/api'
|
||||
url = core.utils.common.create_url(scheme, host, port, route)
|
||||
if not server_responding(url):
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - {section} did not respond.'
|
||||
)
|
||||
|
||||
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 +126,8 @@ def process(
|
||||
|
||||
# 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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - No change in wanted status'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - No change in wanted status'
|
||||
)
|
||||
|
||||
elif status == 0 and section == 'Lidarr':
|
||||
@ -116,9 +146,9 @@ def process(
|
||||
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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to connect to '
|
||||
f'{section}'
|
||||
)
|
||||
|
||||
try:
|
||||
@ -127,9 +157,8 @@ def process(
|
||||
logger.debug('Scan started with id: {0}'.format(scan_id), section)
|
||||
except Exception as e:
|
||||
logger.warning('No scan id was returned due to: {0}'.format(e), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Unable to start scan'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to start scan'
|
||||
)
|
||||
|
||||
n = 0
|
||||
@ -145,44 +174,43 @@ def process(
|
||||
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)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
elif command_status and command_status in ['completed']:
|
||||
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
elif command_status and command_status in ['failed']:
|
||||
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),
|
||||
# status_code=1,
|
||||
# return ProcessResult.failure(
|
||||
# f'{section}: Failed to post-process {input_name}'
|
||||
# )
|
||||
else:
|
||||
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=f'{section}: Passing back to {section} to attempt '
|
||||
f'Complete Download Handling',
|
||||
status_code=status,
|
||||
)
|
||||
|
||||
else:
|
||||
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),
|
||||
status_code=1, # Return as failed to flag this in the downloader.
|
||||
# Return as failed to flag this in the downloader.
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Download Failed. Sending back to {section}'
|
||||
)
|
||||
else:
|
||||
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)
|
||||
remove_dir(dir_name)
|
||||
return ProcessResult(
|
||||
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.
|
||||
# Return as failed to flag this in the downloader.
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process. {section} does not '
|
||||
f'support failed downloads'
|
||||
)
|
||||
|
||||
|
||||
@ -224,26 +252,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))
|
||||
except requests.ConnectionError:
|
||||
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),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to connect to '
|
||||
f'{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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Server returned status {r.status_code}'
|
||||
)
|
||||
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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Returned log from {section} '
|
||||
f'was not as expected.'
|
||||
)
|
||||
|
||||
# we will now wait for this album to be processed before returning to TorrentToMedia and unpausing.
|
||||
@ -252,15 +279,13 @@ def force_process(params, url, apikey, input_name, dir_name, section, wait_for):
|
||||
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)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_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)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
time.sleep(10 * wait_for)
|
||||
# The status hasn't changed.
|
||||
|
@ -2,6 +2,7 @@ import copy
|
||||
import errno
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
|
||||
import requests
|
||||
@ -21,6 +22,8 @@ from core.plugins.subtitles import import_subs, rename_subs
|
||||
from core.scene_exceptions import process_all_exceptions
|
||||
from core.utils import (
|
||||
convert_to_ascii,
|
||||
find_download,
|
||||
find_imdbid,
|
||||
flatten,
|
||||
list_media_files,
|
||||
remote_dir,
|
||||
@ -33,29 +36,56 @@ requests.packages.urllib3.disable_warnings()
|
||||
|
||||
|
||||
def process(
|
||||
section,
|
||||
dir_name,
|
||||
input_name=None,
|
||||
failed=False,
|
||||
client_agent='manual',
|
||||
download_id=None,
|
||||
input_category=None,
|
||||
failure_link=None,
|
||||
*,
|
||||
section: str,
|
||||
dir_name: str,
|
||||
input_name: str = '',
|
||||
status: int = 0,
|
||||
failed: bool = False,
|
||||
client_agent: str = 'manual',
|
||||
download_id: str = '',
|
||||
input_category: str = '',
|
||||
failure_link: str = '',
|
||||
) -> ProcessResult:
|
||||
cfg = dict(core.CFG[section][input_category])
|
||||
# Get configuration
|
||||
cfg = core.CFG[section][input_category]
|
||||
|
||||
# Base URL
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
scheme = 'https' if ssl else 'http'
|
||||
host = cfg['host']
|
||||
port = cfg['port']
|
||||
ssl = int(cfg.get('ssl', 0))
|
||||
web_root = cfg.get('web_root', '')
|
||||
scheme = 'https' if ssl else 'http'
|
||||
|
||||
# Authentication
|
||||
apikey = cfg.get('apikey', '')
|
||||
username = cfg.get('username', '')
|
||||
password = cfg.get('password', '')
|
||||
apikey = cfg.get('apikey', '')
|
||||
api_version = int(cfg.get('api_version', 2))
|
||||
sso_username = cfg.get('sso_username', '')
|
||||
sso_password = cfg.get('sso_password', '')
|
||||
|
||||
# Params
|
||||
delete_failed = int(cfg.get('delete_failed', 0))
|
||||
remote_path = int(cfg.get('remote_path', 0))
|
||||
wait_for = int(cfg.get('wait_for', 2))
|
||||
|
||||
# Misc
|
||||
if status > 0 and core.NOEXTRACTFAILED:
|
||||
extract = 0
|
||||
else:
|
||||
extract = int(cfg.get('extract', 0))
|
||||
chmod_directory = int(str(cfg.get('chmodDirectory', '0')), 8)
|
||||
import_mode = cfg.get('importMode', 'Move')
|
||||
nzb_extraction_by = cfg.get('nzbExtractionBy', 'Downloader')
|
||||
process_method = cfg.get('process_method')
|
||||
force = int(cfg.get('force', 0))
|
||||
delete_on = int(cfg.get('delete_on', 0))
|
||||
ignore_subs = int(cfg.get('ignore_subs', 0))
|
||||
status = int(failed)
|
||||
|
||||
# Begin processing
|
||||
|
||||
# Refactor into an OO structure.
|
||||
# For now let's do botch the OO and the serialized code, until everything has been migrated.
|
||||
init_sickbeard = InitSickBeard(cfg, section, input_category)
|
||||
@ -71,29 +101,12 @@ def process(
|
||||
fork, fork_params = 'None', {}
|
||||
else:
|
||||
logger.error('Server did not respond. Exiting', section)
|
||||
return ProcessResult(
|
||||
status_code=1,
|
||||
message='{0}: Failed to post-process - {0} did not respond.'.format(section),
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - {section} did not respond.'
|
||||
)
|
||||
|
||||
delete_failed = int(cfg.get('delete_failed', 0))
|
||||
nzb_extraction_by = cfg.get('nzbExtractionBy', 'Downloader')
|
||||
process_method = cfg.get('process_method')
|
||||
if client_agent == core.TORRENT_CLIENT_AGENT and core.USE_LINK == 'move-sym':
|
||||
process_method = 'symlink'
|
||||
remote_path = int(cfg.get('remote_path', 0))
|
||||
wait_for = int(cfg.get('wait_for', 2))
|
||||
force = int(cfg.get('force', 0))
|
||||
delete_on = int(cfg.get('delete_on', 0))
|
||||
ignore_subs = int(cfg.get('ignore_subs', 0))
|
||||
status = int(failed)
|
||||
if status > 0 and core.NOEXTRACTFAILED:
|
||||
extract = 0
|
||||
else:
|
||||
extract = int(cfg.get('extract', 0))
|
||||
# get importmode, default to 'Move' for consistency with legacy
|
||||
import_mode = cfg.get('importMode', 'Move')
|
||||
|
||||
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.
|
||||
dir_name = os.path.split(os.path.normpath(dir_name))[0]
|
||||
|
||||
@ -161,10 +174,8 @@ def process(
|
||||
failure_link += '&corrupt=true'
|
||||
elif client_agent == 'manual':
|
||||
logger.warning('No media files found in directory {0} to manually process.'.format(dir_name), section)
|
||||
return ProcessResult(
|
||||
message='',
|
||||
status_code=0, # Success (as far as this script is concerned)
|
||||
)
|
||||
# Success (as far as this script is concerned)
|
||||
return ProcessResult.success()
|
||||
elif nzb_extraction_by == 'Destination':
|
||||
logger.info('Check for media files ignored because nzbExtractionBy is set to Destination.')
|
||||
if int(failed) == 0:
|
||||
@ -188,16 +199,14 @@ def process(
|
||||
logger.debug('SUCCESS: Transcoding succeeded for files in {0}'.format(dir_name), section)
|
||||
dir_name = new_dir_name
|
||||
|
||||
chmod_directory = int(str(cfg.get('chmodDirectory', '0')), 8)
|
||||
logger.debug('Config setting \'chmodDirectory\' currently set to {0}'.format(oct(chmod_directory)), section)
|
||||
if chmod_directory:
|
||||
logger.info('Attempting to set the octal permission of \'{0}\' on directory \'{1}\''.format(oct(chmod_directory), dir_name), section)
|
||||
core.rchmod(dir_name, chmod_directory)
|
||||
else:
|
||||
logger.error('FAILED: Transcoding failed for files in {0}'.format(dir_name), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Transcoding failed'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Transcoding failed'
|
||||
)
|
||||
|
||||
# Part of the refactor
|
||||
@ -272,9 +281,8 @@ def process(
|
||||
if status == 0:
|
||||
if section == 'NzbDrone' and not apikey:
|
||||
logger.info('No Sonarr apikey entered. Processing completed.')
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
logger.postprocess('SUCCESS: The download succeeded, sending a post-process request', section)
|
||||
else:
|
||||
@ -285,18 +293,19 @@ def process(
|
||||
logger.postprocess('FAILED: The download failed. Sending \'failed\' process request to {0} branch'.format(fork), section)
|
||||
elif section == 'NzbDrone':
|
||||
logger.postprocess('FAILED: The download failed. Sending failed download to {0} for CDH processing'.format(fork), section)
|
||||
return ProcessResult(
|
||||
message='{0}: Download Failed. Sending back to {0}'.format(section),
|
||||
status_code=1, # Return as failed to flag this in the downloader.
|
||||
# Return as failed to flag this in the downloader.
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Download Failed. Sending back to {section}'
|
||||
)
|
||||
else:
|
||||
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:
|
||||
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),
|
||||
status_code=1, # Return as failed to flag this in the downloader.
|
||||
# Return as failed to flag this in the downloader.
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process. {section} does not '
|
||||
f'support failed downloads'
|
||||
)
|
||||
|
||||
route = ''
|
||||
@ -376,16 +385,16 @@ def process(
|
||||
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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Unable to connect to {0}'.format(section),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Unable to connect to '
|
||||
f'{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)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Server returned status '
|
||||
f'{r.status_code}'
|
||||
)
|
||||
|
||||
success = False
|
||||
@ -431,9 +440,8 @@ def process(
|
||||
remove_dir(dir_name)
|
||||
|
||||
if success:
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
elif section == 'NzbDrone' and started:
|
||||
n = 0
|
||||
@ -449,21 +457,18 @@ def process(
|
||||
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)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
elif command_status and command_status in ['completed']:
|
||||
logger.debug('The Scan command has completed successfully. Renaming was successful.', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Successfully post-processed {1}'.format(section, input_name),
|
||||
status_code=0,
|
||||
return ProcessResult.success(
|
||||
f'{section}: Successfully post-processed {input_name}'
|
||||
)
|
||||
elif command_status and command_status in ['failed']:
|
||||
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),
|
||||
# status_code=1,
|
||||
# return ProcessResult.failure(
|
||||
# f'{section}: Failed to post-process {input_name}'
|
||||
# )
|
||||
|
||||
url2 = core.utils.common.create_url(scheme, host, port, route)
|
||||
@ -471,17 +476,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),
|
||||
section)
|
||||
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,
|
||||
)
|
||||
else:
|
||||
logger.warning('The Scan command did not return a valid status. Renaming was not successful.', section)
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process {1}'.format(section, input_name),
|
||||
status_code=1,
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process {input_name}'
|
||||
)
|
||||
else:
|
||||
return ProcessResult(
|
||||
message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section),
|
||||
status_code=1, # We did not receive Success confirmation.
|
||||
# We did not receive Success confirmation.
|
||||
return ProcessResult.failure(
|
||||
f'{section}: Failed to post-process - Returned log from {section} '
|
||||
f'was not as expected.'
|
||||
)
|
||||
|
@ -116,24 +116,33 @@ def process(input_directory, input_name=None, status=0, client_agent='manual', d
|
||||
|
||||
logger.info('Calling {0}:{1} to post-process:{2}'.format(section_name, input_category, input_name))
|
||||
|
||||
if section_name in ['CouchPotato', 'Radarr', 'Watcher3']:
|
||||
result = movies.process(section_name, input_directory, input_name, status, client_agent, download_id, input_category, failure_link)
|
||||
elif section_name in ['SickBeard', 'SiCKRAGE', 'NzbDrone', 'Sonarr']:
|
||||
result = tv.process(section_name, input_directory, input_name, status, client_agent, download_id, input_category, failure_link)
|
||||
elif section_name in ['HeadPhones', 'Lidarr']:
|
||||
result = music.process(section_name, input_directory, input_name, status, client_agent, input_category)
|
||||
elif section_name == 'Mylar':
|
||||
result = comics.process(section_name, input_directory, input_name, status, client_agent, input_category)
|
||||
elif section_name == 'Gamez':
|
||||
result = games.process(section_name, input_directory, input_name, status, client_agent, input_category)
|
||||
elif section_name == 'LazyLibrarian':
|
||||
result = books.process(section_name, input_directory, input_name, status, client_agent, input_category)
|
||||
elif section_name == 'UserScript':
|
||||
if section_name == 'UserScript':
|
||||
result = external_script(input_directory, input_name, input_category, section[usercat])
|
||||
else:
|
||||
result = ProcessResult(
|
||||
message='',
|
||||
status_code=-1,
|
||||
process_map = {
|
||||
'CouchPotato': movies.process,
|
||||
'Radarr': movies.process,
|
||||
'Watcher3': movies.process,
|
||||
'SickBeard': tv.process,
|
||||
'SiCKRAGE': tv.process,
|
||||
'NzbDrone': tv.process,
|
||||
'Sonarr': tv.process,
|
||||
'LazyLibrarian': books.process,
|
||||
'HeadPhones': music.process,
|
||||
'Lidarr': music.process,
|
||||
'Mylar': comics.process,
|
||||
'Gamez': games.process,
|
||||
}
|
||||
processor = process_map[section_name]
|
||||
result = processor(
|
||||
section=section_name,
|
||||
dir_name=input_directory,
|
||||
input_name=input_name,
|
||||
status=status,
|
||||
client_agent=client_agent,
|
||||
download_id=download_id,
|
||||
input_category=input_category,
|
||||
failure_link=failure_link,
|
||||
)
|
||||
|
||||
plex_update(input_category)
|
||||
|
Loading…
x
Reference in New Issue
Block a user