Ejemplo n.º 1
0
    def test_parser_string_representation_except_for_timedeltas_doesnt_change_after_tick(self):
        subtitle_string = """2
00:01:04,788 --> 00:01:10,192
Take a lock of his hair back to Korea."""
        parser = StringParser(subtitle_string)
        parser.parse()
        parser.uptick(timedelta(seconds=5))
        
        expected = """2
00:01:09,788 --> 00:01:15,192
Take a lock of his hair back to Korea."""
        self.assertEquals(expected, str(parser))
Ejemplo n.º 2
0
class StringParserCanManipulateTimeDeltas(unittest.TestCase):
    
    def setUp(self):
        self.subtitle_string = """2
00:01:04,788 --> 00:01:10,192
Take a lock of his hair back to Korea.

3
00:01:13,464 --> 00:01:17,696
Fear not, l will take this to your family.

4
00:01:25,809 --> 00:01:27,333
AD 1 3 75-The first year of the King WOO,
Korean Dynasty."""
        self.parser = StringParser(self.subtitle_string)
        self.parser.parse()

    def test_parser_advance_by_seconds(self):
        self.parser.uptick(timedelta(seconds=5))
        
        self.assertEqual(SubtitleDelta(timedelta(minutes=1, seconds=9, milliseconds=788),
                                       timedelta(minutes=1, seconds=15, milliseconds=192)),
                         self.parser.lines[1])
        
        self.assertEqual(SubtitleDelta(timedelta(minutes=1, seconds=18, milliseconds=464),
                                       timedelta(minutes=1, seconds=22, milliseconds=696)),
                         self.parser.lines[5])
        
        self.assertEqual(SubtitleDelta(timedelta(minutes=1, seconds=30, milliseconds=809),
                                       timedelta(minutes=1, seconds=32, milliseconds=333)),
                         self.parser.lines[9])
        

    def test_parser_decline_by_seconds(self):
        self.parser.downtick(timedelta(seconds=5))
        self.assertEqual(SubtitleDelta(timedelta(minutes=1, seconds=20, milliseconds=809),
                                       timedelta(minutes=1, seconds=22, milliseconds=333)),
                         self.parser.lines[9])
Ejemplo n.º 3
0
"""
Created on Oct 20, 2012

@author: igor
"""
from lib.parser import StringParser
from datetime import timedelta

if __name__ == "__main__":
    f = open("/tmp/meow.srt", "r")
    string = f.read()
    f.close()

    p = StringParser(string)
    p.parse()
    p.uptick(timedelta(seconds=1))
    f = open("/tmp/meow.srt", "w")
    f.write(str(p))
    f.close()