Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(prog='SrtModPy',\
            description='Just adjusts the timing of subtitle files')
    parser.add_argument('file', help='the subtitle to be modified')
    parser.add_argument('time_amount', type=float,\
           help='the amount of time to be added or subtracted to subtitle')
    parser.add_argument('-t',\
           help='it\'s the part of time to be modified', choices=['S', 'M'], default='S')
    parser.add_argument('-o',\
           help='add or discount time to subtitle', choices=['A', 'D'], default='A')
    arg = parser.parse_args()

    time_amount = arg.time_amount
    file_ = arg.file
    time_part = arg.t
    operation = arg.o
    try:
        srt = SrtMod(file_, time_amount, time_part, operation)
        if srt.process():
			print 'subtitle file was created successfully'
			print 'file saved at: ' + os.path.splitext(file_)[0] +'(modified).srt'
        else:
            print '\nsubtitle can not be processed'
    except OverflowError:
        print 'Exception: Invalid time amount for this operation'
Exemplo n.º 2
0
 def test_file_cannot_be_processed(self):
     srt = SrtMod('lalala.srt', 1, 'm', 'd')
     result = srt.process()
     self.assertFalse(result)
Exemplo n.º 3
0
 def test_file_can_be_processed(self):
     srt = SrtMod('sub.srt', 1, 's', 'a')
     result = srt.process()
     self.assertTrue(result)
Exemplo n.º 4
0
 def test_correct_file_extension(self):
     srt = SrtMod('lalala.srt')
     result = srt.check_file_extension()
     self.assertTrue(result)
Exemplo n.º 5
0
 def test_decrement_one_minute_to_time_line(self):
     srt = SrtMod('sub.srt', 1, 'm', 'D')
     line = '00:15:03,000 --> 00:16:04,992'
     mod = srt.mod_line(line)
     self.assertEqual('00:14:03,000 --> 00:15:04,992\n', mod)
Exemplo n.º 6
0
 def test_decrement_ten_seconds_to_time_line(self):
     srt = SrtMod('sub.srt', 10, 's', 'd')
     line = '00:00:13,000 --> 00:00:14,992'
     mod = srt.mod_line(line)
     self.assertEqual('00:00:03,000 --> 00:00:04,992\n', mod)
Exemplo n.º 7
0
 def test_increment_fiften_seconds_to_time_line(self):
     srt = SrtMod('sub.srt', 15, 's')
     line = '00:00:03,000 --> 00:00:04,992'
     mod = srt.mod_line(line)
     self.assertEqual('00:00:18,000 --> 00:00:19,992\n', mod)
Exemplo n.º 8
0
 def test_decrement_sixty_seconds_to_time(self):
     srt = SrtMod('sub.srt', 60, 'S', 'D')
     part = '00:01:03,000'
     begin = re.match(r'(\d+):(\d+):(\d+),(\d{3})', part)
     mod = srt.mod_time(begin)
     self.assertEqual('00:00:03,000', mod)
Exemplo n.º 9
0
 def test_increment_fiften_seconds_to_time(self):
     srt = SrtMod('sub.srt', 15)
     part = '00:00:03,000'
     begin = re.match(r'(\d+):(\d+):(\d+),(\d{3})', part)
     mod = srt.mod_time(begin)
     self.assertEqual('00:00:18,000', mod)
Exemplo n.º 10
0
 def test_when_file_is_load_content_must_be_greater_than_zero(self):
     srt = SrtMod('sub.srt')
     srt.process()
     self.assertGreater(len(srt.content), 0)
Exemplo n.º 11
0
 def test_file_exists(self):
     srt = SrtMod('sub.srt')
     result = srt.file_exist()
     self.assertTrue(result)
Exemplo n.º 12
0
 def test_incorrect_file_extension(self):
     srt = SrtMod('lalala.txt')
     result = srt.check_file_extension()
     self.assertFalse(result)