diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index d934976163..24b4b01a17 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -142,6 +142,12 @@ def _combine_results(self, first, second, attr): else: return b + def _unicodify(self, obj, encoding = "utf-8"): + if isinstance(obj, basestring): + if not isinstance(obj, unicode): + obj = unicode(obj, encoding) + return obj + def _convert_number(self, number): if type(number) == int: return number @@ -167,6 +173,8 @@ def _convert_number(self, number): def parse(self, name): + name = self._unicodify(name) + # break it into parts if there are any (dirname, file name, extension) dir_name, file_name = os.path.split(name) ext_match = re.match('(.*)\.\w{3,4}$', file_name) @@ -225,6 +233,7 @@ def __init__(self, release_group=None, air_date=None ): + self.original_name = original_name self.series_name = series_name @@ -276,7 +285,7 @@ def __str__(self): if self.release_group: to_return += ' (' + self.release_group + ')' - return to_return + return to_return.encode('utf-8') def _is_air_by_date(self): if self.season_number == None and len(self.episode_numbers) == 0 and self.air_date: diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index 7231c6a481..4095a1d63c 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -313,7 +313,7 @@ def _analyze_name(self, name, file=True): # parse the name to break it into show name, season, and episode np = NameParser(file) parse_result = np.parse(name) - self._log("Parsed "+name+" into "+str(parse_result), logger.DEBUG) + self._log("Parsed "+name+" into "+str(parse_result).decode('utf-8'), logger.DEBUG) if parse_result.air_by_date: season = -1 diff --git a/tests/name_parser_tests.py b/tests/name_parser_tests.py index 5d6ec038a6..667e727c14 100644 --- a/tests/name_parser_tests.py +++ b/tests/name_parser_tests.py @@ -99,6 +99,27 @@ ] +unicode_test_cases = [ + (u'The.Big.Bang.Theory.2x07.The.Panty.Pi\xf1ata.Polarization.720p.HDTV.x264.AC3-SHELDON.mkv', + parser.ParseResult(None, 'The.Big.Bang.Theory', 2, [7], '720p.HDTV.x264.AC3', 'SHELDON') + ), + ('The.Big.Bang.Theory.2x07.The.Panty.Pi\xc3\xb1ata.Polarization.720p.HDTV.x264.AC3-SHELDON.mkv', + parser.ParseResult(None, 'The.Big.Bang.Theory', 2, [7], '720p.HDTV.x264.AC3', 'SHELDON') + ), + ] + +class UnicodeTests(unittest.TestCase): + + def _test_unicode(self, name, result): + print repr(name) + np = parser.NameParser(True) + parse_result = np.parse(name) + print repr(str(parse_result)) + + def test_unicode(self): + for (name, result) in unicode_test_cases: + self._test_unicode(name, result) + class ComboTests(unittest.TestCase): def _test_combo(self, name, result, which_regexes): @@ -232,7 +253,10 @@ def test_combination_names(self): suite = unittest.TestLoader().loadTestsFromName('name_parser_tests.BasicTests.test_'+sys.argv[1]) else: suite = unittest.TestLoader().loadTestsFromTestCase(BasicTests) - unittest.TextTestRunner(verbosity=2).run(suite) + #unittest.TextTestRunner(verbosity=2).run(suite) suite = unittest.TestLoader().loadTestsFromTestCase(ComboTests) + #unittest.TextTestRunner(verbosity=2).run(suite) + + suite = unittest.TestLoader().loadTestsFromTestCase(UnicodeTests) unittest.TextTestRunner(verbosity=2).run(suite)