How to use the pycaption.exceptions.CaptionReadSyntaxError 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 / tests / test_dfxp.py View on Github external
def test_caption_error_for_invalid_or_unsupported_positioning_units(self):
        invalid_dfxp = (
            SAMPLE_DFXP_INVALID_POSITIONING_VALUE_TEMPLATE
            .format(origin="6foo 7bar")
        )
        self.assertRaises(
            CaptionReadSyntaxError, DFXPReader().read,
            invalid_dfxp
        )
github pbs / pycaption / pycaption / scc / state_machines.py View on Github external
def get_current_position(self):
        """Returns the currently tracked positioning, the last positioning that
        was set (anywhere), or the default it was initiated with

        :rtype: tuple[int]
        """
        try:
            return (
                super(DefaultProvidingPositionTracker, self).
                get_current_position()
            )
        except CaptionReadSyntaxError:
            return self.default
github pbs / pycaption / pycaption / webvtt.py View on Github external
def _parse_timestamp(self, timestamp):
        """Returns an integer representing a number of microseconds
        :rtype: int
        """
        m = TIMESTAMP_PATTERN.search(timestamp)
        if not m:
            raise CaptionReadSyntaxError(
                'Invalid timing format.')

        m = m.groups()

        if m[2]:
            # Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
            return microseconds(m[0], m[1], m[2].replace(":", ""), m[3])
        else:
            # Timestamp takes the form of [minutes]:[seconds].[milliseconds]
            return microseconds(0, m[0], m[1], m[3])
github pbs / pycaption / pycaption / webvtt.py View on Github external
def _validate_timings(self, start, end, last_start_time):
        if start is None:
            raise CaptionReadSyntaxError(
                'Invalid cue start timestamp.')
        if end is None:
            raise CaptionReadSyntaxError('Invalid cue end timestamp.')
        if start > end:
            raise CaptionReadError(
                'End timestamp is not greater than start timestamp.')
        if start < last_start_time:
            raise CaptionReadError(
                'Start timestamp is not greater than or equal'
                'to start timestamp of previous cue.')
github pbs / pycaption / pycaption / dfxp / base.py View on Github external
if not styling_tag:
            return result

        reference = style.get('style')

        if reference:
            referenced_styles = styling_tag.findChildren(
                'style', {'xml:id': reference}
            )

            if len(referenced_styles) == 1:
                return result + cls._get_style_reference_chain(
                    referenced_styles[0], styling_tag
                )
            elif len(referenced_styles) > 1:
                raise CaptionReadSyntaxError(
                    "Invalid caption file. "
                    "More than 1 style with 'xml:id': {id}"
                    .format(id=reference)
                )

        return result
github pbs / pycaption / pycaption / sami.py View on Github external
def feed(self, data):
        """
        :param data: Raw SAMI unicode string
        :returns: tuple (unicode, dict, set)
        """
        no_cc = 'no closed captioning available'

        if '")

            self.styles = self._css_parse(
                BeautifulSoup(data[:index], "lxml").find('style').get_text())
        except AttributeError:
            self.styles = {}

        # fix erroneous italics tags
        data = data.replace('<i>', '<i>')

        # fix awkward tags found in some SAMIs
        data = data.replace(';&gt;', '&gt;')</i></i>
github pbs / pycaption / pycaption / webvtt.py View on Github external
if '-->' in line:
                found_timing = True
                timing_line = i
                last_start_time = captions[-1].start if captions else 0
                try:
                    start, end, layout_info = self._parse_timing_line(
                        line, last_start_time)
                except CaptionReadError as e:
                    new_message = '%s (line %d)' % (e.args[0], timing_line)
                    six.reraise(type(e), type(e)(new_message), sys.exc_info()[2])

            elif '' == line:
                if found_timing:
                    if not nodes:
                        raise CaptionReadSyntaxError(
                            'Cue without content. (line %d)' % timing_line)
                    else:
                        found_timing = False
                        caption = Caption(
                            start, end, nodes, layout_info=layout_info)
                        captions.append(caption)
                        nodes = []
            else:
                if found_timing:
                    if nodes:
                        nodes.append(CaptionNode.create_break())
                    nodes.append(CaptionNode.create_text(
                        self._decode(line)))
                else:
                    # it's a comment or some metadata; ignore it
                    pass
github pbs / pycaption / pycaption / sami.py View on Github external
def feed(self, data):
        """
        :param data: Raw SAMI unicode string
        :returns: tuple (unicode, dict, set)
        """
        no_cc = 'no closed captioning available'

        if '")

            self.styles = self._css_parse(
                BeautifulSoup(data[:index], "lxml").find('style').get_text())
        except AttributeError:
            self.styles = {}

        # fix erroneous italics tags
        data = data.replace('<i>', '<i>')</i></i>