def test_self_generate(self):
        parsed_subs1 = utils.get_subs("simple.dfxp")
        parsed_subs2 = DFXPParser(
            DFXPGenerator(parsed_subs1.subtitle_set, 'en').__unicode__())

        for x1, x2 in zip([x for x in parsed_subs1.to_internal()],
                          [x for x in parsed_subs2.to_internal()]):
            self.assertEquals(x1, x2)
Example #2
0
    def test_merge_with_header(self):
        initial_ttml = etree.fromstring("""\
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling">
    <head>
        <styling>
            <style xml:id="style" tts:color="foo" tts:fontSize="bar" />
        </styling>

        <layout>
            <region xml:id="region" style="style" tts:extent="foo" tts:origin="bar" />
        </layout>
    </head>
    <body />
</tt>""")

        result = DFXPGenerator.merge_subtitles(
            [self.en_subs, self.es_subs, self.fr_subs],
            initial_ttml=initial_ttml)

        utils.assert_long_text_equal(result, """\
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="">
    <head>
        <styling>
            <style xml:id="style" tts:color="foo" tts:fontSize="bar"/>
        </styling>
        <layout>
            <region xml:id="region" style="style" tts:extent="foo" tts:origin="bar"/>
        </layout>
    </head>
    <body>
        <div xml:lang="en">
            <div>
                <p begin="00:00:01.000" end="00:00:01.500">content</p>
            </div>
        </div>
        <div xml:lang="es">
            <div>
                <p begin="00:00:01.000" end="00:00:01.500">spanish content</p>
            </div>
            <div>
                <p begin="00:00:02.000" end="00:00:02.500">spanish content 2</p>
            </div>
        </div>
        <div xml:lang="fr">
            <div>
                <p begin="00:00:01.000" end="00:00:01.500">french content</p>
            </div>
        </div>
    </body>
</tt>
""")
Example #3
0
    def test_unsynced_generator(self):
        subs = SubtitleSet('en')
        for x in xrange(0,5):
            subs.append_subtitle(None, None,"%s" % x)
        output = unicode(DFXPGenerator(subs))

        parsed = DFXPParser(output, 'en')
        internal = parsed.to_internal()

        subs = [x for x in internal.subtitle_items()]
        self.assertEqual(len(internal), 5)
        for i,sub in enumerate(subs):
            self.assertIsNone(sub[0])
            self.assertIsNone(sub[1])
            self.assertEqual(sub[2], str(i))

        for node in internal.get_subtitles():
            self.assertIsNone(get_attr(node, 'begin'))
            self.assertIsNone(get_attr(node, 'end'))
Example #4
0
    def test_dfxp_merge(self):
        result = DFXPGenerator.merge_subtitles(
            [self.en_subs, self.es_subs, self.fr_subs])

        utils.assert_long_text_equal(result, """\
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="">
    <head>
        <metadata xmlns:ttm="http://www.w3.org/ns/ttml#metadata">
            <ttm:title/>
            <ttm:description/>
            <ttm:copyright/>
        </metadata>
        <styling xmlns:tts="http://www.w3.org/ns/ttml#styling">
            <style xml:id="amara-style" tts:color="white" tts:fontFamily="proportionalSansSerif" tts:fontSize="18px" tts:textAlign="center"/>
        </styling>
        <layout xmlns:tts="http://www.w3.org/ns/ttml#styling">
            <region xml:id="amara-subtitle-area" style="amara-style" tts:extent="560px 62px" tts:padding="5px 3px" tts:backgroundColor="black" tts:displayAlign="after"/>
        </layout>
    </head>
    <body region="amara-subtitle-area">
        <div xml:lang="en">
            <div>
                <p begin="00:00:01.000" end="00:00:01.500">content</p>
            </div>
        </div>
        <div xml:lang="es">
            <div>
                <p begin="00:00:01.000" end="00:00:01.500">spanish content</p>
            </div>
            <div>
                <p begin="00:00:02.000" end="00:00:02.500">spanish content 2</p>
            </div>
        </div>
        <div xml:lang="fr">
            <div>
                <p begin="00:00:01.000" end="00:00:01.500">french content</p>
            </div>
        </div>
    </body>
</tt>
""")
Example #5
0
 def dfxp_merge(self, subtitle_sets):
     """Create a merged DFXP file from a list of subtitle sets."""
     initial_ttml = self._empty_ttml('', '', '')
     return DFXPGenerator.merge_subtitles(subtitle_sets, initial_ttml)
Example #6
0
 def dfxp_merge(self, subtitle_sets):
     """Create a merged DFXP file from a list of subtitle sets."""
     initial_ttml = self._empty_ttml('', '', '')
     return DFXPGenerator.merge_subtitles(subtitle_sets, initial_ttml)