pycaption 2.2.4__tar.gz → 2.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {pycaption-2.2.4/pycaption.egg-info → pycaption-2.2.5}/PKG-INFO +1 -1
  2. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/scc/__init__.py +33 -19
  3. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/scc/constants.py +2 -0
  4. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/scc/specialized_collections.py +4 -4
  5. {pycaption-2.2.4 → pycaption-2.2.5/pycaption.egg-info}/PKG-INFO +1 -1
  6. {pycaption-2.2.4 → pycaption-2.2.5}/setup.py +1 -1
  7. {pycaption-2.2.4 → pycaption-2.2.5}/tests/conftest.py +2 -0
  8. {pycaption-2.2.4 → pycaption-2.2.5}/tests/fixtures/dfxp.py +2 -2
  9. {pycaption-2.2.4 → pycaption-2.2.5}/tests/fixtures/scc.py +28 -1
  10. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_scc.py +35 -4
  11. {pycaption-2.2.4 → pycaption-2.2.5}/LICENSE +0 -0
  12. {pycaption-2.2.4 → pycaption-2.2.5}/MANIFEST.in +0 -0
  13. {pycaption-2.2.4 → pycaption-2.2.5}/README.rst +0 -0
  14. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/__init__.py +0 -0
  15. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/base.py +0 -0
  16. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/dfxp/__init__.py +0 -0
  17. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/dfxp/base.py +0 -0
  18. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/dfxp/extras.py +0 -0
  19. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/english.pickle +0 -0
  20. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/exceptions.py +0 -0
  21. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/geometry.py +0 -0
  22. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/microdvd.py +0 -0
  23. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/sami.py +0 -0
  24. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/scc/state_machines.py +0 -0
  25. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/scc/translator.py +0 -0
  26. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/srt.py +0 -0
  27. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/transcript.py +0 -0
  28. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/utils.py +0 -0
  29. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption/webvtt.py +0 -0
  30. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption.egg-info/SOURCES.txt +0 -0
  31. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption.egg-info/dependency_links.txt +0 -0
  32. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption.egg-info/requires.txt +0 -0
  33. {pycaption-2.2.4 → pycaption-2.2.5}/pycaption.egg-info/top_level.txt +0 -0
  34. {pycaption-2.2.4 → pycaption-2.2.5}/setup.cfg +0 -0
  35. {pycaption-2.2.4 → pycaption-2.2.5}/tests/__init__.py +0 -0
  36. {pycaption-2.2.4 → pycaption-2.2.5}/tests/fixtures/__init__.py +0 -0
  37. {pycaption-2.2.4 → pycaption-2.2.5}/tests/fixtures/microdvd.py +0 -0
  38. {pycaption-2.2.4 → pycaption-2.2.5}/tests/fixtures/sami.py +0 -0
  39. {pycaption-2.2.4 → pycaption-2.2.5}/tests/fixtures/srt.py +0 -0
  40. {pycaption-2.2.4 → pycaption-2.2.5}/tests/fixtures/translated_scc.py +0 -0
  41. {pycaption-2.2.4 → pycaption-2.2.5}/tests/fixtures/webvtt.py +0 -0
  42. {pycaption-2.2.4 → pycaption-2.2.5}/tests/mixins.py +0 -0
  43. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_base.py +0 -0
  44. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_dfxp.py +0 -0
  45. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_dfxp_conversion.py +0 -0
  46. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_dfxp_extras.py +0 -0
  47. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_functions.py +0 -0
  48. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_geometry.py +0 -0
  49. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_microdvd.py +0 -0
  50. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_microdvd_conversion.py +0 -0
  51. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_sami.py +0 -0
  52. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_sami_conversion.py +0 -0
  53. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_scc_conversion.py +0 -0
  54. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_scc_translator.py +0 -0
  55. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_srt.py +0 -0
  56. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_srt_conversion.py +0 -0
  57. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_webvtt.py +0 -0
  58. {pycaption-2.2.4 → pycaption-2.2.5}/tests/test_webvtt_conversion.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycaption
