Merge pull request #35 from coslyk/master

Enable loading danmaku from /dev/stdin
This commit is contained in:
Star Brilliant 2016-07-26 16:50:21 +08:00 committed by GitHub
commit 7e0be7ef6c

View File

@ -824,10 +824,12 @@ def ReadComments(input_files, font_size=25.0, progress_callback=None):
if progress_callback: if progress_callback:
progress_callback(idx, len(input_files)) progress_callback(idx, len(input_files))
with ConvertToFile(i, 'r', encoding='utf-8', errors='replace') as f: with ConvertToFile(i, 'r', encoding='utf-8', errors='replace') as f:
CommentProcessor = GetCommentProcessor(f) s = f.read()
str_io = io.StringIO(s)
CommentProcessor = GetCommentProcessor(str_io)
if not CommentProcessor: if not CommentProcessor:
raise ValueError(_('Unknown comment file format: %s') % i) raise ValueError(_('Unknown comment file format: %s') % i)
comments.extend(CommentProcessor(FilterBadChars(f), font_size)) comments.extend(CommentProcessor(FilterBadChars(str_io), font_size))
if progress_callback: if progress_callback:
progress_callback(len(input_files), len(input_files)) progress_callback(len(input_files), len(input_files))
comments.sort() comments.sort()