Exemple #1
0
def main():
    create_loggers()
    log.info('Dummy XML Encoder')

    tt = bindings.tt(sequenceIdentifier='testSequence001',
                     sequenceNumber='1',
                     timeBase='smpte',
                     lang='en-GB',
                     head=bindings.head_type(
                         metadata.headMetadata_type(
                             metadata.documentMetadata()),
                         bindings.styling(bindings.style(id='ID001')),
                         bindings.layout()),
                     body=BIND(
                         bindings.div_type(
                             bindings.p_type(
                                 bindings.span_type('Some example text...'),
                                 bindings.br_type(),
                                 bindings.span_type('And another line'),
                                 id='ID005',
                                 begin='00:00:00:50',
                                 end='00:00:03:24',
                             ))))

    print(
        tt.toDOM(bds=BindingDOMSupport(
            default_namespace=bindings.Namespace)).toprettyxml(indent='  '))
    log.info('XML output printed')
    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
    def process_document(self, document):

        activation_time = self._reference_clock.get_time() + timedelta(seconds=1)

        if self._input_blocks:
            try:
                lines = self._input_blocks.next()
            except StopIteration:
                raise EndOfData(END_OF_DATA)
        else:
            lines = [LimitedClockTimingType(activation_time)]

        document = self._document_sequence.new_document()

        # Add default style
        document.binding.head.styling = styling(
            style_type(
                id='defaultStyle1',
                backgroundColor="rgb(0, 0, 0)",
                color="rgb(255, 255, 255)",
                linePadding="0.5c",
                fontFamily="sansSerif"
            )
        )
        document.binding.head.layout = layout(
            region_type(
                id='bottomRegion',
                origin='14.375% 60%',
                extent='71.25% 24%',
                displayAlign='after',
                writingMode='lrtb',
                overflow="visible"
            )
        )
        document.add_div(
            self._create_fragment(
                lines,
                'defaultStyle1'
            ),
        )

        document.set_dur(LimitedClockTimingType(timedelta(seconds=1)))
        document.set_begin(LimitedClockTimingType(activation_time))

        document.validate()

        self._carriage_impl.emit_document(document)
def main():
    create_loggers()
    log.info('Dummy XML Encoder')

    tt = bindings.tt(
        sequenceIdentifier='testSequence001',
        sequenceNumber='1',
        timeBase='smpte',
        lang='en-GB',
        head=bindings.head_type(
            metadata.headMetadata_type(
                metadata.documentMetadata()
            ),
            bindings.styling(
                bindings.style(
                    id='ID001'
                )
            ),
            bindings.layout()
        ),
        body=BIND(
            bindings.div_type(
                bindings.p_type(
                    bindings.span_type(
                        'Some example text...'
                    ),
                    bindings.br_type(),
                    bindings.span_type(
                        'And another line'
                    ),
                    id='ID005',
                    begin='00:00:00:50',
                    end='00:00:03:24',
                )
            )
        )
    )

    print(
        tt.toDOM(
            bds=BindingDOMSupport(default_namespace=bindings.Namespace)
        ).toprettyxml(
            indent='  '
        )
    )
    log.info('XML output printed')
