How to use the pysubs2.SSAEvent function in pysubs2

To help you get started, we’ve selected a few pysubs2 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 tkarabela / pysubs2 / tests / test_ssafile.py View on Github external
def prepare():
        subs.events = [SSAEvent(style="red"), SSAEvent(style="unrelated")]
        subs.styles = dict(red=red, green=green)
github tkarabela / pysubs2 / tests / test_substation.py View on Github external
def build_ref():
    subs = SSAFile()
    subs.info["My Custom Info"] = "Some: Test, String."
    subs.styles["left"] = SSAStyle(alignment=7, bold=True)
    subs.styles["topleft"] = SSAStyle(alignment=4)
    subs.append(SSAEvent(start=0, end=make_time(m=1), text="An, example, subtitle."))
    subs.append(SSAEvent(start=0, end=make_time(m=1), type="Comment", text="You can't see this one."))
    subs.append(SSAEvent(start=make_time(m=1), end=make_time(m=2), text="Subtitle number\\Ntwo."))
    return subs
github tkarabela / pysubs2 / tests / test_ssaevent.py View on Github external
def test_shift():
    e = SSAEvent(start=0, end=10)

    with assert_raises(ValueError):
        e.shift(frames=5)

    with assert_raises(ValueError):
        e.shift(fps=23.976)

    with assert_raises(ValueError):
        e.shift(frames=5, fps=-1)

    e2 = e.copy(); e2.shift(ms=5)
    assert e2 == SSAEvent(start=5, end=15)

    e2 = e.copy(); e2.shift(ms=-5)
    assert e2 == SSAEvent(start=-5, end=5)
github tkarabela / pysubs2 / tests / test_ssafile.py View on Github external
subs = SSAFile()
    subs.append(SSAEvent(start=0, end=10))
    subs.append(SSAEvent(start=1000, end=1010))

    with assert_raises(ValueError):
        subs.transform_framerate(1, 0)
    with assert_raises(ValueError):
        subs.transform_framerate(1, -1)
    with assert_raises(ValueError):
        subs.transform_framerate(0, 1)
    with assert_raises(ValueError):
        subs.transform_framerate(-1, 1)

    subs.transform_framerate(10, 20)
    assert subs[0] == SSAEvent(start=0, end=5)
    assert subs[1] == SSAEvent(start=500, end=505)
github tkarabela / pysubs2 / tests / test_ssaevent.py View on Github external
def test_duration():
    e = SSAEvent(start=0, end=10)
    assert e.duration == 10

    e.duration = 20
    assert e.start == 0 and e.end == 20

    e.duration = 5
    assert e.start == 0 and e.end == 5

    e.duration = 0
    assert e.start == 0 and e.end == 0

    with assert_raises(ValueError):
        e.duration = -20
github tkarabela / pysubs2 / tests / test_ssafile.py View on Github external
def test_transform_framerate():
    subs = SSAFile()
    subs.append(SSAEvent(start=0, end=10))
    subs.append(SSAEvent(start=1000, end=1010))

    with assert_raises(ValueError):
        subs.transform_framerate(1, 0)
    with assert_raises(ValueError):
        subs.transform_framerate(1, -1)
    with assert_raises(ValueError):
        subs.transform_framerate(0, 1)
    with assert_raises(ValueError):
        subs.transform_framerate(-1, 1)

    subs.transform_framerate(10, 20)
    assert subs[0] == SSAEvent(start=0, end=5)
    assert subs[1] == SSAEvent(start=500, end=505)
github tkarabela / pysubs2 / tests / test_subrip.py View on Github external
def test_simple_write():
    subs = SSAFile()

    e1 = SSAEvent()
    e1.start = 0
    e1.end = 60000
    e1.text = "An example subtitle."

    e2 = SSAEvent()
    e2.start = 60000
    e2.end = 120000
    e2.text = "Subtitle number\\Ntwo."

    e3 = SSAEvent()
    e3.start = 60000
    e3.end = 120000
    e3.text = "Invisible subtitle."
    e3.is_comment = True

    subs.append(e1)
    subs.append(e2)
    subs.append(e3)

    ref = dedent("""\
    1
github tkarabela / pysubs2 / tests / test_ssafile.py View on Github external
def test_repr_simple():
    subs = SSAFile()
    subs.append(SSAEvent(start=make_time(m=5), end=make_time(m=6)))
    subs.append(SSAEvent(start=make_time(m=125), end=make_time(m=126)))
    subs.append(SSAEvent(start=make_time(m=15), end=make_time(m=16)))
    subs.styles["style1"] = SSAStyle()
    subs.styles["style2"] = SSAStyle()
    ref = ""
    assert repr(subs) == ref
github tkarabela / pysubs2 / tests / test_subrip.py View on Github external
def test_simple_read():
    text = dedent("""\
    1
    00:00:00,000 --> 00:01:00,000
    An example subtitle.

    2
    00:01:00,000 --> 00:02:00,000
    Subtitle number
    two.
    """)

    ref = SSAFile()
    ref.append(SSAEvent(start=0, end=make_time(m=1), text="An example subtitle."))
    ref.append(SSAEvent(start=make_time(m=1), end=make_time(m=2), text="Subtitle number\\Ntwo."))

    subs = SSAFile.from_string(text)
    assert subs.equals(ref)