Skip to content

Commit

Permalink
Merge pull request #328 from pbs/OCTO-10929-pass-the-caption-cue-time…
Browse files Browse the repository at this point in the history
…-with-all-error-messages

Octo 10929 pass the caption cue time with all error messages
  • Loading branch information
OlteanuRares authored Apr 9, 2024
2 parents c7d1cc1 + 0379378 commit 0ff80f4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Changelog
---------
2.2.6
^^^^^
- Pass the caption cue time with all error messages.

2.2.5
^^^^^
- Yanked.

2.2.4
^^^^^
- Skip duplicated extended characters.
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
# built documents.
#
# The short X.Y version.
version = '2.2.4'
version = '2.2.6'
# The full version, including alpha/beta/rc tags.
release = '2.2.4'
release = '2.2.6'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
28 changes: 18 additions & 10 deletions pycaption/scc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
import math
import re
import textwrap
from collections import deque
from collections import deque, defaultdict
from copy import deepcopy

from pycaption.base import (
BaseReader, BaseWriter, CaptionSet, CaptionNode,
BaseReader, BaseWriter, CaptionSet
)
from pycaption.exceptions import CaptionReadNoCaptions, InvalidInputError, \
CaptionReadTimingError, CaptionLineLengthError
Expand Down Expand Up @@ -232,16 +232,24 @@ def read(self, content, lang='en-US', simulate_roll_up=False, offset=0):
captions = CaptionSet({lang: self.caption_stash.get_all()})

# check captions for incorrect lengths
lines = []
lines_too_long = defaultdict(list)
for caption in self.caption_stash._collection:
caption_start = caption.to_real_caption().format_start()
caption_text = "".join(caption.to_real_caption().get_text_nodes())
lines.extend(caption_text.split("\n"))
lines_too_long = [line for line in lines if len(line) > 32]

if bool(lines_too_long):
msg = ""
for line in lines_too_long:
msg += line + f" - Length { len(line)}" + "\n"
text_too_long = [line for line in caption_text.split("\n") if len(line) > 32]
if caption_start in lines_too_long:
lines_too_long[caption_start] = text_too_long
else:
lines_too_long[caption_start].extend(text_too_long)

msg = ""
if bool(lines_too_long.keys()):
for key in lines_too_long:
if lines_too_long[key]:
msg += f"around {key} - "
for line in lines_too_long[key]:
msg += line + f" - Length { len(line)}" + "\n"
if len(msg):
raise CaptionLineLengthError(
f"32 character limit for caption cue in scc file.\n"
f"Lines longer than 32:\n"
Expand Down
1 change: 0 additions & 1 deletion pycaption/scc/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from itertools import product
from collections import defaultdict

COMMANDS = {
'9420': '',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

setup(
name='pycaption',
version='2.2.4',
version='2.2.6',
description='Closed caption converter',
long_description=open(README_PATH).read(),
author='Joe Norton',
Expand Down
5 changes: 3 additions & 2 deletions tests/test_scc.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ def test_line_too_long(self, sample_scc_with_line_too_long):

assert exc_info.value.args[0].startswith(
"32 character limit for caption cue in scc file.")
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"))
str_to_check = ("around 00:00:05.900 - 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")
assert str_to_check in exc_info.value.args[0].split("\n")


class TestCoverageOnly:
Expand Down

0 comments on commit 0ff80f4

Please sign in to comment.