Exemplo n.º 1
0
    def _create_test_document(self):
        doc = EBUTT3Document(time_base='clock',
                             clock_mode='local',
                             lang='en-GB',
                             sequence_identifier='testSequenceEncoder01',
                             sequence_number='1')

        head_elem = bindings.head_type(
            metadata.headMetadata_type(metadata.documentMetadata()),
            bindings.styling(
                bindings.style_type(id='style1', fontSize='12px'),
                bindings.style_type(id='style2', fontSize='15px'),
                bindings.style_type(id='style3', color='red', fontSize='12px'),
                bindings.style_type(id='style4', backgroundColor='blue')),
            bindings.layout(
                bindings.region_type(id='region1',
                                     origin='200px 450px',
                                     extent='300px 150px',
                                     style=['style3'])))

        body_elem = bindings.body_type(bindings.div_type(bindings.p_type(
            bindings.span_type('Some example text...',
                               begin=datatypes.LimitedClockTimingType(
                                   timedelta(hours=11, minutes=32, seconds=1)),
                               end=datatypes.LimitedClockTimingType(
                                   timedelta(hours=11, minutes=32, seconds=2)),
                               style=['style4'],
                               id='span1'),
            bindings.br_type(),
            bindings.span_type('And another line',
                               begin=datatypes.LimitedClockTimingType(
                                   timedelta(hours=11, minutes=32, seconds=3)),
                               end=datatypes.LimitedClockTimingType(
                                   timedelta(hours=11, minutes=32, seconds=4)),
                               id='span2'),
            id='ID005',
        ),
                                                         style=['style1'],
                                                         region='region1'),
                                       begin=datatypes.LimitedClockTimingType(
                                           timedelta(hours=11,
                                                     minutes=32,
                                                     seconds=.5)),
                                       dur=datatypes.LimitedClockTimingType(
                                           timedelta(hours=11,
                                                     minutes=32,
                                                     seconds=5)),
                                       style=['style2'])

        doc.binding.head = head_elem
        doc.binding.body = body_elem
        doc.binding.extent = '800px 600px'
        doc.validate()
        raw_xml = doc.get_xml()
        doc = EBUTT3Document.create_from_xml(raw_xml)
        return doc
