9494 MICROSECONDS_PER_CODEWORD , CHARACTER_TO_CODE ,
9595 SPECIAL_OR_EXTENDED_CHAR_TO_CODE , PAC_BYTES_TO_POSITIONING_MAP ,
9696 PAC_HIGH_BYTE_BY_ROW , PAC_LOW_BYTE_BY_ROW_RESTRICTED ,
97- PAC_TAB_OFFSET_COMMANDS ,
97+ PAC_TAB_OFFSET_COMMANDS , CUE_STARTING_COMMAND
9898)
9999from .specialized_collections import ( # noqa: F401
100100 TimingCorrectingCaptionList , NotifyingDict , CaptionCreator ,
@@ -164,6 +164,7 @@ def __init__(self, *args, **kw):
164164 )
165165
166166 self .last_command = ''
167+ self .double_starter = False
167168
168169 self .buffer_dict = NotifyingDict ()
169170
@@ -223,6 +224,7 @@ def read(self, content, lang='en-US', simulate_roll_up=False, offset=0):
223224 # split lines
224225 lines = content .splitlines ()
225226
227+
226228 # loop through each line except the first
227229 for line in lines [1 :]:
228230 self ._translate_line (line )
@@ -307,24 +309,21 @@ def _translate_line(self, line):
307309 parts = r .findall (line .lower ())
308310
309311 self .time_translator .start_at (parts [0 ][0 ])
310-
311312 word_list = parts [0 ][2 ].split (' ' )
312- pacs_are_doubled = len ( word_list ) > 1 and word_list [ 0 ] == word_list [ 1 ]
313+
313314 for idx , word in enumerate (word_list ):
314- # ignore empty results or invalid commands
315315 word = word .strip ()
316- previous_is_pac_or_tab = idx > 0 and (
317- _is_pac_command (word_list [idx - 1 ]) or word_list [idx - 1 ] in PAC_TAB_OFFSET_COMMANDS
316+ previous_is_pac_or_tab = len ( word_list ) > 1 and (
317+ _is_pac_command (word_list [idx - 1 ]) or word_list [idx - 1 ] in PAC_TAB_OFFSET_COMMANDS
318318 )
319319 if len (word ) == 4 :
320320 self ._translate_word (
321321 word = word ,
322322 previous_is_pac_or_tab = previous_is_pac_or_tab ,
323- pacs_are_doubled = pacs_are_doubled
324323 )
325324
326- def _translate_word (self , word , previous_is_pac_or_tab , pacs_are_doubled ):
327- if self ._handle_double_command (word , pacs_are_doubled ):
325+ def _translate_word (self , word , previous_is_pac_or_tab ):
326+ if self ._handle_double_command (word ):
328327 # count frames for timing
329328 self .time_translator .increment_frames ()
330329 return
@@ -348,19 +347,25 @@ def _translate_word(self, word, previous_is_pac_or_tab, pacs_are_doubled):
348347 # count frames for timing only after processing a command
349348 self .time_translator .increment_frames ()
350349
351- def _handle_double_command (self , word , pacs_are_doubled ):
350+ def _handle_double_command (self , word ):
352351 # If the caption is to be broadcast, each of the commands are doubled
353352 # up for redundancy in case the signal is garbled in transmission.
354353 # The decoder is programmed to ignore a second command when it is the
355354 # same as the first.
356355 # If we have doubled commands we're skipping also
357356 # doubled special characters and doubled extended characters
358357 # with only one member of each pair being displayed.
359- doubled_types = word in COMMANDS or _is_pac_command (word )
360- if pacs_are_doubled :
361- doubled_types = doubled_types or word in SPECIAL_CHARS or word in EXTENDED_CHARS
358+
359+ doubled_types = word != "94a1" and word in COMMANDS or _is_pac_command (word )
360+ if self .double_starter :
361+ doubled_types = doubled_types or word in EXTENDED_CHARS or word == "94a1" or word in SPECIAL_CHARS
362+
363+ if word in CUE_STARTING_COMMAND and word != self .last_command :
364+ self .double_starter = False
362365
363366 if doubled_types and word == self .last_command :
367+ if word in CUE_STARTING_COMMAND :
368+ self .double_starter = True
364369 self .last_command = ''
365370 return True
366371 # Fix for the <position> <tab offset> <position> <tab offset>
0 commit comments