3
- Version: 2.2.4
3
+ Version: 2.2.5
4
4
  Summary: Closed caption converter
5
5
  Author: Joe Norton
6
6
  Author-email: joey@nortoncrew.com
@@ -301,21 +301,27 @@ class SCCReader(BaseReader):
301
301
  self.time_translator.start_at(parts[0][0])
302
302
 
303
303
  # loop through each word
304
- for word in parts[0][2].split(' '):
305
- # ignore empty results or invalid commands
306
- word = word.strip()
307
- if len(word) == 4:
308
- self._translate_word(word)
309
-
310
- def _translate_word(self, word):
311
- if self._handle_double_command(word):
304
+ words = [word.strip() for word in parts[0][2].split(' ') if len(word) == 4]
305
+
306
+ for idx, word in enumerate(words):
307
+ self._translate_word(word, words, idx)
308
+
309
+ @staticmethod
310
+ def get_command(commands, idx):
311
+ try:
312
+ return commands[idx]
313
+ except IndexError:
314
+ return None
315
+
316
+ def _translate_word(self, word, words, idx):
317
+ if self._skip_double_command(word, words, idx):
312
318
  # count frames for timing
313
319
  self.time_translator.increment_frames()
314
320
  return
315
321
  # first check if word is a command
316
322
  # TODO - check that all the positioning commands are here, or use
317
323
  # some other strategy to determine if the word is a command.
318
- if word in COMMANDS or _is_pac_command(word):
324
+ if word in COMMANDS or _is_pac_command(word) or word in PAC_TAB_OFFSET_COMMANDS:
319
325
  self._translate_command(word)
320
326
 
321
327
  # second, check if word is a special character
@@ -332,31 +338,39 @@ class SCCReader(BaseReader):
332
338
  # count frames for timing only after processing a command
333
339
  self.time_translator.increment_frames()
334
340
 
335
- def _handle_double_command(self, word):
341
+ def _skip_double_command(self, word, words, idx):
336
342
  # If the caption is to be broadcast, each of the commands are doubled
337
343
  # up for redundancy in case the signal is garbled in transmission.
338
344
  # The decoder is programmed to ignore a second command when it is the
339
345
  # same as the first.
340
346
  # Also like codes, Special Characters are always doubled up,
341
347
  # with only one member of each pair being displayed.
348
+ next_command = self.get_command(words, idx + 1)
349
+ second_next = self.get_command(words, idx + 2)
350
+
342
351
  if word in COMMANDS or _is_pac_command(word) or word in SPECIAL_CHARS or word in EXTENDED_CHARS:
343
- if word == self.last_command:
352
+ # skip duplicates, execute the last occurrence if not a positioning command
353
+ if word == self.last_command and not _is_pac_command(word):
344
354
  self.last_command = ''
345
355
  return True
346
- # Fix for the <position> <tab offset> <position> <tab offset>
347
- # repetition
348
- elif _is_pac_command(word) and word in self.last_command:
356
+ # skip consecutive positioning commands, execute the last one
357
+ elif _is_pac_command(word) and _is_pac_command(next_command):
349
358
  self.last_command = ''
350
359
  return True
360
+ # Fix for the <position> <tab offset> <position> <tab offset> repetition
361
+ # execute the last positioning command
362
+ elif _is_pac_command(word) and next_command in PAC_TAB_OFFSET_COMMANDS and _is_pac_command(second_next):
363
+ self.last_command = ''
364
+ return True
365
+ # execute offset commands only if previous command is PAC and next is not PAC
351
366
  elif word in PAC_TAB_OFFSET_COMMANDS:
352
- if _is_pac_command(self.last_command):
353
- self.last_command += f" {word}"
367
+ if _is_pac_command(self.last_command) and not _is_pac_command(next_command):
368
+ self.last_command = word
354
369
  return False
355
370
  else:
356
371
  return True
357
-
358
- self.last_command = word
359
- return False
372
+ self.last_command = word
373
+ return False
360
374
 
361
375
  def _translate_special_char(self, word):
362
376
  self.buffer.add_chars(SPECIAL_CHARS[word])
@@ -987,6 +987,8 @@ MICROSECONDS_PER_CODEWORD = 1000.0 * 1000.0 / (30.0 * 1000.0 / 1001.0)
987
987
 
988
988
  HEADER = 'Scenarist_SCC V1.0'
989
989
 
990
+ UNHANDLED_COMMANDS = ["9120", "91ae", "912f", "91a1"]
991
+
990
992
  # taken from
991
993
  # http://www.theneitherworld.com/mcpoodle/SCC_TOOLS/DOCS/CC_CHARS.HTML
992
994
  INCONVERTIBLE_TO_ASCII_EXTENDED_CHARS_ASSOCIATION = {
@@ -8,7 +8,8 @@ from ..geometry import (
8
8
  )
9
9
  from .constants import (
10
10
  PAC_BYTES_TO_POSITIONING_MAP, COMMANDS, PAC_TAB_OFFSET_COMMANDS,
11
- MICROSECONDS_PER_CODEWORD, INCONVERTIBLE_TO_ASCII_EXTENDED_CHARS_ASSOCIATION
11
+ MICROSECONDS_PER_CODEWORD, UNHANDLED_COMMANDS,
12
+ INCONVERTIBLE_TO_ASCII_EXTENDED_CHARS_ASSOCIATION
12
13
  )
13
14
 
14
15
  PopOnCue = collections.namedtuple("PopOnCue", "buffer, start, end")
@@ -342,10 +343,9 @@ class InstructionNodeCreator:
342
343
 
343
344
  :type command: str
344
345
  """
345
- self._update_positioning(command)
346
-
346
+ if command not in UNHANDLED_COMMANDS:
347
+ self._update_positioning(command)
347
348
  text = COMMANDS.get(command, '')
348
-
349
349
  if 'italic' in text:
350
350
  if 'end' not in text:
351
351
  self._collection.append(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycaption
3
- Version: 2.2.4
3
+ Version: 2.2.5
4
4
  Summary: Closed caption converter
5
5
  Author: Joe Norton
6
6
  Author-email: joey@nortoncrew.com
@@ -24,7 +24,7 @@ transcript_dependencies = [
24
24
 
25
25
  setup(
26
26
  name='pycaption',
27
- version='2.2.4',
27
+ version='2.2.5',
28
28
  description='Closed caption converter',
29
29
  long_description=open(README_PATH).read(),
30
30
  author='Joe Norton',
@@ -61,6 +61,8 @@ from tests.fixtures.scc import ( # noqa: F401
61
61
  sample_scc_duplicate_tab_offset, sample_scc_duplicate_special_characters,
62
62
  sample_scc_tab_offset, sample_scc_with_unknown_commands,
63
63
  sample_scc_special_and_extended_characters,
64
+ sample_scc_with_consecutive_pac_commands,
65
+ sample_scc_special_and_extended_characters,
64
66
  sample_scc_with_line_too_long
65
67
  )
66
68
  from tests.fixtures.srt import ( # noqa: F401
@@ -920,10 +920,10 @@ def sample_dfxp_from_scc_output():
920
920
  <region tts:displayAlign="before" tts:origin="40% 53%" tts:textAlign="left" xml:id="r5"/>
921
921
  <region tts:displayAlign="before" tts:origin="70% 17%" tts:textAlign="left" xml:id="r6"/>
922
922
  <region tts:displayAlign="before" tts:origin="20% 35%" tts:textAlign="left" xml:id="r7"/>
923
- <region tts:displayAlign="before" tts:origin="20% 83%" tts:textAlign="left" xml:id="r8"/>
923
+ <region tts:displayAlign="before" tts:origin="25% 83%" tts:textAlign="left" xml:id="r8"/>
924
924
  <region tts:displayAlign="before" tts:origin="70% 11%" tts:textAlign="left" xml:id="r9"/>
925
925
  <region tts:displayAlign="before" tts:origin="40% 41%" tts:textAlign="left" xml:id="r10"/>
926
- <region tts:displayAlign="before" tts:origin="20% 71%" tts:textAlign="left" xml:id="r11"/>
926
+ <region tts:displayAlign="before" tts:origin="25% 71%" tts:textAlign="left" xml:id="r11"/>
927
927
  </layout>
928
928
  </head>
929
929
  <body>
@@ -24,6 +24,33 @@ Scenarist_SCC V1.0
24
24
  """
25
25
 
26
26
 
27
+ @pytest.fixture(scope="session")
28
+ def sample_scc_with_consecutive_pac_commands():
29
+ return """\
30
+ Scenarist_SCC V1.0
31
+
32
+ 00:00:00;15 942c
33
+
34
+ 00:11:45;10 9420 94d0 94ce 5b20 cec1 5252 c154 4f52 205d 9470 946e cd4f cecb 45d9 d320 4c4f d645 2054 c849 cec7 d320 54c8 c154 2046 4cd9 ae80 942c 8080 8080 942f
35
+
36
+ 00:11:47;28 9420 9454 9723 d9c1 d9a1 94f4 9723 5b20 c84f 4f54 49ce c720 5d80 942c 8080 8080 942f
37
+
38
+ 00:11:50;08 9420 94d0 94ce 45d3 d045 4349 c14c 4cd9 2049 4620 54c8 45d9 a752 4520 54c8 4520 4fce 45d3 9470 946e 57c8 4f20 c745 5420 544f 2046 4cd9 2054 c845 cdae 942c 8080 8080 942f
39
+
40
+ 00:11:54;06 942c
41
+
42
+ 00:23:00;13 9420 1370 136e 5b20 43c8 494c c420 5d80 94d0 94ce c745 4f52 c745 20cd c1c4 4520 c120 cdc1 43c8 49ce 4580 9470 946e 464f 5220 c84f 5749 4520 544f 942c 8080 8080 942f
43
+
44
+ 00:23:02;04 9420 91d0 91ce 544f 2046 49ce c420 43d5 5249 4fd5 d320 c745 4f52 c745 9170 916e c1ce c420 c849 d320 4652 4945 cec4 d380 92d0 92ce 45d6 4552 d920 c4c1 d920 4fce 4c49 ce45 2c80 942c 8080 8080 942f
45
+
46
+ 00:23:05;00 9420 9152 91ae d357 49ce c720 c2d9 20d0 c2d3 cb49 c4d3 ae4f 52c7 9170 916e 544f 20d0 4cc1 d920 46d5 ce20 c7c1 cd45 d320 c1ce c420 57c1 5443 c880 92d0 9723 91ae d94f d552 2046 c1d6 4f52 4954 4520 d649 c445 4fd3 ae80 942c 8080 8080 942f
47
+
48
+
49
+ 00:23:05;00 9420 9152 91ae d357 49ce c720 c2d9 20d0 c2d3 cb49 c4d3 ae4f 52c7 9170 916e 544f 20d0 4cc1 d920 46d5 ce20 c7c1 cd45 d320 c1ce c420 57c1 5443 c880 92d0 9723 91ae d94f d552 2046 c1d6 4f52 4954 4520 d649 c445 4fd3 ae80 942c 8080 8080 942f
50
+
51
+ """
52
+
53
+
27
54
  @pytest.fixture(scope="session")
28
55
  def scc_that_generates_webvtt_with_proper_newlines():
29
56
  return """\
@@ -435,7 +462,7 @@ Scenarist_SCC V1.0
435
462
 
436
463
  00:00:00;03 942c
437
464
 
438
- 00:00:01;45 9420 91f4 cb45 4c4c d920 4ac1 cd45 d3ba 20c8 eff7 9254 f468 e520 7368 eff7 2073 f461 f2f4 e564 942c 8080 8080 942f
465
+ 00:00:01;45 9420 91f4 cb45 4c4c d920 4ac1 cd45 d3ba 20c8 eff7 9254 f468 e520 7368 eff7d3ba 20c8 eff7 9254 f468 e520 7368 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 eff7 2073 f461 f2f4 e564 942c 8080 8080 942f
439
466
 
440
467
  00:00:02;55 9420 91e0 9723 f761 7320 4361 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 ec20 c4e5 6ee9 73ef 6e2c 2061 20e6 f2e9 e56e 6480 9240 9723 efe6 20ef 75f2 732c 20f7 6173 2064 efe9 6e67 206d 7920 43c4 73ae 942c 8080 8080 942f
441
468
 
@@ -77,10 +77,10 @@ class TestSCCReader(ReaderTestingMixIn):
77
77
  ((40.0, UnitEnum.PERCENT), (53.0, UnitEnum.PERCENT)),
78
78
  ((70.0, UnitEnum.PERCENT), (17.0, UnitEnum.PERCENT)),
79
79
  ((20.0, UnitEnum.PERCENT), (35.0, UnitEnum.PERCENT)),
80
- ((20.0, UnitEnum.PERCENT), (83.0, UnitEnum.PERCENT)),
80
+ ((25.0, UnitEnum.PERCENT), (83.0, UnitEnum.PERCENT)),
81
81
  ((70.0, UnitEnum.PERCENT), (11.0, UnitEnum.PERCENT)),
82
82
  ((40.0, UnitEnum.PERCENT), (41.0, UnitEnum.PERCENT)),
83
- ((20.0, UnitEnum.PERCENT), (71.0, UnitEnum.PERCENT))
83
+ ((25.0, UnitEnum.PERCENT), (71.0, UnitEnum.PERCENT))
84
84
  ]
85
85
 
86
86
  actual_positioning = [
@@ -244,6 +244,38 @@ class TestSCCReader(ReaderTestingMixIn):
244
244
  assert exc_info.value.args[0].startswith(
245
245
  "Unsupported cue duration around 00:00:20.433")
246
246
 
247
+ def test_skip_first_pac_command(self, sample_scc_with_consecutive_pac_commands):
248
+ caption_set = SCCReader().read(sample_scc_with_consecutive_pac_commands)
249
+ caption = caption_set.get_captions('en-US')
250
+ actual_lines = [
251
+ node.content
252
+ for cap_ in caption
253
+ for node in cap_.nodes
254
+ if node.type_ == CaptionNode.TEXT
255
+ ]
256
+ expected_lines = [
257
+ '[ NARRATOR ]',
258
+ 'MONKEYS LOVE THINGS THAT FLY.',
259
+ 'YAY!',
260
+ '[ HOOTING ]',
261
+ "ESPECIALLY IF THEY'RE THE ONES",
262
+ 'WHO GET TO FLY THEM.',
263
+ '[ CHILD ]',
264
+ 'GEORGE MADE A MACHINE',
265
+ 'FOR HOWIE TO',
266
+ 'TO FIND CURIOUS GEORGE',
267
+ 'AND HIS FRIENDS',
268
+ 'EVERY DAY ONLINE,',
269
+ 'SWING BY PBSKIDS.ORG',
270
+ 'TO PLAY FUN GAMES AND WATCH',
271
+ 'YOUR FAVORITE VIDEOS.',
272
+ 'SWING BY PBSKIDS.ORG',
273
+ 'TO PLAY FUN GAMES AND WATCH',
274
+ 'YOUR FAVORITE VIDEOS.'
275
+ ]
276
+ # is not breaking the lines
277
+ assert expected_lines == actual_lines
278
+
247
279
  def test_line_too_long(self, sample_scc_with_line_too_long):
248
280
  with pytest.raises(CaptionLineLengthError) as exc_info:
249
281
  SCCReader().read(sample_scc_with_line_too_long)
@@ -345,7 +377,6 @@ class TestCoverageOnly:
345
377
  ]
346
378
 
347
379
  actual_timings = [(c_.start, c_.end) for c_ in captions]
348
-
349
380
  assert expected_timings == actual_timings
350
381
 
351
382
  def test_freeze_colon_spec_time(self, sample_scc_pop_on):
@@ -584,4 +615,4 @@ class TestTimingCorrectingCaptionList:
584
615
  # just one caption, first EOC disappears
585
616
  num_captions = len(caption_set.get_captions('en-US'))
586
617
 
587
- assert num_captions == 2
618
+ assert num_captions == 1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes