How to use the pycaption.base.CaptionNode function in pycaption

To help you get started, we’ve selected a few pycaption examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pbs / pycaption / pycaption / srt.py View on Github external
if not lines[start_line].isdigit():
                break

            end_line = self._find_text_line(start_line, lines)

            timing = lines[start_line + 1].split('-->')
            start = self._srttomicro(timing[0].strip(' \r\n'))
            end = self._srttomicro(timing[1].strip(' \r\n'))

            nodes = []

            for line in lines[start_line + 2:end_line - 1]:
                # skip extra blank lines
                if not nodes or line != '':
                    nodes.append(CaptionNode.create_text(line))
                    nodes.append(CaptionNode.create_break())

            if len(nodes):
                # remove last line break from end of caption list
                nodes.pop()
                caption = Caption(start, end, nodes)
                captions.append(caption)

            start_line = end_line

        caption_set = CaptionSet({lang: captions})

        if caption_set.is_empty():
            raise CaptionReadNoCaptions("empty caption file")

        return caption_set
github pbs / pycaption / pycaption / transcript.py View on Github external
def _strip_text(self, elements, lang_transcript):
        for el in elements:
            if el.type_ == CaptionNode.TEXT:
                lang_transcript += el.content
        return lang_transcript
github pbs / pycaption / pycaption / dfxp / base.py View on Github external
def _recreate_text(self, caption, dfxp, caption_set=None, lang=None):
        line = ''

        for node in caption.nodes:
            if node.type_ == CaptionNode.TEXT:
                line += self._encode(node.content)

            elif node.type_ == CaptionNode.BREAK:
                line = line.rstrip() + '<br>\n    '

            elif node.type_ == CaptionNode.STYLE:
                line = self._recreate_span(
                    line, node, dfxp, caption_set, caption, lang)

        return line.rstrip()
github pbs / pycaption / pycaption / dfxp / base.py View on Github external
pattern = re.compile("^(?:[\n\r]+\s*)?(.+)")
            result = pattern.search(tag)
            if result:
                # Escaping/unescaping xml entities is the responsibility of the
                # xml parser used by BeautifulSoup in its initialization. The
                # content of the tag variable at this point should be a plain
                # unicode string with xml entities already converted to unicode
                # characters.
                tag_text = result.groups()[0]
                node = CaptionNode.create_text(
                    tag_text, layout_info=tag.layout_info)
                self.nodes.append(node)
        # convert line breaks
        elif tag.name == 'br':
            self.nodes.append(
                CaptionNode.create_break(layout_info=tag.layout_info))
        # convert italics
        elif tag.name == 'span':
            # convert span
            self._translate_span(tag)
        else:
            # recursively call function for any children elements
            for a in tag.contents:
                self._translate_tag(a)
github pbs / pycaption / pycaption / base.py View on Github external
def create_break(layout_info=None):
        return CaptionNode(CaptionNode.BREAK, layout_info=layout_info)