-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClearSubtitle.py
30 lines (26 loc) · 1.01 KB
/
ClearSubtitle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Author : D4Vinci
#Clear subtitles files from coloring codes so if you wanted to play movies on tv without any annonying codes
#Usage : ClearSubtitle.py <Subtitle_file>
import sys,re,os
def clear(srt):
codes = ["</font>","<i>","</i>"]
font_regex = re.compile(r".font color=.#[a-z|A-Z|0-9]*..") #"""<font color="#FFA500">"""
font_regex2 = re.compile(r".font color=#[a-z|A-Z|0-9]*.") #"""<font color=#FFA500>"""
ra5ama_regex = re.compile(r"{.*}") #"""{\fs50\fad(1000,1500)\cὈ&\..\...\..\....}"""
f=open(srt,"r")
subtitles=f.read()
f.close()
extracted=font_regex.findall(subtitles)
extracted+=font_regex2.findall(subtitles)
extracted+=ra5ama_regex.findall(subtitles)
all = extracted + codes
for i in all :
subtitles=subtitles.replace(i,"")
open(srt,"w").write(subtitles)
try:
srt = sys.argv[1]
clear(srt)
except:
srts =[ i for i in os.listdir() if i.endswith(".srt") ]
for srt in srts:
clear(srt)