Created
December 6, 2013 10:44
-
-
Save ducin/7821817 to your computer and use it in GitHub Desktop.
Simple subtitles modifier (handles MicroDVD format), tested on python 2.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
parser = argparse.ArgumentParser(description='Move subtitles in MicroDVD format.') | |
parser.add_argument('input_file', metavar='input_file', type=str, help='input file') | |
parser.add_argument('output_file', metavar='output_file', type=str, help='output file') | |
parser.add_argument('frames_diff', metavar='frames_diff', type=float, help='frames difference (check MicroDVD format)') | |
parser.add_argument('--ignore-lines', dest='ignore_lines', type=int, default=0, help='number of lines to be ignored') | |
args = parser.parse_args() | |
import re | |
my_re = r"\{([0-9]*)\}\{([0-9]*)\}(.*)" | |
fin = open(args.input_file, 'r') | |
fout = open(args.output_file, 'w') | |
change_frames = lambda before: int(int(before) + args.frames_diff) | |
for _ in range(args.ignore_lines): | |
fout.write(fin.readline()) | |
for line in fin: | |
mobj = re.match(my_re, line) | |
fout.write("{%d}{%d}%s\n" % (change_frames(mobj.group(1)), change_frames(mobj.group(2)), mobj.group(3))) | |
fin.close() | |
fout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment