-
Notifications
You must be signed in to change notification settings - Fork 2
Fixed color code revering issues and allow it to run on python 3.8.x #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/build | ||
/test_smis/*.ass | ||
__pycache__ | ||
.vscode | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,15 +27,14 @@ | |
major = sys.version_info.major | ||
minor = sys.version_info.minor | ||
|
||
if major == 3 and minor == 7: | ||
if major == 3 and minor >= 7: | ||
import html | ||
elif major == 3 and minor < 7: | ||
from html.parser import HTMLParser | ||
else: | ||
print ('version 3.x needed') | ||
|
||
default_lang_code = 'kor' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you let me know why this had to be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought if the subtitle file only incused single language in the subtitle it is meaningless to add kor on the file name. Since already know what language is in the subtitle file. |
||
default_font_name = 'sans-serif' | ||
default_font_name = 'Malgun Gothic' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using fonts like "Noto Sans CJK KR" instead, given Malgun Gothic is not available in non-Windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is part of my mistake, while using and testing this program, I modified the ass to match with my subtitle settings. |
||
|
||
# lang class for multiple language subtitle | ||
langCode = {'KRCC':'kor','KOCC':'kor','KR':'kor','KO':'kor','KOREANSC':'kor','KRC':'kor', | ||
|
@@ -47,10 +46,12 @@ | |
"""[Script Info] | ||
;This is an Advanced Sub Station Alpha v4+ script. | ||
;Converted by smi2ass | ||
Title: 0 | ||
ScriptType: v4.00+ | ||
Collisions: Normal | ||
PlayResX: 384 | ||
PlayResY: 288 | ||
PlayDepth: 0 | ||
PlayResX: 1920 | ||
PlayResY: 1080 | ||
Timer: 100.0000 | ||
|
||
""" | ||
|
@@ -59,7 +60,7 @@ | |
""" | ||
[V4+ Styles] | ||
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding | ||
Style: Default,""" + default_font_name + """,22,&H00ffffff,&H0000ffff,&H00000000,&H80000000,0,0,0,0,100,100,0,0.00,1,1,1,2,20,20,20,1 | ||
Style: Default,""" + default_font_name + """,16,&H00FFFFFF,&H0000FFFF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,1 | ||
|
||
""" | ||
|
||
|
@@ -336,18 +337,19 @@ def smi2ass_internal (sln): | |
if not col == None: | ||
hexcolor = re.search('[0-9a-fA-F]{6}',color['color'].lower()) # bad cases : '23df34' | ||
if hexcolor is not None: | ||
converted_color = '{\\c&H' + hexcolor.group(0)[::-1]+'&}' + color.text + '{\\c}' | ||
converted_color = '{\\c&H' + rgb2bgr(hexcolor.group(0)[::]) +'&}' + color.text + '{\\c}' | ||
else: | ||
try: | ||
converted_color = '{\\c&H' + css3_names_to_hex[color['color'].lower()][::-1].replace('#','&}') + color.text + '{\\c}' | ||
hexConvert = rgb2bgr(css3_names_to_hex[color['color'].lower()][::].replace('#','')) | ||
converted_color = '{\\c&H' + hexConvert + '&}' + color.text + '{\\c}' | ||
except: # bad cases : 'skybule' | ||
converted_color = color.text | ||
print('Failed to convert a color name: %s' % color['color'].lower()) | ||
color.replaceWith(converted_color) | ||
|
||
contents = p_tags.text | ||
contents = re.sub(r'smi2ass_unicode\(([0-9]+)\)', r'&#\1;', contents) | ||
if minor == 7: | ||
if minor >= 7: | ||
contents = html.unescape(contents) | ||
else: | ||
parser = HTMLParser() | ||
|
@@ -356,10 +358,8 @@ def smi2ass_internal (sln): | |
if len(contents.strip()) != 0: | ||
line = 'Dialogue: 0,%s,%s,Default,,0000,0000,0000,,%s\n' % (tcstart,tcend, contents) | ||
ass_lines.append(line) | ||
|
||
return ass_lines | ||
|
||
|
||
def ms2timecode(ms): | ||
hours = int(ms / 3600000) | ||
ms -= hours * 3600000 | ||
|
@@ -371,7 +371,6 @@ def ms2timecode(ms): | |
timecode = '%01d:%02d:%02d.%02d' % (hours, minutes, seconds, ms) | ||
return timecode | ||
|
||
|
||
def separate_by_lang(smi_lines): | ||
#prepare multilanguage dict with languages separated list | ||
multiLanguageDict = defaultdict(list) | ||
|
@@ -482,8 +481,14 @@ def separate_by_lang(smi_lines): | |
longlang.append('') | ||
return multiLanguageDictSorted, longlang | ||
|
||
def rgb2bgr(rgb): | ||
# Converting RGB based color code to BGR color code. | ||
# Based on the ASS documentation, ASS useses BGR | ||
return rgb[4:6] + rgb[2:4] + rgb[0:2] | ||
|
||
for smi_path in sys.argv[1:]: | ||
# Print what file is currently working on | ||
print(smi_path) | ||
# Open as binary and detect the encoding. | ||
smi_file = open(smi_path, 'rb') | ||
smi_encoding = chardet.detect(smi_file.read())['encoding'] | ||
|
@@ -495,7 +500,7 @@ def separate_by_lang(smi_lines): | |
ass_dict = smi2ass(smi_sgml) | ||
for lang in ass_dict: | ||
if len(lang) == 0: | ||
ass_path = smi_path[:smi_path.rfind('.')] + '.' + default_lang_code + '.ass' | ||
ass_path = smi_path[:smi_path.rfind('.')] + '.ass' | ||
else: | ||
ass_path = smi_path[:smi_path.rfind('.')] + '.' + lang + '.ass' | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is automatically added by my IDE setting.