Filter chars under \x20

This commit is contained in:
Star Brilliant 2013-11-03 11:59:52 +08:00
parent 0563194b82
commit d3d22c0ade

View File

@ -4,11 +4,13 @@ import argparse
import calendar import calendar
import colorsys import colorsys
import gettext import gettext
import io
import json import json
import logging import logging
import math import math
import os import os
import random import random
import re
import sys import sys
import time import time
import xml.dom.minidom import xml.dom.minidom
@ -338,6 +340,12 @@ def ConvertToFile(filename_or_file, *args, **kwargs):
return filename_or_file return filename_or_file
def FilterBadChars(f):
s = f.read()
s = re.sub('[\\x00-\\x19]', '\ufffd', s)
return io.StringIO(s)
def Danmaku2ASS(input_files, output_file, stage_width, stage_height, reserve_blank=0, font_face=_('(FONT) sans-serif')[7:], font_size=25.0, text_opaque=1.0, comment_duration=5.0, is_reduce_comments=False): def Danmaku2ASS(input_files, output_file, stage_width, stage_height, reserve_blank=0, font_face=_('(FONT) sans-serif')[7:], font_size=25.0, text_opaque=1.0, comment_duration=5.0, is_reduce_comments=False):
if isinstance(input_files, str): if isinstance(input_files, str):
input_files = [input_files] input_files = [input_files]
@ -347,7 +355,7 @@ def Danmaku2ASS(input_files, output_file, stage_width, stage_height, reserve_bla
CommentProcesser = CommentFormatMap[ProbeCommentFormat(f)] CommentProcesser = CommentFormatMap[ProbeCommentFormat(f)]
if not CommentProcesser: if not CommentProcesser:
raise ValueError(_('Unknown comment file format: %s') % i) raise ValueError(_('Unknown comment file format: %s') % i)
for comment in CommentProcesser(f, font_size): for comment in CommentProcesser(FilterBadChars(f), font_size):
comments.append(comment) comments.append(comment)
try: try:
if output_file: if output_file: