From d2dfd135c6a8c43ec7564c8fb41d9211c7d5832e Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Fri, 9 Dec 2022 16:20:18 -0500 Subject: [PATCH] Add peppiness --- core/__init__.py | 2 +- core/auto_process/books.py | 10 +++--- core/auto_process/comics.py | 10 +++--- core/auto_process/games.py | 16 ++++----- core/auto_process/managers/pymedusa.py | 16 ++++----- core/auto_process/managers/sickbeard.py | 42 +++++++++++----------- core/auto_process/movies.py | 42 +++++++++++----------- core/auto_process/music.py | 26 +++++++------- core/auto_process/tv.py | 47 +++++++++++++------------ core/databases.py | 4 +-- core/extractor/__init__.py | 38 ++++++++------------ core/main_db.py | 14 ++++---- core/plugins/subtitles.py | 26 +++++++------- core/processor/manual.py | 24 ++++++++----- core/processor/nzb.py | 9 +++-- core/scene_exceptions.py | 8 ++--- core/utils/files.py | 2 +- core/utils/identification.py | 4 +-- core/utils/paths.py | 2 +- 19 files changed, 172 insertions(+), 170 deletions(-) diff --git a/core/__init__.py b/core/__init__.py index e1a89154..aa78aa07 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -392,7 +392,7 @@ def configure_updates(): # Set Current Version logger.info( - 'nzbToMedia Version:{version} Branch:{branch} ({system} {release})'.format(version=NZBTOMEDIA_VERSION, branch=GIT_BRANCH, system=platform.system(), release=platform.release()), + f'nzbToMedia Version:{NZBTOMEDIA_VERSION} Branch:{GIT_BRANCH} ({platform.system()} {platform.release()})', ) diff --git a/core/auto_process/books.py b/core/auto_process/books.py index 20965515..4ae1c4a4 100644 --- a/core/auto_process/books.py +++ b/core/auto_process/books.py @@ -70,7 +70,7 @@ def process( if not server_responding(url): logger.error('Server did not respond. Exiting', section) return ProcessResult.failure( - f'{section}: Failed to post-process - {section} did not respond.' + f'{section}: Failed to post-process - {section} did not respond.', ) input_name, dir_name = convert_to_ascii(input_name, dir_name) @@ -89,7 +89,7 @@ def process( logger.error('Unable to open URL') return ProcessResult.failure( f'{section}: Failed to post-process - Unable to connect to ' - f'{section}' + f'{section}', ) logger.postprocess(f'{r.text}', section) @@ -98,16 +98,16 @@ def process( logger.error(f'Server returned status {r.status_code}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Server returned status ' - f'{r.status_code}' + f'{r.status_code}', ) elif r.text == 'OK': logger.postprocess(f'SUCCESS: ForceProcess for {dir_name} has been started in LazyLibrarian', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) else: logger.error(f'FAILED: ForceProcess of {dir_name} has Failed in LazyLibrarian', section) return ProcessResult.failure( f'{section}: Failed to post-process - Returned log from {section} ' - f'was not as expected.' + f'was not as expected.', ) diff --git a/core/auto_process/comics.py b/core/auto_process/comics.py index 5475bbd0..d13622ff 100644 --- a/core/auto_process/comics.py +++ b/core/auto_process/comics.py @@ -72,7 +72,7 @@ def process( if not server_responding(url): logger.error('Server did not respond. Exiting', section) return ProcessResult.failure( - f'{section}: Failed to post-process - {section} did not respond.' + f'{section}: Failed to post-process - {section} did not respond.', ) input_name, dir_name = convert_to_ascii(input_name, dir_name) @@ -101,13 +101,13 @@ def process( logger.error('Unable to open URL', section) return ProcessResult.failure( f'{section}: Failed to post-process - Unable to connect to ' - f'{section}' + f'{section}', ) if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error(f'Server returned status {r.status_code}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Server returned status ' - f'{r.status_code}' + f'{r.status_code}', ) result = r.text @@ -122,11 +122,11 @@ def process( if success: logger.postprocess('SUCCESS: This issue has been processed successfully', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + 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.failure( f'{section}: Failed to post-process - Returned log from ' - f'{section} was not as expected.' + f'{section} was not as expected.', ) diff --git a/core/auto_process/games.py b/core/auto_process/games.py index 0bf0347d..de685c49 100644 --- a/core/auto_process/games.py +++ b/core/auto_process/games.py @@ -69,9 +69,7 @@ def process( 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.failure( - f'{section}: Failed to post-process - {section} did not respond.' - ) + return ProcessResult.failure(f'{section}: Failed to post-process - {section} did not respond.') input_name, dir_name = convert_to_ascii(input_name, dir_name) @@ -96,7 +94,7 @@ def process( logger.error('Unable to open URL') return ProcessResult.failure( f'{section}: Failed to post-process - Unable to connect to ' - f'{section}' + f'{section}', ) result = r.json() @@ -108,29 +106,29 @@ def process( except Exception: logger.error(f'Unable to move {dir_name} to {os.path.join(library, input_name)}', section) return ProcessResult.failure( - f'{section}: Failed to post-process - Unable to move files' + 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.failure( f'{section}: Failed to post-process - No library defined in ' - f'{section}' + f'{section}', ) if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error(f'Server returned status {r.status_code}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Server returned status ' - f'{r.status_code}' + f'{r.status_code}', ) elif result['success']: logger.postprocess(f'SUCCESS: Status for {gamez_id} has been set to {download_status} in Gamez', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) else: logger.error(f'FAILED: Status for {gamez_id} has NOT been updated in Gamez', section) return ProcessResult.failure( f'{section}: Failed to post-process - Returned log from {section} ' - f'was not as expected.' + f'was not as expected.', ) diff --git a/core/auto_process/managers/pymedusa.py b/core/auto_process/managers/pymedusa.py index 2e5f76f4..dabe7e87 100644 --- a/core/auto_process/managers/pymedusa.py +++ b/core/auto_process/managers/pymedusa.py @@ -57,7 +57,7 @@ class PyMedusaApiV1(SickBeard): ) return ProcessResult.failure( f'{self.sb_init.section}: Failed to post-process - Unable to ' - f'connect to {self.sb_init.section}' + f'connect to {self.sb_init.section}', ) successful_status_codes = [ @@ -72,18 +72,18 @@ class PyMedusaApiV1(SickBeard): ) result = ProcessResult.failure( f'{self.sb_init.section}: Failed to post-process - Server ' - f'returned status {response.status_code}' + f'returned status {response.status_code}', ) elif response.json()['result'] == 'success': result = ProcessResult.success( f'{self.sb_init.section}: Successfully post-processed ' - f'{self.input_name}' + f'{self.input_name}', ) else: # We did not receive Success confirmation. result = ProcessResult.failure( f'{self.sb_init.section}: Failed to post-process - Returned ' - f'log from {self.sb_init.section} was not as expected.' + f'log from {self.sb_init.section} was not as expected.', ) return result @@ -99,7 +99,7 @@ class PyMedusaApiV2(SickBeard): if not sb_init.apikey: logger.error( 'For the section SickBeard `fork = medusa-apiv2` you also ' - 'need to configure an `apikey`' + 'need to configure an `apikey`', ) raise ValueError('Missing apikey for fork: medusa-apiv2') @@ -160,7 +160,7 @@ class PyMedusaApiV2(SickBeard): ) return ProcessResult.failure( f'{self.sb_init.section}: Unable to send postprocess request ' - f'to PyMedusa' + f'to PyMedusa', ) # Get UUID @@ -203,12 +203,12 @@ class PyMedusaApiV2(SickBeard): if response.get('success'): result = ProcessResult.success( f'{self.sb_init.section}: Successfully post-processed ' - f'{self.input_name}' + f'{self.input_name}', ) else: # We did not receive Success confirmation. result = ProcessResult.failure( f'{self.sb_init.section}: Failed to post-process - Returned ' - f'log from {self.sb_init.section} was not as expected.' + f'log from {self.sb_init.section} was not as expected.', ) return result diff --git a/core/auto_process/managers/sickbeard.py b/core/auto_process/managers/sickbeard.py index 3c98d45b..d86bb6d8 100644 --- a/core/auto_process/managers/sickbeard.py +++ b/core/auto_process/managers/sickbeard.py @@ -65,7 +65,7 @@ class InitSickBeard: # keep using determined fork for multiple (manual) post-processing logger.info( f'{self.section}:{self.input_category} fork already set to ' - f'{core.FORK_SET[0]}' + f'{core.FORK_SET[0]}', ) return core.FORK_SET[0], core.FORK_SET[1] @@ -108,13 +108,13 @@ class InitSickBeard: except requests.ConnectionError: logger.warning( f'Could not connect to {self.section}:' - f'{self.input_category} to verify fork!' + f'{self.input_category} to verify fork!', ) if not r.ok: logger.warning( f'Connection to {self.section}:{self.input_category} ' - f'failed! Check your configuration' + f'failed! Check your configuration', ) self.fork = ['default', {}] @@ -148,8 +148,8 @@ class InitSickBeard: ): oauth = OAuth2Session( client=LegacyApplicationClient( - client_id=core.SICKRAGE_OAUTH_CLIENT_ID - ) + client_id=core.SICKRAGE_OAUTH_CLIENT_ID, + ), ) oauth_token = oauth.fetch_token( client_id=core.SICKRAGE_OAUTH_CLIENT_ID, @@ -175,12 +175,12 @@ class InitSickBeard: if not r.ok: logger.warning( f'Connection to {self.section}:{self.input_category} ' - f'failed! Check your configuration' + f'failed! Check your configuration', ) except requests.ConnectionError: logger.warning( f'Could not connect to {self.section}:' - f'{self.input_category} to verify API version!' + f'{self.input_category} to verify API version!', ) params = { @@ -201,7 +201,7 @@ class InitSickBeard: self.detect_fork() logger.info( - f'{self.section}:{self.input_category} fork set to {self.fork[0]}' + f'{self.section}:{self.input_category} fork set to {self.fork[0]}', ) core.FORK_SET = self.fork self.fork, self.fork_params = self.fork[0], self.fork[1] @@ -235,7 +235,7 @@ class InitSickBeard: excess_parameters = set(params).difference(optional_parameters) excess_parameters.remove('cmd') # Don't remove cmd from api params logger.debug( - f'Removing excess parameters: ' f'{sorted(excess_parameters)}' + f'Removing excess parameters: ' f'{sorted(excess_parameters)}', ) rem_params.extend(excess_parameters) return rem_params, True @@ -298,7 +298,7 @@ class InitSickBeard: except requests.ConnectionError: logger.info( f'Could not connect to {self.section}:{self.input_category} ' - f'to perform auto-fork detection!' + f'to perform auto-fork detection!', ) r = [] @@ -323,7 +323,7 @@ class InitSickBeard: logger.info( f'Could not connect to {self.section}:' f'{self.input_category} to perform auto-fork ' - f'detection!' + f'detection!', ) rem_params, found = self._api_check(r, params, rem_params) params['cmd'] = 'postprocess' @@ -348,18 +348,18 @@ class InitSickBeard: self.fork = fork logger.info( f'{self.section}:{self.input_category} fork auto-detection ' - f'successful ...' + f'successful ...', ) elif rem_params: logger.info( f'{self.section}:{self.input_category} fork auto-detection ' - f'found custom params {params}' + f'found custom params {params}', ) self.fork = ['custom', params] else: logger.info( f'{self.section}:{self.input_category} fork auto-detection ' - f'failed' + f'failed', ) self.fork = list(core.FORKS.items())[ list(core.FORKS.keys()).index(core.FORK_DEFAULT) @@ -381,7 +381,7 @@ class InitSickBeard: else: logger.info( f'{self.section}:{self.input_category} Could not create a ' - f'fork object for {self.fork}. Probaly class not added yet.' + f'fork object for {self.fork}. Probaly class not added yet.', ) @@ -402,7 +402,7 @@ class SickBeard: self.delete_failed = int(self.sb_init.config.get('delete_failed', 0)) self.nzb_extraction_by = self.sb_init.config.get( - 'nzbExtractionBy', 'Downloader' + 'nzbExtractionBy', 'Downloader', ) self.process_method = self.sb_init.config.get('process_method') self.remote_path = int(self.sb_init.config.get('remote_path', 0)) @@ -581,11 +581,11 @@ class SickBeard: ) except requests.ConnectionError: logger.error( - f'Unable to open URL: {self.url}', self.sb_init.section + f'Unable to open URL: {self.url}', self.sb_init.section, ) result = ProcessResult.failure( f'{self.sb_init.section}: Failed to post-process - Unable to ' - f'connect to {self.sb_init.section}' + f'connect to {self.sb_init.section}', ) else: successful_statuses = [ @@ -600,7 +600,7 @@ class SickBeard: ) result = ProcessResult.failure( f'{self.sb_init.section}: Failed to post-process - Server ' - f'returned status {response.status_code}' + f'returned status {response.status_code}', ) else: result = self.process_response(response) @@ -631,12 +631,12 @@ class SickBeard: if self.success: result = ProcessResult.success( f'{self.sb_init.section}: Successfully post-processed ' - f'{self.input_name}' + f'{self.input_name}', ) else: # We did not receive Success confirmation. result = ProcessResult.failure( f'{self.sb_init.section}: Failed to post-process - Returned ' - f'log from {self.sb_init.section} was not as expected.' + f'log from {self.sb_init.section} was not as expected.', ) return result diff --git a/core/auto_process/movies.py b/core/auto_process/movies.py index a8687893..2a7b1ed9 100644 --- a/core/auto_process/movies.py +++ b/core/auto_process/movies.py @@ -104,9 +104,7 @@ def process( release = None else: logger.error('Server did not respond. Exiting', section) - return ProcessResult.failure( - f'{section}: Failed to post-process - {section} did not respond.' - ) + return ProcessResult.failure(f'{section}: Failed to post-process - {section} did not respond.') # pull info from release found if available release_id = None @@ -166,7 +164,7 @@ def process( logger.debug(f'Video marked as failed due to missing required language: {core.REQUIRE_LAN}', section) else: logger.debug('Video marked as failed due to missing playable audio or video', section) - if good_files < num_files and failure_link: # only report corrupt files + if good_files < num_files and failure_link: # only report corrupt files failure_link += '&corrupt=true' elif client_agent == 'manual': logger.warning(f'No media files found in directory {dir_name} to manually process.', section) @@ -296,8 +294,10 @@ def process( status_code=1, ) else: - logger.error(f'FAILED: {method} scan was unable to finish for folder {dir_name}. exiting!', - section) + logger.error( + f'FAILED: {method} scan was unable to finish for folder {dir_name}. exiting!', + section, + ) return ProcessResult( message=f'{section}: Failed to post-process - Server did not return success', status_code=1, @@ -334,8 +334,10 @@ def process( remove_dir(dir_name) if not release_id and not media_id: - logger.error(f'Could not find a downloaded movie in the database matching {input_name}, exiting!', - section) + logger.error( + f'Could not find a downloaded movie in the database matching {input_name}, exiting!', + section, + ) return ProcessResult( message='{0}: Failed to post-process - Failed download not found in {0}'.format(section), status_code=1, @@ -385,7 +387,7 @@ def process( logger.error(f'Unable to open URL {url}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Unable to connect to ' - f'{section}' + f'{section}', ) result = r.json() @@ -393,18 +395,18 @@ def process( logger.error(f'Server returned status {r.status_code}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Server returned status ' - f'{r.status_code}' + f'{r.status_code}', ) elif result['success']: logger.postprocess('SUCCESS: Snatched the next highest release ...', section) return ProcessResult.success( - f'{section}: Successfully snatched next highest release' + 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.success( f'{section}: No new release found now. ' - f'{section} will keep searching' + 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. @@ -414,7 +416,7 @@ def process( if no_status_check: return ProcessResult.success( f'{section}: Successfully processed but no change in status ' - f'confirmed' + f'confirmed', ) # we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing. @@ -434,13 +436,13 @@ def process( title = release[release_id]['title'] logger.postprocess(f'SUCCESS: Movie {title} has now been added to CouchPotato with release status of [{str(release_status_new).upper()}]', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) if release_status_new != release_status_old: logger.postprocess(f'SUCCESS: Release {release_id} has now been marked with a status of [{str(release_status_new).upper()}]', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) except Exception: pass @@ -452,7 +454,7 @@ def process( if command_status in ['completed']: logger.debug('The Scan command has completed successfully. Renaming was successful.', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) elif command_status in ['failed']: logger.debug('The Scan command has failed. Renaming was not successful.', section) @@ -464,13 +466,13 @@ def process( if not os.path.isdir(dir_name): logger.postprocess(f'SUCCESS: Input Directory [{dir_name}] has been processed and removed', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) elif not list_media_files(dir_name, media=True, audio=False, meta=False, archives=True): logger.postprocess(f'SUCCESS: Input Directory [{dir_name}] has no remaining media files. This has been fully processed.', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) # pause and let CouchPotatoServer/Radarr catch its breath @@ -481,7 +483,7 @@ def process( logger.debug(f'The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {section}.', section) return ProcessResult.success( f'{section}: Complete DownLoad Handling is enabled. Passing back ' - f'to {section}' + f'to {section}', ) logger.warning( f'{input_name} does not appear to have changed status after {wait_for} minutes, Please check your logs.', @@ -489,7 +491,7 @@ def process( ) return ProcessResult.failure( - f'{section}: Failed to post-process - No change in status' + f'{section}: Failed to post-process - No change in status', ) diff --git a/core/auto_process/music.py b/core/auto_process/music.py index 5280aa97..6fde4936 100644 --- a/core/auto_process/music.py +++ b/core/auto_process/music.py @@ -77,7 +77,7 @@ def process( if not server_responding(url): logger.error('Server did not respond. Exiting', section) return ProcessResult.failure( - f'{section}: Failed to post-process - {section} did not respond.' + 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. @@ -127,7 +127,7 @@ def process( # The status hasn't changed. uTorrent can resume seeding now. logger.warning(f'The music album does not appear to have changed status after {wait_for} minutes. Please check your Logs', section) return ProcessResult.failure( - f'{section}: Failed to post-process - No change in wanted status' + f'{section}: Failed to post-process - No change in wanted status', ) elif status == 0 and section == 'Lidarr': @@ -148,7 +148,7 @@ def process( logger.error(f'Unable to open URL: {url}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Unable to connect to ' - f'{section}' + f'{section}', ) try: @@ -158,7 +158,7 @@ def process( except Exception as e: logger.warning(f'No scan id was returned due to: {e}', section) return ProcessResult.failure( - f'{section}: Failed to post-process - Unable to start scan' + f'{section}: Failed to post-process - Unable to start scan', ) n = 0 @@ -175,12 +175,12 @@ def process( if not os.path.exists(dir_name): logger.debug(f'The directory {dir_name} has been removed. Renaming was successful.', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + 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.success( - f'{section}: Successfully post-processed {input_name}' + 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) @@ -200,7 +200,7 @@ def process( logger.postprocess(f'FAILED: The download failed. Sending failed download to {section} for CDH processing', section) # Return as failed to flag this in the downloader. return ProcessResult.failure( - f'{section}: Download Failed. Sending back to {section}' + f'{section}: Download Failed. Sending back to {section}', ) else: logger.warning('FAILED DOWNLOAD DETECTED', section) @@ -210,7 +210,7 @@ def process( # 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' + f'support failed downloads', ) @@ -254,7 +254,7 @@ def force_process(params, url, apikey, input_name, dir_name, section, wait_for): logger.error(f'Unable to open URL {url}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Unable to connect to ' - f'{section}' + f'{section}', ) logger.debug(f'Result: {r.text}', section) @@ -262,7 +262,7 @@ def force_process(params, url, apikey, input_name, dir_name, section, wait_for): if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error(f'Server returned status {r.status_code}', section) return ProcessResult.failure( - f'{section}: Failed to post-process - Server returned status {r.status_code}' + f'{section}: Failed to post-process - Server returned status {r.status_code}', ) elif r.text == 'OK': logger.postprocess(f'SUCCESS: Post-Processing started for {input_name} in folder {dir_name} ...', section) @@ -270,7 +270,7 @@ def force_process(params, url, apikey, input_name, dir_name, section, wait_for): logger.error(f'FAILED: Post-Processing has NOT started for {input_name} in folder {dir_name}. exiting!', section) return ProcessResult.failure( f'{section}: Failed to post-process - Returned log from {section} ' - f'was not as expected.' + f'was not as expected.', ) # we will now wait for this album to be processed before returning to TorrentToMedia and unpausing. @@ -280,12 +280,12 @@ def force_process(params, url, apikey, input_name, dir_name, section, wait_for): if current_status is not None and current_status != release_status: # Something has changed. CPS must have processed this movie. logger.postprocess(f'SUCCESS: This release is now marked as status [{current_status}]', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) if not os.path.isdir(dir_name): logger.postprocess(f'SUCCESS: The input directory {dir_name} has been removed Processing must have finished.', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) time.sleep(10 * wait_for) # The status hasn't changed. diff --git a/core/auto_process/tv.py b/core/auto_process/tv.py index 72ab107c..f9745562 100644 --- a/core/auto_process/tv.py +++ b/core/auto_process/tv.py @@ -102,7 +102,7 @@ def process( else: logger.error('Server did not respond. Exiting', section) return ProcessResult.failure( - f'{section}: Failed to post-process - {section} did not respond.' + f'{section}: Failed to post-process - {section} did not respond.', ) if client_agent == core.TORRENT_CLIENT_AGENT and core.USE_LINK == 'move-sym': @@ -170,7 +170,7 @@ def process( logger.debug(f'Video marked as failed due to missing required language: {core.REQUIRE_LAN}', section) else: logger.debug('Video marked as failed due to missing playable audio or video', section) - if good_files < num_files and failure_link: # only report corrupt files + if good_files < num_files and failure_link: # only report corrupt files failure_link += '&corrupt=true' elif client_agent == 'manual': logger.warning(f'No media files found in directory {dir_name} to manually process.', section) @@ -206,7 +206,7 @@ def process( else: logger.error(f'FAILED: Transcoding failed for files in {dir_name}', section) return ProcessResult.failure( - f'{section}: Failed to post-process - Transcoding failed' + f'{section}: Failed to post-process - Transcoding failed', ) # Part of the refactor @@ -282,7 +282,7 @@ def process( if section == 'NzbDrone' and not apikey: logger.info('No Sonarr apikey entered. Processing completed.') return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) logger.postprocess('SUCCESS: The download succeeded, sending a post-process request', section) else: @@ -295,7 +295,7 @@ def process( logger.postprocess(f'FAILED: The download failed. Sending failed download to {fork} for CDH processing', section) # Return as failed to flag this in the downloader. return ProcessResult.failure( - f'{section}: Download Failed. Sending back to {section}' + f'{section}: Download Failed. Sending back to {section}', ) else: logger.postprocess(f'FAILED: The download failed. {fork} branch does not handle failed downloads. Nothing to process', section) @@ -303,10 +303,7 @@ def process( logger.postprocess(f'Deleting failed files and folder {dir_name}', section) remove_dir(dir_name) # 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' - ) + return ProcessResult.failure(f'{section}: Failed to post-process. {section} does not support failed downloads') route = '' if section == 'SickBeard': @@ -360,10 +357,12 @@ def process( if api_version >= 2 and sso_username and sso_password: oauth = OAuth2Session(client=LegacyApplicationClient(client_id=core.SICKRAGE_OAUTH_CLIENT_ID)) - oauth_token = oauth.fetch_token(client_id=core.SICKRAGE_OAUTH_CLIENT_ID, - token_url=core.SICKRAGE_OAUTH_TOKEN_URL, - username=sso_username, - password=sso_password) + oauth_token = oauth.fetch_token( + client_id=core.SICKRAGE_OAUTH_CLIENT_ID, + token_url=core.SICKRAGE_OAUTH_TOKEN_URL, + username=sso_username, + password=sso_password, + ) s.headers.update({'Authorization': 'Bearer ' + oauth_token['access_token']}) params = { @@ -374,7 +373,7 @@ def process( 'returnData': str(bool(fork_params['return_data'])).lower(), 'delete': str(bool(fork_params['delete'])).lower(), 'forceNext': str(bool(fork_params['force_next'])).lower(), - 'nzbName': fork_params['nzbName'] + 'nzbName': fork_params['nzbName'], } else: params = fork_params @@ -387,14 +386,14 @@ def process( logger.error(f'Unable to open URL: {url}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Unable to connect to ' - f'{section}' + f'{section}', ) if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: logger.error(f'Server returned status {r.status_code}', section) return ProcessResult.failure( f'{section}: Failed to post-process - Server returned status ' - f'{r.status_code}' + f'{r.status_code}', ) success = False @@ -441,7 +440,7 @@ def process( if success: return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + f'{section}: Successfully post-processed {input_name}', ) elif section == 'NzbDrone' and started: n = 0 @@ -458,12 +457,12 @@ def process( if not os.path.exists(dir_name): logger.debug(f'The directory {dir_name} has been removed. Renaming was successful.', section) return ProcessResult.success( - f'{section}: Successfully post-processed {input_name}' + 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.success( - f'{section}: Successfully post-processed {input_name}' + 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) @@ -473,8 +472,10 @@ def process( url2 = core.utils.common.create_url(scheme, host, port, route) if completed_download_handling(url2, headers, section=section): - logger.debug(f'The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {section}.', - section) + logger.debug( + f'The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {section}.', + section, + ) return ProcessResult( message=f'{section}: Complete DownLoad Handling is enabled. ' f'Passing back to {section}', @@ -483,11 +484,11 @@ def process( else: logger.warning('The Scan command did not return a valid status. Renaming was not successful.', section) return ProcessResult.failure( - f'{section}: Failed to post-process {input_name}' + f'{section}: Failed to post-process {input_name}', ) else: # We did not receive Success confirmation. return ProcessResult.failure( f'{section}: Failed to post-process - Returned log from {section} ' - f'was not as expected.' + f'was not as expected.', ) diff --git a/core/databases.py b/core/databases.py index d3a605d1..9a3bae34 100644 --- a/core/databases.py +++ b/core/databases.py @@ -41,12 +41,12 @@ class InitialSchema(main_db.SchemaUpgrade): if cur_db_version < MIN_DB_VERSION: logger.log_error_and_exit( - 'Your database version ({current}) is too old to migrate from what this version of nzbToMedia supports ({min}).\nPlease remove nzbtomedia.db file to begin fresh.'.format(current=cur_db_version, min=MIN_DB_VERSION), + f'Your database version ({cur_db_version}) is too old to migrate from what this version of nzbToMedia supports ({MIN_DB_VERSION}).\nPlease remove nzbtomedia.db file to begin fresh.', ) if cur_db_version > MAX_DB_VERSION: logger.log_error_and_exit( - 'Your database version ({current}) has been incremented past what this version of nzbToMedia supports ({max}).\nIf you have used other forks of nzbToMedia, your database may be unusable due to their modifications.'.format(current=cur_db_version, max=MAX_DB_VERSION), + f'Your database version ({cur_db_version}) has been incremented past what this version of nzbToMedia supports ({MAX_DB_VERSION}).\nIf you have used other forks of nzbToMedia, your database may be unusable due to their modifications.', ) if cur_db_version < MAX_DB_VERSION: # We need to upgrade. queries = [ diff --git a/core/extractor/__init__.py b/core/extractor/__init__.py index c48dcf04..c87b5219 100644 --- a/core/extractor/__init__.py +++ b/core/extractor/__init__.py @@ -46,8 +46,10 @@ def extract(file_path, output_destination): if not os.getenv('TR_TORRENT_DIR'): devnull = open(os.devnull, 'w') for cmd in required_cmds: - if call(['which', cmd], stdout=devnull, - stderr=devnull): # note, returns 0 if exists, or 1 if doesn't exist. + if call( + ['which', cmd], stdout=devnull, + stderr=devnull, + ): # note, returns 0 if exists, or 1 if doesn't exist. for k, v in extract_commands.items(): if cmd in v[0]: if not call(['which', '7zr'], stdout=devnull, stderr=devnull): # we do have '7zr' @@ -57,9 +59,7 @@ def extract(file_path, output_destination): elif not call(['which', '7za'], stdout=devnull, stderr=devnull): # we do have '7za' extract_commands[k] = ['7za', 'x', '-y'] else: - core.logger.error('EXTRACTOR: {cmd} not found, ' - 'disabling support for {feature}'.format - (cmd=cmd, feature=k)) + core.logger.error(f'EXTRACTOR: {cmd} not found, disabling support for {k}') del extract_commands[k] devnull.close() else: @@ -74,7 +74,7 @@ def extract(file_path, output_destination): # Check if this is a tar if os.path.splitext(ext[0])[1] == '.tar': cmd = extract_commands[f'.tar{ext[1]}'] - else: # Try gunzip + else: # Try gunzip cmd = extract_commands[ext[1]] elif ext[1] in ('.1', '.01', '.001') and os.path.splitext(ext[0])[1] in ('.rar', '.zip', '.7z'): cmd = extract_commands[os.path.splitext(ext[0])[1]] @@ -84,8 +84,7 @@ def extract(file_path, output_destination): if ext[1] in extract_commands: cmd = extract_commands[ext[1]] else: - core.logger.debug('EXTRACTOR: Unknown file type: {ext}'.format - (ext=ext[1])) + core.logger.debug(f'EXTRACTOR: Unknown file type: {ext[1]}') return False # Create outputDestination folder @@ -96,10 +95,8 @@ def extract(file_path, output_destination): else: passwords = [] - core.logger.info('Extracting {file} to {destination}'.format - (file=file_path, destination=output_destination)) - core.logger.debug('Extracting {cmd} {file} {destination}'.format - (cmd=cmd, file=file_path, destination=output_destination)) + core.logger.info(f'Extracting {file_path} to {output_destination}') + core.logger.debug(f'Extracting {cmd} {file_path} {output_destination}') orig_files = [] orig_dirs = [] @@ -122,13 +119,12 @@ def extract(file_path, output_destination): else: cmd = core.NICENESS + cmd cmd2 = cmd - if not 'gunzip' in cmd: #gunzip doesn't support password + if not 'gunzip' in cmd: # gunzip doesn't support password cmd2.append('-p-') # don't prompt for password. p = Popen(cmd2, stdout=devnull, stderr=devnull, startupinfo=info) # should extract files fine. res = p.wait() if res == 0: # Both Linux and Windows return 0 for successful. - core.logger.info('EXTRACTOR: Extraction was successful for {file} to {destination}'.format - (file=file_path, destination=output_destination)) + core.logger.info(f'EXTRACTOR: Extraction was successful for {file_path} to {output_destination}') success = 1 elif len(passwords) > 0 and not 'gunzip' in cmd: core.logger.info('EXTRACTOR: Attempting to extract with passwords') @@ -142,17 +138,13 @@ def extract(file_path, output_destination): p = Popen(cmd2, stdout=devnull, stderr=devnull, startupinfo=info) # should extract files fine. res = p.wait() if (res >= 0 and platform == 'Windows') or res == 0: - core.logger.info('EXTRACTOR: Extraction was successful ' - 'for {file} to {destination} using password: {pwd}'.format - (file=file_path, destination=output_destination, pwd=password)) + core.logger.info(f'EXTRACTOR: Extraction was successful for {file_path} to {output_destination} using password: {password}') success = 1 break else: continue except Exception: - core.logger.error('EXTRACTOR: Extraction failed for {file}. ' - 'Could not call command {cmd}'.format - (file=file_path, cmd=cmd)) + core.logger.error(f'EXTRACTOR: Extraction failed for {file_path}. Could not call command {cmd}') os.chdir(pwd) return False @@ -177,7 +169,5 @@ def extract(file_path, output_destination): pass return True else: - core.logger.error('EXTRACTOR: Extraction failed for {file}. ' - 'Result was {result}'.format - (file=file_path, result=res)) + core.logger.error(f'EXTRACTOR: Extraction failed for {file_path}. Result was {res}') return False diff --git a/core/main_db.py b/core/main_db.py index d0030c7a..6aff97ac 100644 --- a/core/main_db.py +++ b/core/main_db.py @@ -57,7 +57,7 @@ class DBConnection: sql_result = cursor.fetchone()[0] else: logger.log( - '{name}: {query} with args {args}'.format(name=self.filename, query=query, args=args), logger.DB, + f'{self.filename}: {query} with args {args}', logger.DB, ) cursor = self.connection.cursor() cursor.execute(query, args) @@ -133,7 +133,7 @@ class DBConnection: sql_result = self.connection.execute(query) else: logger.log( - '{name}: {query} with args {args}'.format(name=self.filename, query=query, args=args), logger.DB, + f'{self.filename}: {query} with args {args}', logger.DB, ) sql_result = self.connection.execute(query, args) self.connection.commit() @@ -231,25 +231,25 @@ def pretty_name(class_name): def _process_upgrade(connection, upgrade_class): instance = upgrade_class(connection) logger.log( - 'Checking {name} database upgrade'.format(name=pretty_name(upgrade_class.__name__)), logger.DEBUG, + f'Checking {pretty_name(upgrade_class.__name__)} database upgrade', logger.DEBUG, ) if not instance.test(): logger.log( - 'Database upgrade required: {name}'.format(name=pretty_name(upgrade_class.__name__)), logger.MESSAGE, + f'Database upgrade required: {pretty_name(upgrade_class.__name__)}', logger.MESSAGE, ) try: instance.execute() except sqlite3.DatabaseError as error: print( - 'Error in {name}: {msg}'.format(name=upgrade_class.__name__, msg=error), + f'Error in {upgrade_class.__name__}: {error}', ) raise logger.log( - '{name} upgrade completed'.format(name=upgrade_class.__name__), logger.DEBUG, + f'{upgrade_class.__name__} upgrade completed', logger.DEBUG, ) else: logger.log( - '{name} upgrade not required'.format(name=upgrade_class.__name__), logger.DEBUG, + f'{upgrade_class.__name__} upgrade not required', logger.DEBUG, ) for upgradeSubClass in upgrade_class.__subclasses__(): diff --git a/core/plugins/subtitles.py b/core/plugins/subtitles.py index 8359881e..3040cbba 100644 --- a/core/plugins/subtitles.py +++ b/core/plugins/subtitles.py @@ -41,24 +41,25 @@ def import_subs(filename): except Exception as e: logger.error(f'Failed to download subtitles for {filename} due to: {e}', 'SUBTITLES') + def rename_subs(path): filepaths = [] sub_ext = ['.srt', '.sub', '.idx'] vidfiles = core.list_media_files(path, media=True, audio=False, meta=False, archives=False) - if not vidfiles or len(vidfiles) > 1: # If there is more than 1 video file, or no video files, we can't rename subs. + if not vidfiles or len(vidfiles) > 1: # If there is more than 1 video file, or no video files, we can't rename subs. return name = os.path.splitext(os.path.split(vidfiles[0])[1])[0] for directory, _, filenames in os.walk(path): for filename in filenames: filepaths.extend([os.path.join(directory, filename)]) subfiles = [item for item in filepaths if os.path.splitext(item)[1] in sub_ext] - subfiles.sort() #This should sort subtitle names by language (alpha) and Number (where multiple) + subfiles.sort() # This should sort subtitle names by language (alpha) and Number (where multiple) renamed = [] for sub in subfiles: subname, ext = os.path.splitext(os.path.basename(sub)) - if name in subname: # The sub file name already includes the video name. + if name in subname: # The sub file name already includes the video name. continue - words = re.findall('[a-zA-Z]+',str(subname)) # find whole words in string + words = re.findall('[a-zA-Z]+', str(subname)) # find whole words in string # parse the words for language descriptors. lan = None for word in words: @@ -71,7 +72,7 @@ def rename_subs(path): lan = Language.fromname(word.lower()) if lan: break - except: #if we didn't find a language, try next word. + except: # if we didn't find a language, try next word. continue # rename the sub file as name.lan.ext if not lan: @@ -79,19 +80,20 @@ def rename_subs(path): new_sub_name = name else: new_sub_name = f'{name}.{str(lan)}' - new_sub = os.path.join(directory, new_sub_name) # full path and name less ext - if f'{new_sub}{ext}' in renamed: # If duplicate names, add unique number before ext. - for i in range(1,len(renamed)+1): + new_sub = os.path.join(directory, new_sub_name) # full path and name less ext + if f'{new_sub}{ext}' in renamed: # If duplicate names, add unique number before ext. + for i in range(1, len(renamed) + 1): if f'{new_sub}.{i}{ext}' in renamed: continue new_sub = f'{new_sub}.{i}' break - new_sub = f'{new_sub}{ext}' # add extension now - if os.path.isfile(new_sub): # Don't copy over existing - final check. + new_sub = f'{new_sub}{ext}' # add extension now + if os.path.isfile(new_sub): # Don't copy over existing - final check. logger.debug(f'Unable to rename sub file {sub} as destination {new_sub} already exists') continue - logger.debug('Renaming sub file from {old} to {new}'.format - (old=sub, new=new_sub)) + logger.debug( + f'Renaming sub file from {sub} to {new_sub}', + ) renamed.append(new_sub) try: os.rename(sub, new_sub) diff --git a/core/processor/manual.py b/core/processor/manual.py index b6841cb9..ae2e08a8 100644 --- a/core/processor/manual.py +++ b/core/processor/manual.py @@ -13,7 +13,8 @@ from core.utils import ( def process(): # Perform Manual Post-Processing logger.warning( - 'Invalid number of arguments received from client, Switching to manual run mode ...') + 'Invalid number of arguments received from client, Switching to manual run mode ...', + ) # Post-Processing Result result = ProcessResult( @@ -27,13 +28,15 @@ def process(): continue for dir_name in get_dirs(section, subsection, link='move'): logger.info( - f'Starting manual run for {section}:{subsection} - Folder: {dir_name}') + f'Starting manual run for {section}:{subsection} - Folder: {dir_name}', + ) logger.info( - f'Checking database for download info for {os.path.basename(dir_name)} ...' + f'Checking database for download info for {os.path.basename(dir_name)} ...', ) core.DOWNLOAD_INFO = get_download_info( - os.path.basename(dir_name), 0) + os.path.basename(dir_name), 0, + ) if core.DOWNLOAD_INFO: logger.info(f'Found download info for {os.path.basename(dir_name)}, setting variables now ...') client_agent = core.DOWNLOAD_INFO[0]['client_agent'] or 'manual' @@ -48,12 +51,15 @@ def process(): input_name = os.path.basename(dir_name) - results = nzb.process(dir_name, input_name, 0, - client_agent=client_agent, - download_id=download_id or None, - input_category=subsection) + results = nzb.process( + dir_name, input_name, 0, + client_agent=client_agent, + download_id=download_id or None, + input_category=subsection, + ) if results.status_code != 0: logger.error( - f'A problem was reported when trying to perform a manual run for {section}:{subsection}.') + f'A problem was reported when trying to perform a manual run for {section}:{subsection}.', + ) result = results return result diff --git a/core/processor/nzb.py b/core/processor/nzb.py index 8a81f5a9..bcf06ee7 100644 --- a/core/processor/nzb.py +++ b/core/processor/nzb.py @@ -19,7 +19,8 @@ from core.utils import ( def process(input_directory, input_name=None, status=0, client_agent='manual', download_id=None, input_category=None, failure_link=None): if core.SAFE_MODE and input_directory == core.NZB_DEFAULT_DIRECTORY: logger.error( - f'The input directory:[{input_directory}] is the Default Download Directory. Please configure category directories to prevent processing of other media.') + f'The input directory:[{input_directory}] is the Default Download Directory. Please configure category directories to prevent processing of other media.', + ) return ProcessResult( message='', status_code=-1, @@ -62,7 +63,8 @@ def process(input_directory, input_name=None, status=0, client_agent='manual', d section = core.CFG.findsection('ALL').isenabled() if section is None: logger.error( - f'Category:[{input_category}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.') + f'Category:[{input_category}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.', + ) return ProcessResult( message='', status_code=-1, @@ -72,7 +74,8 @@ def process(input_directory, input_name=None, status=0, client_agent='manual', d if len(section) > 1: logger.error( - f'Category:[{input_category}] is not unique, {section.keys()} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.') + f'Category:[{input_category}] is not unique, {section.keys()} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.', + ) return ProcessResult( message='', status_code=-1, diff --git a/core/scene_exceptions.py b/core/scene_exceptions.py index bad0a177..d62921f8 100644 --- a/core/scene_exceptions.py +++ b/core/scene_exceptions.py @@ -72,7 +72,7 @@ def rename_file(filename, newfile_path): if os.path.isfile(newfile_path): newfile_path = os.path.splitext(newfile_path)[0] + '.NTM' + os.path.splitext(newfile_path)[1] logger.debug( - 'Replacing file name {old} with download name {new}'.format(old=filename, new=newfile_path), 'EXCEPTION', + f'Replacing file name {filename} with download name {newfile_path}', 'EXCEPTION', ) try: os.rename(filename, newfile_path) @@ -88,7 +88,7 @@ def replace_filename(filename, dirname, name): elif media_pattern.search(name.replace(' ', '.').lower()) is not None: newname = name.replace(' ', '.') logger.debug( - 'Replacing file name {old} with download name {new}'.format(old=head, new=newname), 'EXCEPTION', + f'Replacing file name {head} with download name {newname}', 'EXCEPTION', ) else: logger.warning(f'No name replacement determined for {head}', 'EXCEPTION') @@ -118,7 +118,7 @@ def reverse_filename(filename, dirname, name): newname = head[::-1].title() newname = newname.replace(' ', '.') logger.debug( - 'Reversing filename {old} to {new}'.format(old=head, new=newname), 'EXCEPTION', + f'Reversing filename {head} to {newname}', 'EXCEPTION', ) newfile = newname + file_extension newfile_path = os.path.join(dirname, newfile) @@ -146,7 +146,7 @@ def rename_script(dirname): if os.path.isfile(dest): continue logger.debug( - 'Renaming file {source} to {destination}'.format(source=orig, destination=dest), 'EXCEPTION', + f'Renaming file {orig} to {dest}', 'EXCEPTION', ) try: os.rename(orig, dest) diff --git a/core/utils/files.py b/core/utils/files.py index b8752299..a634ed9a 100644 --- a/core/utils/files.py +++ b/core/utils/files.py @@ -216,7 +216,7 @@ def backup_versioned_file(old_file, version): break except Exception as error: logger.log( - 'Error while trying to back up {old} to {new} : {msg}'.format(old=old_file, new=new_file, msg=error), logger.WARNING, + f'Error while trying to back up {old_file} to {new_file} : {error}', logger.WARNING, ) num_tries += 1 time.sleep(1) diff --git a/core/utils/identification.py b/core/utils/identification.py index 11130d0b..aeac0b9e 100644 --- a/core/utils/identification.py +++ b/core/utils/identification.py @@ -124,7 +124,7 @@ def category_search(input_directory, input_name, input_category, root, categorie tordir = True elif input_name and os.path.isdir(os.path.join(input_directory, sanitize_name(input_name))): logger.info( - 'SEARCH: Found torrent directory {} in input directory directory {}'.format(sanitize_name(input_name), input_directory), + f'SEARCH: Found torrent directory {sanitize_name(input_name)} in input directory directory {input_directory}', ) input_directory = os.path.join(input_directory, sanitize_name(input_name)) logger.info(f'SEARCH: Setting input_directory to {input_directory}') @@ -136,7 +136,7 @@ def category_search(input_directory, input_name, input_category, root, categorie tordir = True elif input_name and os.path.isfile(os.path.join(input_directory, sanitize_name(input_name))): logger.info( - 'SEARCH: Found torrent file {} in input directory directory {}'.format(sanitize_name(input_name), input_directory,), + f'SEARCH: Found torrent file {sanitize_name(input_name)} in input directory directory {input_directory}', ) input_directory = os.path.join(input_directory, sanitize_name(input_name)) logger.info(f'SEARCH: Setting input_directory to {input_directory}') diff --git a/core/utils/paths.py b/core/utils/paths.py index 949a0d46..bf3acc41 100644 --- a/core/utils/paths.py +++ b/core/utils/paths.py @@ -98,7 +98,7 @@ def remove_read_only(filename): if not file_attribute & stat.S_IWRITE: # File is read-only, so make it writeable logger.debug( - 'Read only mode on file {name}. Attempting to make it writeable'.format(name=filename), + f'Read only mode on file {filename}. Attempting to make it writeable', ) try: os.chmod(filename, stat.S_IWRITE)