Repository: pbs/pycaption

Issue:
SCC file content error
I tried to read a SCC file and print the content, the content looks repetitive

(Client's Voice)\nRemember that degree\nyou got in taxation?
(Client's Voice)\nRemember that degree\nyou got in taxation?
(Client's Voice)\nRemember that degree\nyou got in taxation?
(Client's Voice)\nRemember that degree\nyou got in taxation?
(Client's Voice)\nRemember that degree\nyou got in taxation?
(Client's Voice)\nRemember that degree\nyou got in taxation?
(Client's Voice)\nRemember that degree\nyou got in taxation?


[TV1_HC47974.txt](https://github.com/pbs/pycaption/files/2863380/TV1_HC47974.txt)

Could you please let me know the issue.


Comments:

Patch:
diff --git a/README.rst b/README.rst
index ffbcc1c..3fbd233 100644
--- a/README.rst
+++ b/README.rst
@@ -14,6 +14,10 @@ For details, see the `documentation <http://pycaption.readthedocs.org>`__.
 
 Changelog
 ---------
+1.0.7
+^^^^^
+- Fixed issue with SCC paint-on buffer not being cleared after storing
+
 1.0.6
 ^^^^^
 - Added MicroDVD format
diff --git a/pycaption/scc/__init__.py b/pycaption/scc/__init__.py
index 5e11e83..493a36b 100644
--- a/pycaption/scc/__init__.py
+++ b/pycaption/scc/__init__.py
@@ -285,6 +285,8 @@ class SCCReader(BaseReader):
             if not self.buffer_dict['paint'].is_empty():
                 self.caption_stash.create_and_store(
                     self.buffer_dict['paint'], self.time)
+                self.buffer_dict['paint'] = \
+                    self.node_creator_factory.new_creator()
 
     def _translate_line(self, line):
         # ignore blank lines
@@ -415,10 +417,9 @@ class SCCReader(BaseReader):
             if not self.buffer.is_empty():
                 self._roll_up()
 
-        # clear screen
+        # 942c - Erase Displayed Memory - Clear the current screen of any
+        # displayed captions or text.
         elif word == '942c':
-            self.roll_rows = []
-
             # XXX - The 942c command has nothing to do with paint-ons
             # This however is legacy code, and will break lots of tests if
             # the proper buffer (self.buffer) is used.
@@ -427,13 +428,11 @@ class SCCReader(BaseReader):
             if not self.buffer_dict['paint'].is_empty():
                 self.caption_stash.create_and_store(
                     self.buffer_dict['paint'], self.time)
-                self.buffer = self.node_creator_factory.new_creator()
-
-            # attempt to add proper end time to last caption(s)
+                self.buffer_dict['paint'] = \
+                    self.node_creator_factory.new_creator()
             self.caption_stash.correct_last_timing(
                 self.time_translator.get_time())
-
-        # if command not one of the aforementioned, add to buffer
+        # If command is not one of the aforementioned, add it to buffer
         else:
             self.buffer.interpret_command(word)
 
diff --git a/setup.py b/setup.py
index dbd59ce..7eae904 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@ dependencies = [
 
 setup(
     name='pycaption',
-    version='1.0.6',
+    version='1.0.7',
     description='Closed caption converter',
     long_description=open(README_PATH).read(),
     author='Joe Norton',


Test patch:
diff --git a/tests/samples/scc.py b/tests/samples/scc.py
index b2f3ac2..27c4946 100644
--- a/tests/samples/scc.py
+++ b/tests/samples/scc.py
@@ -293,3 +293,24 @@ Scenarist_SCC V1.0
 
 00:04:36;06	 9420 9420 9152 9152 cdc1 4a4f 5220 46d5 cec4 49ce c720 d052 4fd6 49c4 45c4 20c2 d980 2026
 """
+
+SAMPLE_SCC_MULTIPLE_FORMATS = """\
+Scenarist_SCC V1.0 
+
+00:00:00;00	942c 1c2c 
+
+00:00:00;08	9429 9152 97a2 a843 ece9 e56e f4a7 7320 d6ef e9e3 e529 91f2 97a2 52e5 6de5 6d62 e5f2 20f4 6861 f420 64e5 67f2 e5e5 9252 97a2 79ef 7520 67ef f420 e96e 20f4 61f8 61f4 e9ef 6ebf 9420 9152 97a2 a8c4 616e 6e79 2980 91f2 97a2 4fe6 20e3 ef75 f273 e520 79ef 7520 64ef 6ea7 f480 9252 97a2 62e5 e361 7573 e520 79ef 7520 64e9 646e a7f4 a180 
+
+00:00:02;15	9420 942c 942f 9420 91d0 9723 d9ef 75f2 20ea ef62 20e9 736e a7f4 2064 efe9 6e67 2068 61f2 6480 9170 9723 f7ef f26b aeae ae80 
+
+00:00:04;15	9420 942c 942f 9420 91d0 97a2 aeae aee9 f4a7 7320 6d61 6be9 6e67 20f4 68e5 6d20 64ef 2068 61f2 6480 9170 97a2 f7ef f26b aeae ae80 
+
+00:00:06;03	9420 942c 942f 9420 91d0 97a2 aeae ae61 6e64 2067 e5f4 f4e9 6e67 2070 61e9 6420 e6ef f220 e9f4 ae80 
+
+00:00:08;04	9420 942c 942f 9420 91d0 97a1 a8d6 4f29 9170 97a1 d36e 6170 2061 6e64 2073 eff2 f420 79ef 75f2 20e5 f870 e56e 73e5 7320 f4ef 92d0 97a1 7361 76e5 20ef 76e5 f220 a434 2cb6 b0b0 2061 f420 f461 f820 f4e9 6de5 ae80 
+
+00:00:09;18	9420 942c 942f 9420 9152 51d5 4943 cbc2 4f4f cbd3 ae20 c2c1 43cb 49ce c720 d94f d5ae 
+
+00:00:13;04	9420 942c 942f 
+
+"""
\ No newline at end of file
diff --git a/tests/test_scc.py b/tests/test_scc.py
index 0abbae7..23084fb 100644
--- a/tests/test_scc.py
+++ b/tests/test_scc.py
@@ -5,7 +5,7 @@ from pycaption.geometry import UnitEnum, HorizontalAlignmentEnum, VerticalAlignm
 from pycaption.scc.specialized_collections import (InstructionNodeCreator,
                                                    TimingCorrectingCaptionList)
 
-from pycaption import SCCReader, CaptionReadNoCaptions
+from pycaption import SCCReader, CaptionReadNoCaptions, CaptionNode
 from pycaption.scc.state_machines import DefaultProvidingPositionTracker
 
 from tests.samples.scc import (
@@ -14,7 +14,7 @@ from tests.samples.scc import (
     SAMPLE_SCC_WITH_ITALICS, SAMPLE_SCC_EMPTY, SAMPLE_SCC_ROLL_UP_RU2,
     SAMPLE_SCC_PRODUCES_BAD_LAST_END_TIME, SAMPLE_NO_POSITIONING_AT_ALL_SCC,
     SAMPLE_SCC_NO_EXPLICIT_END_TO_LAST_CAPTION, SAMPLE_SCC_EOC_FIRST_COMMAND,
-    SAMPLE_SCC_WITH_EXTENDED_CHARACTERS
+    SAMPLE_SCC_WITH_EXTENDED_CHARACTERS, SAMPLE_SCC_MULTIPLE_FORMATS
 )
 
 TOLERANCE_MICROSECONDS = 500 * 1000
@@ -203,6 +203,35 @@ class CoverageOnlyTestCase(unittest.TestCase):
                           '>> Bike Iowa, your source for']
         self.assertEqual(expected_texts, actual_texts)
 
+    def test_multiple_formats(self):
+        # Test for captions that contain both pop on and paint on formats to
+        # ensure the paint on lines are not repeated
+        expected_text_lines = [
+            "(Client's Voice)",
+            'Remember that degree',
+            'you got in taxation?',
+            '(Danny)',
+            "Of course you don't",
+            "because you didn't!",
+            "Your job isn't doing hard",
+            'work...',
+            "...it's making them do hard",
+            'work...',
+            '...and getting paid for it.',
+            '(VO)',
+            'Snap and sort your expenses to',
+            'save over $4,600 at tax time.',
+            'QUICKBOOKS. BACKING YOU.']
+
+        captions = SCCReader().read(SAMPLE_SCC_MULTIPLE_FORMATS)\
+            .get_captions('en-US')
+        text_lines = [node.content
+                      for caption in captions
+                      for node in caption.nodes
+                      if node.type_ == CaptionNode.TEXT]
+
+        self.assertEqual(expected_text_lines, text_lines)
+
     def test_freeze_semicolon_spec_time(self):
         scc1 = SCCReader().read(SAMPLE_SCC_ROLL_UP_RU2)
         captions = scc1.get_captions('en-US')