Skip to content

Commit

Permalink
solve the doubles at the start of cue issue
Browse files Browse the repository at this point in the history
  • Loading branch information
OlteanuRares committed May 24, 2024
1 parent 61d8e84 commit a51632f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
28 changes: 11 additions & 17 deletions pycaption/scc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __init__(self, *args, **kw):
)

self.last_command = ''
self.cue = []
self.double_starter = None

self.buffer_dict = NotifyingDict()

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 <position> <tab offset> <position> <tab offset>
Expand Down
3 changes: 1 addition & 2 deletions pycaption/scc/specialized_collections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import collections
import unicodedata

from ..base import CaptionList, Caption, CaptionNode
from ..geometry import (
Expand All @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions tests/test_scc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,",
Expand Down

0 comments on commit a51632f

Please sign in to comment.