Last active
December 29, 2016 00:31
-
-
Save byung-u/6df1d209d11626cf42b1862d8c3dee42 to your computer and use it in GitHub Desktop.
자막파일에서 자막에 붙어있는 개행문자 제거해주는 스크립트
This file contains hidden or 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
#!/usr/bin/env python3.5 | |
# | |
# 원본 | |
# 00:14:17.810 --> 00:14:22.529 | |
# since the previous function was a generator | |
# that returns a list of positions, the caller | |
# 스크립트 실행 후 개행문자 제거 | |
# 00:14:17.810 --> 00:14:22.529 | |
# since the previous function was a generator that returns a list of positions, the caller | |
# | |
# USAGE | |
# ./xxxx.py subtitle | |
# 수행하면 subtitle.2016122832 결과 파일 | |
import re | |
import sys | |
from time import gmtime, strftime | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print('Usage: pyty.py FILE', file=sys.stderr) | |
sys.exit(2) | |
file_name = sys.argv[1] | |
out_file_name = '%s.%s' % (file_name, strftime("%Y%m%d%H%M%S", gmtime())) | |
# 00 : 37 : 24.250 -> 00 : 37 : 30.160 | |
# p = re.compile(r'\d+\d+\ :\ \d+\d+\ :\ \d+\d+\.\d+\d+\d+\ \-\>\ \d+\d+\ :\ \d+\d+\ :\ \d+\d+\.\d+\d+\d+') | |
# 00:36:47.450 --> 00:36:50.560 | |
p = re.compile(r'\d+\d+:\d+\d+:\d+\d+\.\d+\d+\d+\ \-\-\>\ \d+\d+:\d+\d+:\d+\d+\.\d+\d+\d+') | |
fw = open(out_file_name, 'w') | |
with open(file_name) as f: | |
for line in f: | |
m = p.match(line) | |
if m is not None: | |
fw.write(line) | |
elif line == '\n': | |
fw.write('\n\n') | |
else: | |
fw.write(line.replace('\n', ' ')) | |
f.closed | |
fw.close() | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment