Skip to content

Commit 879dd48

Browse files
committed
P 태그 이외의 모든 HTML 태그를 제거하도록 개선
1 parent b8164e8 commit 879dd48

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__pycache__
22
build
33
*.pyc
4-
*.old
4+
*.old

examples/smi2vtt.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,8 @@ def throw(code):
88
print(error.msg, file=stderr)
99
exit(error.code)
1010

11-
print('변환을 시작합니다.')
12-
13-
try:
14-
smi_filepath = argv[1].rsplit('.', 1)
15-
except IndexError:
16-
throw(-1)
17-
18-
if len(smi_filepath) < 2:
19-
vtt_filepath = argv[1]+'.vtt'
20-
else:
21-
vtt_filepath = smi_filepath[0]+'.vtt'
22-
2311
smi_filepath = argv[1]
12+
vtt_filepath = smi_filepath.rsplit('.', 1)[0]+'.vtt'
2413

2514
try:
2615
smi = SmiFile(smi_filepath)
@@ -36,9 +25,6 @@ def throw(code):
3625
vtt_file.write(vtt)
3726
vtt_file.close()
3827
except:
39-
print('변환한 자막 파일을 저장할 수 없습니다.', file=stderr)
4028
exit(-5)
4129

42-
print('성공적으로 변환했습니다.')
43-
print(' WebVTT 파일 : '+vtt_filepath)
44-
exit(1)
30+
exit(1)

src/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ def parse_p(item):
5353
lang = search(item, '<p(.+)class=([a-z]+)').group(2)
5454

5555
content = item[search(item, '<p(.+)>').end():]
56-
content = re.sub('<br ?/?>', '\n', content.replace('\n', ''), flags=re.I).strip()
56+
content = content.replace('\n', '')
57+
content = re.sub('<br ?/?>', '\n', content, flags=re.I)
58+
content = re.sub('<.*?>','', content)
59+
content = content.strip()
5760

5861
return [lang, content]
5962

@@ -80,7 +83,7 @@ def convert(self, target, lang='ENCC'):
8083
result = ''
8184

8285
if target == 'vtt':
83-
result += 'WEBVTT FILE'
86+
result += 'WEBVTT'
8487

8588
loop_index = 0
8689
sub_index = 1
@@ -111,4 +114,4 @@ def convert(self, target, lang='ENCC'):
111114
else:
112115
raise ConversionError(-4)
113116

114-
return result
117+
return result

0 commit comments

Comments
 (0)