Skip to content

OCTO-10933-ignore-Cue-Without-a-PAC #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pycaption/scc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,26 @@ def _translate_line(self, line):
# split line in timestamp and words
r = re.compile(r"([0-9:;]*)([\s\t]*)((.)*)")
parts = r.findall(line.lower())
words = parts[0][2].split(' ')
last_code = words[-1]
first_code = words[0]
first_code_is_text = first_code[:2] in CHARACTERS and first_code[2:] in CHARACTERS

# in case we're in roll-on mode and the line starts with text and
# the line doesn't change mode to pop-on
# we print the characters to a new line by inserting 94ad at the start
if self.buffer_dict.active_key != "paint" and first_code_is_text:
if self.buffer_dict.active_key == "roll" and last_code != "942f":
words = ["94ad"] + words
else:
# if line starts with characters and we're not in paint or roll
# mode, we skip this line
return

self.time_translator.start_at(parts[0][0])

# loop through each word
for word in parts[0][2].split(' '):
for word in words:
# ignore empty results or invalid commands
word = word.strip()
if len(word) == 4:
Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
sample_scc_duplicate_tab_offset, sample_scc_duplicate_special_characters,
sample_scc_tab_offset, sample_scc_with_unknown_commands,
sample_scc_special_and_extended_characters,
sample_scc_with_line_too_long
sample_scc_with_line_too_long,
sample_scc_starting_with_text_roll,
sample_scc_starting_with_text_paint,
sample_scc_starting_with_text_pop,
sample_scc_starting_with_text_end_in_942f
)
from tests.fixtures.srt import ( # noqa: F401
sample_srt, sample_srt_ascii, sample_srt_numeric, sample_srt_empty,
Expand Down
76 changes: 76 additions & 0 deletions tests/fixtures/scc.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,79 @@ def sample_scc_with_line_too_long():

00:00:08;58 9420 9452 4920 ea75 73f4 20f7 616e f4e5 6420 ef6e e520 7368 eff7 2c80 94f2 ea75 73f4 20f4 ef20 6861 76e5 2061 7320 6120 ece9 f4f4 ece5 942c 8080 8080 942f
"""


@pytest.fixture(scope="session")
def sample_scc_starting_with_text_roll():
return """\
Scenarist_SCC V1.0

00:21:59;22 942c

01:38:32;27 9426 9426 94ad 94ad 9470 9470 54c8 4520 c1cd 4552 4943 c1ce 2045 58d0 4552 4945 ce43 4520 54c8 524f d5c7 c880

01:38:34;06 9426 9426 94ad 94ad 9470 9470 51d5 c14c 4954 d920 5445 4c45 d649 d349 4fce 20d0 524f c752 c1cd cd49 cec7 ae80

01:38:36;20 942c 942c

01:38:36;27 5449 4fce 2c80

01:38:40;20 9420 9420 94ae 94ae 9452 9452 97a2 97a2 c445 c449 43c1 5445 c420 544f 2045 c4d5 43c1 5449 4fce 94f2 94f2 97a2 97a2 c1ce c420 51d5 c14c 4954 d920 5445 4c45 d649 d349 4fce ae80 942f 942f
"""


@pytest.fixture(scope="session")
def sample_scc_starting_with_text_paint():
return """\
Scenarist_SCC V1.0

00:21:59;22 942c

01:38:32;27 9426 9426 94ad 94ad 9470 9470 54c8 4520 c1cd 4552 4943 c1ce 2045 58d0 4552 4945 ce43 4520 54c8 524f d5c7 c880

01:38:34;06 9426 9426 94ad 94ad 9470 9470 51d5 c14c 4954 d920 5445 4c45 d649 d349 4fce 20d0 524f c752 c1cd cd49 cec7 ae80

01:38:36;20 942c 942c 9429

01:38:36;27 5449 4fce 2c80

01:38:40;20 9420 9420 94ae 94ae 9452 9452 97a2 97a2 c445 c449 43c1 5445 c420 544f 2045 c4d5 43c1 5449 4fce 94f2 94f2 97a2 97a2 c1ce c420 51d5 c14c 4954 d920 5445 4c45 d649 d349 4fce ae80 942f 942f
"""


@pytest.fixture(scope="session")
def sample_scc_starting_with_text_pop():
return """\
Scenarist_SCC V1.0

00:21:59;22 942c

01:38:32;27 9426 9426 94ad 94ad 9470 9470 54c8 4520 c1cd 4552 4943 c1ce 2045 58d0 4552 4945 ce43 4520 54c8 524f d5c7 c880

01:38:34;06 9426 9426 94ad 94ad 9470 9470 51d5 c14c 4954 d920 5445 4c45 d649 d349 4fce 20d0 524f c752 c1cd cd49 cec7 ae80 942f

01:38:36;20 942c 942c

01:38:36;27 5449 4fce 2c80 942f

01:38:40;20 9420 9420 94ae 94ae 9452 9452 97a2 97a2 c445 c449 43c1 5445 c420 544f 2045 c4d5 43c1 5449 4fce 94f2 94f2 97a2 97a2 c1ce c420 51d5 c14c 4954 d920 5445 4c45 d649 d349 4fce ae80 942f 942f
"""


@pytest.fixture(scope="session")
def sample_scc_starting_with_text_end_in_942f():
return """\
Scenarist_SCC V1.0

00:21:59;22 942c

01:38:32;27 9426 9426 94ad 94ad 9470 9470 54c8 4520 c1cd 4552 4943 c1ce 2045 58d0 4552 4945 ce43 4520 54c8 524f d5c7 c880

01:38:34;06 9426 9426 94ad 94ad 9470 9470 51d5 c14c 4954 d920 5445 4c45 d649 d349 4fce 20d0 524f c752 c1cd cd49 cec7 ae80

01:38:36;20 942c 942c

01:38:36;27 5449 4fce 2c80 942f

01:38:40;20 9420 9420 94ae 94ae 9452 9452 97a2 97a2 c445 c449 43c1 5445 c420 544f 2045 c4d5 43c1 5449 4fce 94f2 94f2 97a2 97a2 c1ce c420 51d5 c14c 4954 d920 5445 4c45 d649 d349 4fce ae80 942f 942f
"""
77 changes: 76 additions & 1 deletion tests/test_scc.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,81 @@ def test_line_too_long(self, sample_scc_with_line_too_long):
assert ("was Cal l l l l l l l l l l l l l l l l l l l l l l l l l l l l Denison, a friend - Length 81"
in exc_info.value.args[0].split("\n"))

def test_lines_starting_with_text(
self,
sample_scc_starting_with_text_roll,
sample_scc_starting_with_text_paint,
sample_scc_starting_with_text_pop,
sample_scc_starting_with_text_end_in_942f
):
# if we're in roll on mode and the last command is not 942f
# the characters should be displayed on a new line
caption_set = SCCReader().read(sample_scc_starting_with_text_roll)
expected_lines = [
'THE AMERICAN EXPERIENCE THROUGH',
'QUALITY TELEVISION PROGRAMMING.',
'TION,',
'DEDICATED TO EDUCATION',
'AND QUALITY TELEVISION.'
]
actual_lines = [
node.content
for cap_ in caption_set.get_captions('en-US')
for node in cap_.nodes
if node.type_ == CaptionNode.TEXT
]
assert expected_lines == actual_lines

# in roll mode if text ends with 942f then the text is ignored
caption_set = SCCReader().read(sample_scc_starting_with_text_end_in_942f)
expected_lines = [
'THE AMERICAN EXPERIENCE THROUGH',
'QUALITY TELEVISION PROGRAMMING.',
'DEDICATED TO EDUCATION',
'AND QUALITY TELEVISION.'
]
actual_lines = [
node.content
for cap_ in caption_set.get_captions('en-US')
for node in cap_.nodes
if node.type_ == CaptionNode.TEXT
]
assert expected_lines == actual_lines

# in paint mode the text will be displayed with no changes
# in new line
caption_set = SCCReader().read(sample_scc_starting_with_text_paint)
expected_lines = [
'THE AMERICAN EXPERIENCE THROUGH',
'QUALITY TELEVISION PROGRAMMING.',
'TION,',
'DEDICATED TO EDUCATION',
'AND QUALITY TELEVISION.'
]
actual_lines = [
node.content
for cap_ in caption_set.get_captions('en-US')
for node in cap_.nodes
if node.type_ == CaptionNode.TEXT
]
assert expected_lines == actual_lines

# in pop mode the text will be ignored
caption_set = SCCReader().read(sample_scc_starting_with_text_pop)
expected_lines = [
'THE AMERICAN EXPERIENCE THROUGH',
'QUALITY TELEVISION PROGRAMMING.',
'DEDICATED TO EDUCATION',
'AND QUALITY TELEVISION.'
]
actual_lines = [
node.content
for cap_ in caption_set.get_captions('en-US')
for node in cap_.nodes
if node.type_ == CaptionNode.TEXT
]
assert expected_lines == actual_lines


class TestCoverageOnly:
"""In order to refactor safely, we need coverage of 95% or more.
Expand Down Expand Up @@ -584,4 +659,4 @@ def test_eoc_first_command(self, sample_scc_eoc_first_command):
# just one caption, first EOC disappears
num_captions = len(caption_set.get_captions('en-US'))

assert num_captions == 2
assert num_captions == 1