Exemplo n.º 2
0
def main():
    create_loggers(logging.INFO)
    log.info("Dummy XML Encoder")

    tt = bindings.tt(
        sequenceIdentifier="testSequence001",
        sequenceNumber="1",
        timeBase="clock",
        extent="800px 600px",
        clockMode="local",
        lang="en-GB",
    )

    head_elem = bindings.head_type(
        metadata.headMetadata_type(metadata.documentMetadata()),
        bindings.styling(
            bindings.style_type(id="style1", fontSize="12px"),
            bindings.style_type(id="style2", fontSize="15px"),
            bindings.style_type(id="style3", color="red", fontSize="12px"),
            bindings.style_type(id="style4", backgroundColor="blue"),
        ),
        bindings.layout(
            bindings.region_type(id="region1", origin="200px 450px", extent="300px 150px", style=["style3"])
        ),
    )

    body_elem = bindings.body_type(
        bindings.div_type(
            bindings.p_type(
                bindings.span_type(
                    "Some example text...",
                    begin=datatypes.LimitedClockTimingType(timedelta(seconds=1)),
                    end=datatypes.LimitedClockTimingType(timedelta(seconds=2)),
                    style=["style4"],
                    id="span1",
                ),
                bindings.br_type(),
                bindings.span_type(
                    "And another line",
                    begin=datatypes.LimitedClockTimingType(timedelta(seconds=3)),
                    end=datatypes.LimitedClockTimingType(timedelta(seconds=4)),
                    id="span2",
                ),
                id="ID005",
            ),
            style=["style1"],
            region="region1",
        ),
        begin=datatypes.LimitedClockTimingType(timedelta(seconds=0.5)),
        dur=datatypes.LimitedClockTimingType(timedelta(seconds=5)),
        style=["style2"],
    )

    tt.head = head_elem
    tt.body = body_elem

    document = EBUTT3Document.create_from_raw_binding(tt)

    document.validate()

    print(document.get_xml())

    log.info("XML output printed")
    def test_trimmed_1(self):
        tt = bindings.tt(
            sequenceIdentifier='testSequence001',
            sequenceNumber='1',
            timeBase='clock',
            extent='800px 600px',
            clockMode='local',
            lang='en-GB'
        )
        head_elem = bindings.head_type(
            metadata.headMetadata_type(
                metadata.documentMetadata()
            ),
            bindings.styling(
                bindings.style_type(
                    id='style1',
                    fontSize='12px'
                ),
                bindings.style_type(
                    id='style2',
                    fontSize='15px'
                ),
                bindings.style_type(
                    id='style3',
                    color='red',
                    fontSize='12px'
                ),
                bindings.style_type(
                    id='style4',
                    backgroundColor='blue'
                )
            ),
            bindings.layout(
                bindings.region_type(
                    id='region1',
                    origin='200px 450px',
                    extent='300px 150px',
                    style=['style3']
                )
            )
        )
        body_elem = bindings.body_type(
            bindings.div_type(
                bindings.p_type(
                    bindings.span_type(
                        'Some example text...',
                        begin=datatypes.LimitedClockTimingType(timedelta(seconds=1)),
                        end=datatypes.LimitedClockTimingType(timedelta(seconds=2)),
                        style=['style4'],
                        id='span1'
                    ),
                    bindings.br_type(),
                    bindings.span_type(
                        'And another line',
                        begin=datatypes.LimitedClockTimingType(timedelta(seconds=3)),
                        end=datatypes.LimitedClockTimingType(timedelta(seconds=4)),
                        id='span2'
                    ),
                    id='ID005'
                ),
                style=['style1'],
                region='region1'
            ),
            begin=datatypes.LimitedClockTimingType(timedelta(seconds=.5)),
            dur=datatypes.LimitedClockTimingType(timedelta(seconds=5)),
            style=['style2']
        )
        tt.head = head_elem
        tt.body = body_elem

        document = EBUTT3Document.create_from_raw_binding(binding=tt)
        document.validate()

        self.assertIsInstance(document.get_element_by_id('region1'), bindings.region_type)
        self.assertIsInstance(document.get_element_by_id('style1'), bindings.style_type)
        self.assertIsInstance(document.get_element_by_id('style2'), bindings.style_type)
        self.assertIsInstance(document.get_element_by_id('style3'), bindings.style_type)
        self.assertIsInstance(document.get_element_by_id('style4'), bindings.style_type)

        self.assertIsInstance(document.get_element_by_id('ID005'), bindings.p_type)
        self.assertIsInstance(document.get_element_by_id('span1'), bindings.span_type)
        self.assertIsInstance(document.get_element_by_id('span2'), bindings.span_type)

        cdoc = document.extract_segment(deconflict_ids=True, begin=timedelta(seconds=2.5))
        self.assertIsInstance(cdoc.get_element_by_id('SEQ1.region1'), bindings.region_type)
        self.assertIsInstance(cdoc.get_element_by_id('SEQ1.style1'), bindings.style_type)
        self.assertIsInstance(cdoc.get_element_by_id('SEQ1.style2'), bindings.style_type)
        self.assertIsInstance(cdoc.get_element_by_id('SEQ1.style3'), bindings.style_type)
        self.assertRaises(LookupError, cdoc.get_element_by_id, 'SEQ1.style4')

        self.assertIsInstance(cdoc.get_element_by_id('SEQ1.ID005'), bindings.p_type)
        self.assertRaises(LookupError, cdoc.get_element_by_id, 'SEQ1.span1')
        self.assertIsInstance(cdoc.get_element_by_id('SEQ1.span2'), bindings.span_type)
    def test_simple(self):
        tt = bindings.tt(
            sequenceIdentifier='testSequence001',
            sequenceNumber='1',
            timeBase='clock',
            extent='800px 600px',
            clockMode='local',
            lang='en-GB'
        )
        head_elem = bindings.head_type(
            metadata.headMetadata_type(
                metadata.documentMetadata()
            ),
            bindings.styling(
                bindings.style_type(
                    id='style1',
                    fontSize='12px'
                ),
                bindings.style_type(
                    id='style2',
                    fontSize='15px'
                ),
                bindings.style_type(
                    id='style3',
                    color='red',
                    fontSize='12px'
                )
            ),
            bindings.layout(
                bindings.region_type(
                    id='region1',
                    origin='200px 450px',
                    extent='300px 150px',
                    style=['style3']
                )
            )
        )
        body_elem = bindings.body_type(
            bindings.div_type(
                bindings.p_type(
                    bindings.span_type(
                        'Some example text...'
                    ),
                    bindings.br_type(),
                    bindings.span_type(
                        'And another line'
                    ),
                    id='ID005',
                    begin=datatypes.LimitedClockTimingType(timedelta(seconds=.5)),
                    end=datatypes.LimitedClockTimingType(timedelta(seconds=3.42)),
                ),
                style=['style1'],
                region='region1'
            ),
            begin=datatypes.LimitedClockTimingType(timedelta(seconds=.5)),
            dur=datatypes.LimitedClockTimingType(timedelta(seconds=5)),
            style=['style2']
        )

        tt.head = head_elem
        tt.body = body_elem

        document = EBUTT3Document.create_from_raw_binding(binding=tt)
        document.validate()

        document.extract_segment(deconflict_ids=True)