def main():
    create_loggers()
    log.info('Dummy XML Encoder')

    tt = bindings.tt(
        sequenceIdentifier='testSequence001',
        sequenceNumber='1',
        timeBase='clock',
        clockMode='local',
        lang='en-GB',
        head=bindings.head_type(
            metadata.headMetadata_type(
                metadata.documentMetadata()
            ),
            bindings.styling(
                bindings.style(
                    id='ID001'
                )
            ),
            bindings.layout()
        ),
        body=BIND(
            bindings.div_type(
                bindings.p_type(
                    bindings.span_type(
                        'Some example text...'
                    ),
                    bindings.br_type(),
                    bindings.span_type(
                        'And another line'
                    ),
                    id='ID005',
                    begin=timedelta(seconds=.5),
                    end=timedelta(seconds=3.42),
                )
            ),
            begin=timedelta(seconds=.5),
            dur=timedelta(seconds=5)
        )
    )

    print(
        tt.toxml()
    )

    log.info('XML output printed')
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")
Exemple #7
0
class TestReplaceStylesAndRegions(TestCase):

    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='SEQ58.defaultStyle1',
                                fontSize='12px',
                                color='rgb(255,255,255)',
                                backgroundColor='rgb(0,0,0)',
                                fontFamily='sansSerif'),
            bindings.style_type(id='SEQ59.defaultStyle1',
                                fontSize='12px',
                                color='rgb(255,255,255)',
                                backgroundColor='rgb(0,0,0)',
                                fontFamily='sansSerif'),
            bindings.style_type(id='SEQ60.defaultStyle1',
                                fontSize='12px',
                                color='rgb(0,255,255)',
                                backgroundColor='rgb(0,0,0)',
                                fontFamily='sansSerif'),
            bindings.style_type(id='SEQ61.defaultStyle1',
                                fontSize='12px',
                                color='rgb(255,255,255)',
                                backgroundColor='rgb(0,0,0)',
                                fontFamily='sansSerif')),
        bindings.layout(
            bindings.region_type(id='SEQ58.bottomRegion1',
                                 origin='14.375% 60%',
                                 extent='71.25% 24%',
                                 style=['SEQ58.defaultStyle1']),
            bindings.region_type(id='SEQ59.bottomRegion1',
                                 origin='14.375% 60%',
                                 extent='71.25% 24%',
                                 style=['SEQ58.defaultStyle1']),
            bindings.region_type(id='SEQ60.bottomRegion1',
                                 origin='14.375% 60%',
                                 extent='71.25% 24%',
                                 style=['SEQ58.defaultStyle1']),
            bindings.region_type(id='SEQ61.bottomRegion1',
                                 origin='14.375% 60%',
                                 extent='71.25% 24%',
                                 style=['SEQ58.defaultStyle1'])))
    body_elem = bindings.body_type(
        bindings.div_type(bindings.p_type(
            bindings.span_type('Some example text...',
                               style=['SEQ58.defaultStyle1'],
                               id='span1'),
            bindings.br_type(),
            bindings.span_type('And another line',
                               style=['SEQ58.defaultStyle1'],
                               id='span2'),
            id='ID005'),
                          region='SEQ58.bottomRegion1'),
        bindings.div_type(bindings.p_type(
            bindings.span_type('Another example text...',
                               style=['SEQ59.defaultStyle1'],
                               id='span3'),
            bindings.br_type(),
            bindings.span_type('And another line',
                               style=['SEQ59.defaultStyle1'],
                               id='span4'),
            id='ID006'),
                          region='SEQ59.bottomRegion1'),
        bindings.div_type(bindings.p_type(
            bindings.span_type('More example text...',
                               style=['SEQ60.defaultStyle1'],
                               id='span5'),
            bindings.br_type(),
            bindings.span_type('And another line',
                               style=['SEQ60.defaultStyle1'],
                               id='span6'),
            id='ID007'),
                          region='SEQ60.bottomRegion1'),
        bindings.div_type(bindings.p_type(
            bindings.span_type('Further example text...',
                               style=['SEQ61.defaultStyle1'],
                               id='span7'),
            bindings.br_type(),
            bindings.span_type('And another line',
                               style=['SEQ61.defaultStyle1'],
                               id='span8'),
            id='ID008'),
                          region='SEQ61.bottomRegion1'),
    )

    tt.head = head_elem
    tt.body = body_elem

    test_old_ids = ({
        'SEQ58.defaultStyle1': 1,
        'SEQ59.defaultStyle1': 2,
        'SEQ60.defaultStyle1': 3,
        'SEQ61.defaultStyle1': 4,
        'SEQ58.bottomRegion1': 5,
        'SEQ59.bottomRegion1': 6,
        'SEQ60.bottomRegion1': 7,
        'SEQ61.bottomRegion1': 8
    })
    test_new_ids = ({
        1: 'SEQ61.defaultStyle1',
        3: 'SEQ60.defaultStyle1',
        5: 'SEQ61.bottomRegion1'
    })

    replaceStylesAndRegions = deduplicator.ReplaceStylesAndRegions

    def test_one(self):
        document = EBUTT3Document.create_from_raw_binding(binding=self.tt)
        document.validate()

        cdoc = self.replaceStylesAndRegions(document, self.test_old_ids,
                                            self.test_new_ids)
        cdoc.proceed()

        document.validate()

        print document.get_xml()
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=.5)),
        dur=datatypes.LimitedClockTimingType(timedelta(seconds=5)),
        style=['style2'])

    applied_proc1 = metadata.appliedProcessing_type(
        process='Creation',
        generatedBy='ebu_dummy_encoder',
        appliedDateTime=datetime.now())

    applied_proc2 = metadata.appliedProcessing_type(
        process='Validation',
        generatedBy='ebu_dummy_encoder',
        appliedDateTime=datetime.now())

    head_elem.metadata.documentMetadata.appliedProcessing.append(applied_proc1)
    head_elem.metadata.documentMetadata.appliedProcessing.append(applied_proc2)
    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)