Ejemplo n.º 1
0
def parse_shift_string(shift_string):
    try:
        if ':' in shift_string:
            negator = 1
            if shift_string.startswith('-'):
                negator = -1
                shift_string = shift_string[1:]
            parts = list(map(float, shift_string.split(':')))
            if len(parts) > 3:
                raise PrassError(
                    "Invalid shift value: '{0}'".format(shift_string))
            shift_seconds = sum(
                part * multiplier
                for part, multiplier in zip(reversed(parts), (1.0, 60.0,
                                                              3600.0)))
            return shift_seconds * 1000 * negator  # convert to ms
        else:
            if shift_string.endswith("ms"):
                return float(shift_string[:-2])
            elif shift_string.endswith("s"):
                return float(shift_string[:-1]) * 1000
            else:
                return float(shift_string) * 1000
    except ValueError:
        raise PrassError("Invalid shift value: '{0}'".format(shift_string))
Ejemplo n.º 2
0
 def swell(s):
     sf = common.map(s, 0, 1, 1280, 1440) / 1440
     gd.cmd_loadidentity()
     gd.cmd_translate(640, 360)
     gd.cmd_scale(sf, sf)
     gd.cmd_translate(-1440 / 2, -810 / 2)
     gd.cmd_setmatrix()
Ejemplo n.º 3
0
def parse_srt_time(string):
    m = re.match(r"(\d+):(\d+):(\d+)\,(\d+)", string)
    if m != None:
        groups = m.groups()
        hours, minutes, seconds, milliseconds = list(map(int, groups))
        return hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds
    else:
        raise PrassError(
            "____\nFailed to parse ass time in the following line:\n{0}\n____".
            format(string))
    return None
Ejemplo n.º 4
0
    def draw(self):
        gd = self.gd

        gd.finish()

        if 1:
            v = 0x808f
            gd.cmd_regwrite(gd3.REG_GPIOX, v | (1 << 12))
            print(hex(gd.rd32(gd3.REG_GPIOX)))

        gd.Begin(gd3.BITMAPS)

        def swell(s):
            sf = common.map(s, 0, 1, 1280, 1440) / 1440
            gd.cmd_loadidentity()
            gd.cmd_translate(640, 360)
            gd.cmd_scale(sf, sf)
            gd.cmd_translate(-1440 / 2, -810 / 2)
            gd.cmd_setmatrix()

        t = self.t
        o = int(
            max(common.map(t, 80, 90, 255, 0), common.map(t, 160, 170, 0,
                                                          255)))
        gd.BitmapHandle(0)
        gd.BlendFunc(gd3.SRC_ALPHA, 0)
        gd.ColorA(o)
        if t < 90:
            swell(common.map(t, 0, 90))
        else:
            swell(common.map(t, 160, 250))
        gd.Vertex2f(0, 0)

        if 1:
            o = int(
                min(common.map(t, 80, 90, 0, 255),
                    common.map(t, 160, 170, 255, 0)))
            gd.BitmapHandle(1)
            gd.BlendFunc(gd3.SRC_ALPHA, 1)
            gd.ColorA(o)
            swell(common.map(t, 80, 80 + 90))
            gd.Vertex2f(0, 0)

        gd.RestoreContext()
        # gd.cmd_number(0, 0, 29, 3, t)

        self.t += 1
        self.t %= 250
        assert self.t < 250
Ejemplo n.º 5
0
def parse_shift_string(shift_string):
    try:
        if ':' in shift_string:
            negator = 1
            if shift_string.startswith('-'):
                negator = -1
                shift_string = shift_string[1:]
            parts = list(map(float, shift_string.split(':')))
            if len(parts) > 3:
                raise PrassError("Invalid shift value: '{0}'".format(shift_string))
            shift_seconds = sum(part * multiplier for part, multiplier in zip(reversed(parts), (1.0, 60.0, 3600.0)))
            return shift_seconds * 1000 * negator  # convert to ms
        else:
            if shift_string.endswith("ms"):
                return float(shift_string[:-2])
            elif shift_string.endswith("s"):
                return float(shift_string[:-1]) * 1000
            else:
                return float(shift_string) * 1000
    except ValueError:
        raise PrassError("Invalid shift value: '{0}'".format(shift_string))
Ejemplo n.º 6
0
def srt_line_to_ass(line, box=False):
    line = line.replace('\n', r'\N')
    if '<' in line:
        for tag in ['i', 'b', 'u', 's']:
            line = line.replace('<%s>' % tag, '{\\%s1}' % tag)
            line = line.replace('</%s>' % tag, '{\\%s0}' % tag)
        while '<font color="' in line:
            pre, color, post = re.match(r'(.*)\<font color="(.*?)"\>(.*)',
                                        line).groups()
            if color.startswith('#'):
                r, g, b = color[1:3], color[3:5], color[5:]
            elif webcolors:
                r, g, b = map(lambda x: "%02X" % x,
                              webcolors.name_to_rgb(color))
            else:
                logging.warning(
                    'Can\'t parse color "%s", please install webcolors module.'
                    % color)
                break
            line = pre + '{\c&H%s%s%s&}' % (b, g, r) + post
        line = line.replace('</font>', '{\c&HFFFFFF&}')
    return line
Ejemplo n.º 7
0
def parse_srt_time(string):
    hours, minutes, seconds, milliseconds = map(int, re.match(r"(\d+):(\d+):(\d+)\,(\d+)", string).groups())
    return hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds
Ejemplo n.º 8
0
def parse_ass_time(string):
    hours, minutes, seconds, centiseconds = map(int, re.match(r"(\d+):(\d+):(\d+)\.(\d+)", string).groups())
    return hours * 3600000 + minutes * 60000 + seconds * 1000 + centiseconds * 10
Ejemplo n.º 9
0
def parse_srt_time(string):
    hours, minutes, seconds, milliseconds = map(
        int,
        re.match(r"(\d+):(\d+):(\d+)\,(\d+)", string).groups())
    return hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds
Ejemplo n.º 10
0
def parse_ass_time(string):
    hours, minutes, seconds, centiseconds = map(
        int,
        re.match(r"(\d+):(\d+):(\d+)\.(\d+)", string).groups())
    return hours * 3600000 + minutes * 60000 + seconds * 1000 + centiseconds * 10