From 71c435ba48b629c32727c65350cb31e08ef77a46 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Sun, 5 Jan 2020 12:22:23 +1300 Subject: [PATCH 1/6] fix encoding issue with python3 #1694 --- core/utils/encoding.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/utils/encoding.py b/core/utils/encoding.py index bd6183d5..b97083d8 100644 --- a/core/utils/encoding.py +++ b/core/utils/encoding.py @@ -27,13 +27,13 @@ def char_replace(name_in): encoded = False encoding = None if isinstance(name_in, text_type): - return encoded, name_in.encode(core.SYS_ENCODING) + return encoded, str(name_in.encode(core.SYS_ENCODING)) if PY2: name = name_in else: name = bytes(name_in) for Idx in range(len(name)): - print('Trying to intuit the encoding') + # print('Trying to intuit the encoding') # /!\ detection is done 2char by 2char for UTF-8 special character if (len(name) != 1) & (Idx < (len(name) - 1)): # Detect UTF-8 @@ -61,7 +61,7 @@ def char_replace(name_in): if encoding and not encoding == core.SYS_ENCODING: encoded = True name = name.decode(encoding).encode(core.SYS_ENCODING) - return encoded, name + return encoded, str(name) def convert_to_ascii(input_name, dir_name): From f2c07f3c386cbe375728214f370468fdd77bf30f Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Sun, 5 Jan 2020 13:39:23 +1300 Subject: [PATCH 2/6] fix encoding checks --- core/utils/encoding.py | 88 ++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 30 deletions(-) diff --git a/core/utils/encoding.py b/core/utils/encoding.py index b97083d8..e4ad894a 100644 --- a/core/utils/encoding.py +++ b/core/utils/encoding.py @@ -27,41 +27,69 @@ def char_replace(name_in): encoded = False encoding = None if isinstance(name_in, text_type): - return encoded, str(name_in.encode(core.SYS_ENCODING)) + return encoded, name_in if PY2: name = name_in + for Idx in range(len(name)): + # print('Trying to intuit the encoding') + # /!\ detection is done 2char by 2char for UTF-8 special character + if (len(name) != 1) & (Idx < (len(name) - 1)): + # Detect UTF-8 + if ((name[Idx] == '\xC2') | (name[Idx] == '\xC3')) & ( + (name[Idx + 1] >= '\xA0') & (name[Idx + 1] <= '\xFF')): + encoding = 'utf-8' + break + # Detect CP850 + elif (name[Idx] >= '\x80') & (name[Idx] <= '\xA5'): + encoding = 'cp850' + break + # Detect ISO-8859-15 + elif (name[Idx] >= '\xA6') & (name[Idx] <= '\xFF'): + encoding = 'iso-8859-15' + break + else: + # Detect CP850 + if (name[Idx] >= '\x80') & (name[Idx] <= '\xA5'): + encoding = 'cp850' + break + # Detect ISO-8859-15 + elif (name[Idx] >= '\xA6') & (name[Idx] <= '\xFF'): + encoding = 'iso-8859-15' + break else: name = bytes(name_in) - for Idx in range(len(name)): - # print('Trying to intuit the encoding') - # /!\ detection is done 2char by 2char for UTF-8 special character - 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)): - encoding = 'utf-8' - break - # Detect CP850 - elif (name[Idx] >= 0x80) & (name[Idx] <= 0xA5): - encoding = 'cp850' - break - # Detect ISO-8859-15 - elif (name[Idx] >= 0xA6) & (name[Idx] <= 0xFF): - encoding = 'iso-8859-15' - break - else: - # Detect CP850 - if (name[Idx] >= 0x80) & (name[Idx] <= 0xA5): - encoding = 'cp850' - break - # Detect ISO-8859-15 - elif (name[Idx] >= 0xA6) & (name[Idx] <= 0xFF): - encoding = 'iso-8859-15' - break - if encoding and not encoding == core.SYS_ENCODING: + for Idx in range(len(name)): + # print('Trying to intuit the encoding') + # /!\ detection is done 2char by 2char for UTF-8 special character + 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)): + encoding = 'utf-8' + break + # Detect CP850 + elif (name[Idx] >= 0x80) & (name[Idx] <= 0xA5): + encoding = 'cp850' + break + # Detect ISO-8859-15 + elif (name[Idx] >= 0xA6) & (name[Idx] <= 0xFF): + encoding = 'iso-8859-15' + break + else: + # Detect CP850 + if (name[Idx] >= 0x80) & (name[Idx] <= 0xA5): + encoding = 'cp850' + break + # Detect ISO-8859-15 + elif (name[Idx] >= 0xA6) & (name[Idx] <= 0xFF): + encoding = 'iso-8859-15' + break + if encoding: encoded = True - name = name.decode(encoding).encode(core.SYS_ENCODING) - return encoded, str(name) + name = name.decode(encoding) + elif not PY2: + name = name.decode() + return encoded, name def convert_to_ascii(input_name, dir_name): From b8784d71dd1bcc769cc630b1e4385409bf62fae5 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Wed, 8 Jan 2020 07:03:11 +1300 Subject: [PATCH 3/6] Fix Json returned from Sonarr and Lidarr (#1697) --- core/auto_process/music.py | 2 +- core/auto_process/tv.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/auto_process/music.py b/core/auto_process/music.py index e72d9b8c..af3bb166 100644 --- a/core/auto_process/music.py +++ b/core/auto_process/music.py @@ -125,7 +125,7 @@ def process(section, dir_name, input_name=None, status=0, client_agent='manual', ) try: - res = json.loads(r.content) + res = r.json() scan_id = int(res['id']) logger.debug('Scan started with id: {0}'.format(scan_id), section) except Exception as e: diff --git a/core/auto_process/tv.py b/core/auto_process/tv.py index 57fe2a1e..4c6edfac 100644 --- a/core/auto_process/tv.py +++ b/core/auto_process/tv.py @@ -343,7 +343,7 @@ def process(section, dir_name, input_name=None, failed=False, client_agent='manu time.sleep(60) elif section == 'NzbDrone': try: - res = json.loads(r.content) + res = r.json() scan_id = int(res['id']) logger.debug('Scan started with id: {0}'.format(scan_id), section) started = True From bbc8f132c3713859e88e99eaa850c83948fab89f Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Thu, 9 Jan 2020 14:18:23 +1300 Subject: [PATCH 4/6] fixed typo #1698 --- core/utils/identification.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/utils/identification.py b/core/utils/identification.py index 84fa834a..bd7dff04 100644 --- a/core/utils/identification.py +++ b/core/utils/identification.py @@ -63,7 +63,7 @@ def find_imdbid(dir_name, input_name, omdb_api_key): url = 'http://www.omdbapi.com' if not omdb_api_key: - logger.info('Unable to determine imdbID: No api key provided for ombdapi.com.') + logger.info('Unable to determine imdbID: No api key provided for omdbapi.com.') return logger.debug('Opening URL: {0}'.format(url)) From 6861b9915e9c15e009e1218e065c3f24b1814101 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Mon, 13 Jan 2020 20:40:46 +1300 Subject: [PATCH 5/6] fix empty dir_name #1673 (#1700) --- core/auto_process/tv.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/auto_process/tv.py b/core/auto_process/tv.py index 4c6edfac..801f3234 100644 --- a/core/auto_process/tv.py +++ b/core/auto_process/tv.py @@ -95,12 +95,13 @@ def process(section, dir_name, input_name=None, failed=False, client_agent='manu # Attempt to create the directory if it doesn't exist and ignore any # error stating that it already exists. This fixes a bug where SickRage # won't process the directory because it doesn't exist. - try: - os.makedirs(dir_name) # Attempt to create the directory - except OSError as e: - # Re-raise the error if it wasn't about the directory not existing - if e.errno != errno.EEXIST: - raise + if dir_name: + try: + os.makedirs(dir_name) # Attempt to create the directory + except OSError as e: + # Re-raise the error if it wasn't about the directory not existing + if e.errno != errno.EEXIST: + raise if 'process_method' not in fork_params or (client_agent in ['nzbget', 'sabnzbd'] and nzb_extraction_by != 'Destination'): if input_name: From 43312fc64279d6732d3a740e25d815075a3ea743 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Mon, 13 Jan 2020 21:00:12 +1300 Subject: [PATCH 6/6] update to v12.1.04 --- .bumpversion.cfg | 2 +- core/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 4fd8e112..aa40e7a1 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 12.1.03 +current_version = 12.1.04 commit = True tag = False diff --git a/core/__init__.py b/core/__init__.py index 9814c87f..8cdcfeee 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -83,7 +83,7 @@ from core.utils import ( wake_up, ) -__version__ = '12.1.03' +__version__ = '12.1.04' # Client Agents NZB_CLIENTS = ['sabnzbd', 'nzbget', 'manual'] diff --git a/setup.py b/setup.py index 19d0a3b7..df77e262 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def read(*names, **kwargs): setup( name='nzbToMedia', - version='12.1.03', + version='12.1.04', license='GPLv3', description='Efficient on demand post processing', long_description="""