diff --git a/core/utils/encoding.py b/core/utils/encoding.py index 5111a672..16253287 100644 --- a/core/utils/encoding.py +++ b/core/utils/encoding.py @@ -22,7 +22,8 @@ def char_replace(name_in): if (len(name) != 1) & (Idx < (len(name) - 1)): # Detect UTF-8 if ((name[Idx] == 0xC2) | (name[Idx] == 0xC3)) & ( - (name[Idx + 1] >= 0xA0) & (name[Idx + 1] <= 0xFF)): + (name[Idx + 1] >= 0xA0) & (name[Idx + 1] <= 0xFF) + ): encoding = 'utf-8' break # Detect CP850 diff --git a/core/utils/files.py b/core/utils/files.py index 5364f0ed..b8752299 100644 --- a/core/utils/files.py +++ b/core/utils/files.py @@ -45,11 +45,11 @@ def move_file(mediafile, path, link): title = os.path.splitext(os.path.basename(mediafile))[0] new_path = os.path.join(path, sanitize_name(title)) - # Removed as encoding of directory no-longer required - #try: - # new_path = new_path.encode(core.SYS_ENCODING) - #except Exception: - # pass + # # Removed as encoding of directory no-longer required + # try: + # new_path = new_path.encode(core.SYS_ENCODING) + # except Exception: + # pass # Just fail-safe incase we already have afile with this clean-name (was actually a bug from earlier code, but let's be safe). if os.path.isfile(new_path): @@ -215,8 +215,9 @@ def backup_versioned_file(old_file, version): logger.log('Backup done', logger.DEBUG) 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) + logger.log( + 'Error while trying to back up {old} to {new} : {msg}'.format(old=old_file, new=new_file, msg=error), logger.WARNING, + ) num_tries += 1 time.sleep(1) logger.log('Trying again.', logger.DEBUG) diff --git a/core/utils/identification.py b/core/utils/identification.py index 3f45d6d4..11130d0b 100644 --- a/core/utils/identification.py +++ b/core/utils/identification.py @@ -61,8 +61,10 @@ def find_imdbid(dir_name, input_name, omdb_api_key): logger.debug(f'Opening URL: {url}') try: - r = requests.get(url, params={'apikey': omdb_api_key, 'y': year, 't': title}, - verify=False, timeout=(60, 300)) + r = requests.get( + url, params={'apikey': omdb_api_key, 'y': year, 't': title}, + verify=False, timeout=(60, 300), + ) except requests.ConnectionError: logger.error(f'Unable to open URL {url}') return @@ -111,7 +113,8 @@ def category_search(input_directory, input_name, input_category, root, categorie if input_category and os.path.isdir(os.path.join(input_directory, input_category)): logger.info( - f'SEARCH: Found category directory {input_category} in input directory directory {input_directory}') + f'SEARCH: Found category directory {input_category} in input directory directory {input_directory}', + ) input_directory = os.path.join(input_directory, input_category) logger.info(f'SEARCH: Setting input_directory to {input_directory}') if input_name and os.path.isdir(os.path.join(input_directory, input_name)): @@ -120,8 +123,9 @@ def category_search(input_directory, input_name, input_category, root, categorie logger.info(f'SEARCH: Setting input_directory to {input_directory}') 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)) + logger.info( + 'SEARCH: Found torrent directory {} in input directory directory {}'.format(sanitize_name(input_name), input_directory), + ) input_directory = os.path.join(input_directory, sanitize_name(input_name)) logger.info(f'SEARCH: Setting input_directory to {input_directory}') tordir = True @@ -131,8 +135,9 @@ def category_search(input_directory, input_name, input_category, root, categorie logger.info(f'SEARCH: Setting input_directory to {input_directory}') 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)) + logger.info( + 'SEARCH: Found torrent file {} in input directory directory {}'.format(sanitize_name(input_name), input_directory,), + ) input_directory = os.path.join(input_directory, sanitize_name(input_name)) logger.info(f'SEARCH: Setting input_directory to {input_directory}') tordir = True diff --git a/core/utils/parsers.py b/core/utils/parsers.py index ca90760a..5f0631a4 100644 --- a/core/utils/parsers.py +++ b/core/utils/parsers.py @@ -82,7 +82,7 @@ def parse_synods(args): input_category = '' input_name = os.getenv('TR_TORRENT_NAME') input_hash = os.getenv('TR_TORRENT_HASH') - if not input_name: # No info passed. Assume manual download. + if not input_name: # No info passed. Assume manual download. return input_directory, input_name, input_category, input_hash, input_id torrent_id = os.getenv('TR_TORRENT_ID') input_id = f'dbid_{torrent_id}' @@ -92,12 +92,12 @@ def parse_synods(args): if res['success']: try: tasks = res['data']['tasks'] - task = [ task for task in tasks if task['id'] == input_id ][0] + task = [task for task in tasks if task['id'] == input_id][0] input_id = task['id'] input_directory = task['additional']['detail']['destination'] except: logger.error('unable to find download details in Synology DS') - #Syno paths appear to be relative. Let's test to see if the returned path exists, and if not append to /volume1/ + # Syno paths appear to be relative. Let's test to see if the returned path exists, and if not append to /volume1/ if not os.path.isdir(input_directory): for root in ['/volume1/', '/volume2/', '/volume3/', '/volume4/']: if os.path.isdir(os.path.join(root, input_directory)): diff --git a/core/utils/paths.py b/core/utils/paths.py index a927464b..949a0d46 100644 --- a/core/utils/paths.py +++ b/core/utils/paths.py @@ -97,8 +97,9 @@ def remove_read_only(filename): file_attribute = os.stat(filename)[0] 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)) + logger.debug( + 'Read only mode on file {name}. Attempting to make it writeable'.format(name=filename), + ) try: os.chmod(filename, stat.S_IWRITE) except Exception: