diff --git a/pycaption/scc/__init__.py b/pycaption/scc/__init__.py index 5e4f5d02..dbfc51d4 100644 --- a/pycaption/scc/__init__.py +++ b/pycaption/scc/__init__.py @@ -164,7 +164,7 @@ def __init__(self, *args, **kw): ) self.last_command = '' - self.cue = [] + self.double_starter = None self.buffer_dict = NotifyingDict() @@ -309,29 +309,18 @@ def _translate_line(self, line): parts = r.findall(line.lower()) self.time_translator.start_at(parts[0][0]) - cue_starters = ['9425', '9426', '94a7', '9429', '9420'] word_list = parts[0][2].split(' ') + for idx, word in enumerate(word_list): - # ignore empty results or invalid commands word = word.strip() - # if line_starts_a_cue: - if word in cue_starters: - if len(word_list) > 0 and word_list[idx] == word_list[idx-1]: - self.cue.append(word) - else: - self.cue = [word] - else: - self.cue.append(word) - - previous_is_pac_or_tab = len(self.cue) > 1 and ( + previous_is_pac_or_tab = len(word_list) > 1 and ( _is_pac_command(word_list[idx - 1]) or word_list[idx - 1] in PAC_TAB_OFFSET_COMMANDS ) - pacs_are_doubled = len(self.cue) > 1 and self.cue[0] == self.cue[1] if len(word) == 4: self._translate_word( word=word, previous_is_pac_or_tab=previous_is_pac_or_tab, - pacs_are_doubled=pacs_are_doubled + pacs_are_doubled=self.double_starter ) def _translate_word(self, word, previous_is_pac_or_tab, pacs_are_doubled): @@ -367,12 +356,17 @@ def _handle_double_command(self, word, pacs_are_doubled): # If we have doubled commands we're skipping also # doubled special characters and doubled extended characters # with only one member of each pair being displayed. - + cue_starter_commands = ['9425', '9426', '94a7', '9429', '9420'] doubled_types = word != "94a1" and word in COMMANDS or _is_pac_command(word) if pacs_are_doubled: - doubled_types = doubled_types or word in SPECIAL_CHARS or word in EXTENDED_CHARS or word == "94a1" + doubled_types = doubled_types or word in EXTENDED_CHARS or word == "94a1" + + if word in cue_starter_commands and word != self.last_command: + self.double_starter = False if doubled_types and word == self.last_command: + if word in cue_starter_commands: + self.double_starter = True self.last_command = '' return True # Fix for the diff --git a/pycaption/scc/specialized_collections.py b/pycaption/scc/specialized_collections.py index 920d0d7c..deaf56b9 100644 --- a/pycaption/scc/specialized_collections.py +++ b/pycaption/scc/specialized_collections.py @@ -1,5 +1,4 @@ import collections -import unicodedata from ..base import CaptionList, Caption, CaptionNode from ..geometry import ( @@ -9,7 +8,7 @@ from .constants import ( PAC_BYTES_TO_POSITIONING_MAP, COMMANDS, PAC_TAB_OFFSET_COMMANDS, MICROSECONDS_PER_CODEWORD, BACKGROUND_COLOR_CODES, - MID_ROW_CODES, EXTENDED_CHARS, SPECIAL_CHARS + MID_ROW_CODES, EXTENDED_CHARS ) PopOnCue = collections.namedtuple("PopOnCue", "buffer, start, end") diff --git a/tests/test_scc.py b/tests/test_scc.py index ece0e1ce..13a1da8c 100644 --- a/tests/test_scc.py +++ b/tests/test_scc.py @@ -223,11 +223,10 @@ def test_skip_duplicate_tab_offset(self, sample_scc_duplicate_tab_offset): def test_skip_duplicate_special_characters( self, sample_scc_duplicate_special_characters): expected_lines = [ - '®°½¿™¢£♪à èâêîôû', + '®®°°½½¿¿™™¢¢££♪♪àà èèââêêîîôôûû', '®°½¿™¢£♪à èâêîôû', '®°AA½¿™¢£♪à èâêAAîôû' ] - caption_set = SCCReader().read(sample_scc_duplicate_special_characters) actual_lines = [ node.content @@ -278,7 +277,7 @@ def test_freeze_rollup_captions_contents(self, sample_scc_roll_up_ru2): 'HELPING THE LOCAL NEIGHBORHOODS', 'AND IMPROVING THE LIVES OF ALL', 'WE SERVE.', - '®°½', + '®°½½', 'ABû', 'ÁÉÓ¡', "WHERE YOU'RE STANDING NOW,",