How to use the aeidon.as_seconds function in aeidon

To help you get started, we’ve selected a few aeidon 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 otsaloma / gaupol / aeidon / calculator.py View on Github external
Round `pos` to given precision in decimal digits.

        `ndigits` may be negative. For frames zero will be used
        if given `ndigits` is greater than zero.
        """
        if aeidon.is_time(pos):
            pos = self.time_to_seconds(pos)
            pos = round(pos, ndigits)
            return self.seconds_to_time(pos)
        if aeidon.is_frame(pos):
            ndigits = min(0, ndigits)
            pos = round(pos, ndigits)
            return aeidon.as_frame(pos)
        if aeidon.is_seconds(pos):
            pos = round(pos, ndigits)
            return aeidon.as_seconds(pos)
        raise ValueError("Invalid type for pos: {!r}"
                         .format(type(pos)))
github otsaloma / gaupol / aeidon / subtitle.py View on Github external
def duration_seconds(self, value):
        """Set duration from `value`."""
        self.duration = aeidon.as_seconds(value)
github otsaloma / gaupol / aeidon / calculator.py View on Github external
def frame_to_seconds(self, frame):
        """Convert `frame` to seconds."""
        return aeidon.as_seconds(frame / self._framerate)
github otsaloma / gaupol / gaupol / dialogs / speech_recognition.py View on Github external
def _append_subtitle(self, index):
        """Create subtitle from `index` and append to page."""
        if index < 0:
            index += len(self._starts)
        advance = gaupol.conf.speech_recognition.advance_length
        advance = aeidon.as_seconds(advance/1000) # ms to s
        subtitle = aeidon.Subtitle(mode=aeidon.modes.TIME)
        start = self._starts[index] - advance
        start = max(start, self._stops[index-1] if index > 0 else 0.0)
        subtitle.start = aeidon.as_seconds(start)
        subtitle.end = aeidon.as_seconds(self._stops[index])
        subtitle.main_text = self._texts[index] or ("[{:d}]".format(index+1))
        indices = (len(self._page.project.subtitles),)
        self._page.project.insert_subtitles(indices,
                                            (subtitle,),
                                            register=None)
github otsaloma / gaupol / aeidon / subtitle.py View on Github external
def start_seconds(self, value):
        """Set start position from `value`."""
        self.start = aeidon.as_seconds(value)
github otsaloma / gaupol / gaupol / dialogs / speech_recognition.py View on Github external
def _append_subtitle(self, index):
        """Create subtitle from `index` and append to page."""
        if index < 0:
            index += len(self._starts)
        advance = gaupol.conf.speech_recognition.advance_length
        advance = aeidon.as_seconds(advance/1000) # ms to s
        subtitle = aeidon.Subtitle(mode=aeidon.modes.TIME)
        start = self._starts[index] - advance
        start = max(start, self._stops[index-1] if index > 0 else 0.0)
        subtitle.start = aeidon.as_seconds(start)
        subtitle.end = aeidon.as_seconds(self._stops[index])
        subtitle.main_text = self._texts[index] or ("[{:d}]".format(index+1))
        indices = (len(self._page.project.subtitles),)
        self._page.project.insert_subtitles(indices,
                                            (subtitle,),
                                            register=None)
github otsaloma / gaupol / aeidon / files / mpsub.py View on Github external
def read(self):
        """
        Read file and return subtitles.

        Raise :exc:`IOError` if reading fails.
        Raise :exc:`UnicodeError` if decoding fails.
        """
        subtitles = []
        lines = self._read_lines()
        self._read_header(lines)
        convert = (aeidon.as_seconds
                   if self.mode == aeidon.modes.TIME
                   else aeidon.as_frame)

        end = convert("0")
        for line in lines:
            match = self._re_position_line.match(line)
            if match is None:
                if subtitles[-1].main_text:
                    subtitles[-1].main_text += "\n"
                subtitles[-1].main_text += line
                continue
            subtitle = self._get_subtitle()
            start = end + convert(match.group(1))
            end = start + convert(match.group(2))
            subtitle.start = start
            subtitle.end = end
github otsaloma / gaupol / gaupol / dialogs / speech_recognition.py View on Github external
def _append_subtitle(self, index):
        """Create subtitle from `index` and append to page."""
        if index < 0:
            index += len(self._starts)
        advance = gaupol.conf.speech_recognition.advance_length
        advance = aeidon.as_seconds(advance/1000) # ms to s
        subtitle = aeidon.Subtitle(mode=aeidon.modes.TIME)
        start = self._starts[index] - advance
        start = max(start, self._stops[index-1] if index > 0 else 0.0)
        subtitle.start = aeidon.as_seconds(start)
        subtitle.end = aeidon.as_seconds(self._stops[index])
        subtitle.main_text = self._texts[index] or ("[{:d}]".format(index+1))
        indices = (len(self._page.project.subtitles),)
        self._page.project.insert_subtitles(indices,
                                            (subtitle,),
                                            register=None)
github otsaloma / gaupol / aeidon / subtitle.py View on Github external
def end_seconds(self, value):
        """Set end position from `value`."""
        self.end = aeidon.as_seconds(value)