Add support for sH5V positioned comment

This commit is contained in:
910JQK 2014-02-02 19:22:15 +08:00
parent 84cc08f7f3
commit 49b338b1f9
9 changed files with 204 additions and 147 deletions

View File

@ -219,7 +219,18 @@ def ReadCommentsSH5V(f, fontsize):
c_color = str(comment['color'])
c = str(comment['text'])
size = fontsize
yield (float(c_at), int(c_date), i, c, {'0': 0, '1': 0, '4': 2, '5': 1}[c_type], int(c_color[1:], 16), size, (c.count('\n')+1)*size, CalculateLength(c)*size)
if c_type != '7':
yield (float(c_at), int(c_date), i, c, {'0': 0, '1': 0, '4': 2, '5': 1}[c_type], int(c_color[1:], 16), size, (c.count('\n')+1)*size, CalculateLength(c)*size)
else:
c_x = float(comment['x'])
c_y = float(comment['y'])
size = int(comment['size'])
dur = int(comment['dur'])
data1 = float(comment['data1'])
data2 = float(comment['data2'])
data3 = int(comment['data3'])
data4 = int(comment['data4'])
yield (float(c_at), int(c_date), i, c, 'sH5Vpos', int(c_color[1:], 16), size, 0, 0, c_x, c_y, dur, data1, data2, data3, data4)
except (AssertionError, AttributeError, IndexError, TypeError, ValueError):
logging.warning(_('Invalid comment: %r') % comment)
continue
@ -307,7 +318,6 @@ def WriteCommentBilibiliPositioned(f, c, width, height, styleid):
except IndexError:
logging.warning(_('Invalid comment: %r') % c)
def WriteCommentAcfunPositioned(f, c, width, height, styleid):
AcfunPlayerSize = (560, 400)
ZoomFactor = GetZoomFactor(AcfunPlayerSize, (width, height))
@ -425,6 +435,52 @@ def WriteCommentAcfunPositioned(f, c, width, height, styleid):
except (IndexError, ValueError) as e:
logging.warning(_('Invalid comment: %r') % c[3])
def WriteCommentSH5VPositioned(f, c, width, height, styleid):
def GetTransformStyles(x=None, y=None, fsize=None, rotate_z=None, rotate_y=None, color=None, alpha=None):
styles = []
if x is not None and y is not None:
styles.append('\\pos(%s, %s)' % (x, y))
if fsize is not None:
styles.append('\\fs%s' % fsize)
if rotate_y is not None and rotate_z is not None:
styles.append('\\frz%s' % round(rotate_z))
if not (-1 < rotate_z < 1):
styles.append('\\frx%s' % round(rotate_y*math.sin(rotate_z*math.pi/180.0)))
styles.append('\\fry%s' % round(rotate_y*math.cos(rotate_z*math.pi/180.0)))
else:
styles.append('\\fry%s' % round(rotate_y))
if color is not None:
styles.append('\\c&H%02X%02X%02X&' % (color & 0xff, (color >> 8) & 0xff, (color >> 16) & 0xff))
if color == 0x000000:
styles.append('\\3c&HFFFFFF&')
if alpha is not None:
alpha = 255-round(alpha*255)
styles.append('\\alpha&H%02X' % alpha)
return styles
def FlushCommentLine(f, text, styles, start_time, end_time, styleid):
if end_time > start_time:
f.write('Dialogue: -1,%(start)s,%(end)s,%(styleid)s,,0,0,0,,{%(styles)s}%(text)s\n' % {'start': ConvertTimestamp(start_time), 'end': ConvertTimestamp(end_time), 'styles': ''.join(styles), 'text': text, 'styleid': styleid})
try:
text = ASSEscape(str(c[3]))
to_x = round(float(c[9])*width)
to_y = round(float(c[10])*height)
to_rotate_z = -int(c[14])
to_rotate_y = -int(c[15])
to_color = c[5]
to_alpha = float(c[12])
#Note: Alpha transition hasn't been worked out yet.
to_size = round(int(c[6])*math.sqrt(width*height/307200))
#Note: Because sH5V's data is the absolute size of font,temporarily solve by it at present.[*math.sqrt(width/640*height/480)]
#But it seems to be working fine...
from_time = float(c[0])
action_time = float(c[11])/1000
transform_styles = GetTransformStyles(to_x, to_y, to_size, to_rotate_z, to_rotate_y, to_color, to_alpha)
FlushCommentLine(f, text, transform_styles, from_time, from_time+action_time, styleid)
except (IndexError, ValueError) as e:
logging.warning(_('Invalid comment: %r') % c[3])
# Result: (f, dx, dy)
# To convert: NewX = f*x+dx, NewY = f*y+dy
@ -451,7 +507,6 @@ def GetZoomFactor(SourceSize, TargetSize):
GetZoomFactor.Cached_Result = (1, 0, 0)
return GetZoomFactor.Cached_Result
def ProcessComments(comments, f, width, height, bottomReserved, fontface, fontsize, alpha, lifetime, reduced, progress_callback):
styleid = 'Danmaku2ASS_%04x' % random.randint(0, 0xffff)
WriteASSHead(f, width, height, fontface, fontsize, alpha, styleid)
@ -479,6 +534,8 @@ def ProcessComments(comments, f, width, height, bottomReserved, fontface, fontsi
WriteCommentBilibiliPositioned(f, i, width, height, styleid)
elif i[4] == 'acfunpos':
WriteCommentAcfunPositioned(f, i, width, height, styleid)
elif i[4] == 'sH5Vpos':
WriteCommentSH5VPositioned(f, i, width, height, styleid)
else:
logging.warning(_('Invalid comment: %r') % i[3])
if progress_callback:

Binary file not shown.

View File

@ -2,105 +2,105 @@ msgid ""
msgstr ""
"Project-Id-Version: Danmaku2ASS\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-24 15:30+0800\n"
"POT-Creation-Date: 2014-02-02 18:51+0800\n"
"Last-Translator: Star Brilliant <m13253@hotmail.com>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: danmaku2ass.py:130 danmaku2ass.py:165 danmaku2ass.py:195
#: danmaku2ass.py:139 danmaku2ass.py:178 danmaku2ass.py:208
#, python-format
msgid "Invalid comment: %s"
msgstr "Invalid comment: %s"
#: danmaku2ass.py:145 danmaku2ass.py:179 danmaku2ass.py:211 danmaku2ass.py:317
#: danmaku2ass.py:319 danmaku2ass.py:348
#: danmaku2ass.py:158 danmaku2ass.py:192 danmaku2ass.py:235 danmaku2ass.py:317
#: danmaku2ass.py:319 danmaku2ass.py:436 danmaku2ass.py:483 danmaku2ass.py:540
#, python-format
msgid "Invalid comment: %r"
msgstr "Invalid comment: %r"
#: danmaku2ass.py:496 danmaku2ass.py:539
#: danmaku2ass.py:690 danmaku2ass.py:738
msgid "(FONT) sans-serif"
msgstr "(FONT) Helvetica"
#: danmaku2ass.py:522
#: danmaku2ass.py:719
#, python-format
msgid "Unknown comment file format: %s"
msgstr "Unknown comment file format: %s"
#: danmaku2ass.py:537
#: danmaku2ass.py:736
msgid "OUTPUT"
msgstr "OUTPUT"
#: danmaku2ass.py:537
#: danmaku2ass.py:736
msgid "Output file"
msgstr "Output file"
#: danmaku2ass.py:538
msgid "Stage size in pixels"
msgstr "Stage size in pixels"
#: danmaku2ass.py:538
#: danmaku2ass.py:737
msgid "WIDTHxHEIGHT"
msgstr "WIDTHxHEIGHT"
#: danmaku2ass.py:539
#: danmaku2ass.py:737
msgid "Stage size in pixels"
msgstr "Stage size in pixels"
#: danmaku2ass.py:738
msgid "FONT"
msgstr "FONT"
#: danmaku2ass.py:539
#: danmaku2ass.py:738
#, python-format
msgid "Specify font face [default: %s]"
msgstr "Specify font face [default: %s]"
#: danmaku2ass.py:540
#: danmaku2ass.py:739
msgid "SIZE"
msgstr "SIZE"
#: danmaku2ass.py:739
#, python-format
msgid "Default font size [default: %s]"
msgstr "Default font size [default: %s]"
#: danmaku2ass.py:540
msgid "SIZE"
msgstr "SIZE"
#: danmaku2ass.py:541
#: danmaku2ass.py:740
msgid "ALPHA"
msgstr "ALPHA"
#: danmaku2ass.py:541
#: danmaku2ass.py:740
msgid "Text opaque"
msgstr "Text opaque"
#: danmaku2ass.py:542
#: danmaku2ass.py:741
msgid "SECONDS"
msgstr "SECONDS"
#: danmaku2ass.py:741
#, python-format
msgid "Duration of comment display [default: %s]"
msgstr "Duration of comment display [default: %s]"
#: danmaku2ass.py:542
msgid "SECONDS"
msgstr "SECONDS"
#: danmaku2ass.py:543
#: danmaku2ass.py:742
msgid "HEIGHT"
msgstr "HEIGHT"
#: danmaku2ass.py:543
#: danmaku2ass.py:742
msgid "Reserve blank on the bottom of the stage"
msgstr "Reserve blank on the bottom of the stage"
#: danmaku2ass.py:544
#: danmaku2ass.py:743
msgid "Reduce the amount of comments if stage is full"
msgstr "Reduce the amount of comments if stage is full"
#: danmaku2ass.py:545
msgid "Comment file to be processed"
msgstr "Comment file to be processed"
#: danmaku2ass.py:545
#: danmaku2ass.py:744
msgid "FILE"
msgstr "FILE"
#: danmaku2ass.py:552
#: danmaku2ass.py:744
msgid "Comment file to be processed"
msgstr "Comment file to be processed"
#: danmaku2ass.py:751
#, python-format
msgid "Invalid stage size: %r"
msgstr "Invalid stage size: %r"

Binary file not shown.

View File

@ -2,105 +2,105 @@ msgid ""
msgstr ""
"Project-Id-Version: Danmaku2ASS\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-24 15:30+0800\n"
"POT-Creation-Date: 2014-02-02 18:51+0800\n"
"Last-Translator: Star Brilliant <m13253@hotmail.com>\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: danmaku2ass.py:130 danmaku2ass.py:165 danmaku2ass.py:195
#: danmaku2ass.py:139 danmaku2ass.py:178 danmaku2ass.py:208
#, python-format
msgid "Invalid comment: %s"
msgstr "無効なコメント:%s"
#: danmaku2ass.py:145 danmaku2ass.py:179 danmaku2ass.py:211 danmaku2ass.py:317
#: danmaku2ass.py:319 danmaku2ass.py:348
#: danmaku2ass.py:158 danmaku2ass.py:192 danmaku2ass.py:235 danmaku2ass.py:317
#: danmaku2ass.py:319 danmaku2ass.py:436 danmaku2ass.py:483 danmaku2ass.py:540
#, python-format
msgid "Invalid comment: %r"
msgstr "無効なコメント:%r"
#: danmaku2ass.py:496 danmaku2ass.py:539
#: danmaku2ass.py:690 danmaku2ass.py:738
msgid "(FONT) sans-serif"
msgstr "(FONT) MS PGothic"
#: danmaku2ass.py:522
#: danmaku2ass.py:719
#, python-format
msgid "Unknown comment file format: %s"
msgstr "未知のコメントファイル形式:%s"
#: danmaku2ass.py:537
#: danmaku2ass.py:736
msgid "OUTPUT"
msgstr "出力"
#: danmaku2ass.py:537
#: danmaku2ass.py:736
msgid "Output file"
msgstr "出力ファイル"
#: danmaku2ass.py:538
msgid "Stage size in pixels"
msgstr "ピクセル単位でステージのサイズ"
#: danmaku2ass.py:538
#: danmaku2ass.py:737
msgid "WIDTHxHEIGHT"
msgstr "幅x高"
#: danmaku2ass.py:539
#: danmaku2ass.py:737
msgid "Stage size in pixels"
msgstr "ピクセル単位でステージのサイズ"
#: danmaku2ass.py:738
msgid "FONT"
msgstr "フォント"
#: danmaku2ass.py:539
#: danmaku2ass.py:738
#, python-format
msgid "Specify font face [default: %s]"
msgstr "フォントを指定する [デフォルト: %s]"
#: danmaku2ass.py:540
#: danmaku2ass.py:739
msgid "SIZE"
msgstr "サイズ"
#: danmaku2ass.py:739
#, python-format
msgid "Default font size [default: %s]"
msgstr "デフォルトのフォントサイズ [デフォルト: %s]"
#: danmaku2ass.py:540
msgid "SIZE"
msgstr "サイズ"
#: danmaku2ass.py:541
#: danmaku2ass.py:740
msgid "ALPHA"
msgstr "アルファ"
#: danmaku2ass.py:541
#: danmaku2ass.py:740
msgid "Text opaque"
msgstr "テキストの不透明度"
#: danmaku2ass.py:542
#: danmaku2ass.py:741
msgid "SECONDS"
msgstr "秒数"
#: danmaku2ass.py:741
#, python-format
msgid "Duration of comment display [default: %s]"
msgstr "コメント表示の時間 [デフォルト: %s]"
#: danmaku2ass.py:542
msgid "SECONDS"
msgstr "秒数"
#: danmaku2ass.py:543
#: danmaku2ass.py:742
msgid "HEIGHT"
msgstr "高度"
#: danmaku2ass.py:543
#: danmaku2ass.py:742
msgid "Reserve blank on the bottom of the stage"
msgstr "ステージの下にブランクを予備する"
#: danmaku2ass.py:544
#: danmaku2ass.py:743
msgid "Reduce the amount of comments if stage is full"
msgstr "ステージがいっぱいになったのときにコメントの量を減らす"
#: danmaku2ass.py:545
msgid "Comment file to be processed"
msgstr "ファイルが処理されるコメント"
#: danmaku2ass.py:545
#: danmaku2ass.py:744
msgid "FILE"
msgstr "ファイル"
#: danmaku2ass.py:552
#: danmaku2ass.py:744
msgid "Comment file to be processed"
msgstr "ファイルが処理されるコメント"
#: danmaku2ass.py:751
#, python-format
msgid "Invalid stage size: %r"
msgstr "無効なステージサイズ:%r"

View File

@ -2,105 +2,105 @@ msgid ""
msgstr ""
"Project-Id-Version: Danmaku2ASS\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-24 15:30+0800\n"
"POT-Creation-Date: 2014-02-02 18:51+0800\n"
"Last-Translator: Star Brilliant <m13253@hotmail.com>\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: danmaku2ass.py:130 danmaku2ass.py:165 danmaku2ass.py:195
#: danmaku2ass.py:139 danmaku2ass.py:178 danmaku2ass.py:208
#, python-format
msgid "Invalid comment: %s"
msgstr "无效弹幕:%s"
#: danmaku2ass.py:145 danmaku2ass.py:179 danmaku2ass.py:211 danmaku2ass.py:317
#: danmaku2ass.py:319 danmaku2ass.py:348
#: danmaku2ass.py:158 danmaku2ass.py:192 danmaku2ass.py:235 danmaku2ass.py:317
#: danmaku2ass.py:319 danmaku2ass.py:436 danmaku2ass.py:483 danmaku2ass.py:540
#, python-format
msgid "Invalid comment: %r"
msgstr "无效弹幕:%r"
#: danmaku2ass.py:496 danmaku2ass.py:539
#: danmaku2ass.py:690 danmaku2ass.py:738
msgid "(FONT) sans-serif"
msgstr "(FONT) SimHei"
#: danmaku2ass.py:522
#: danmaku2ass.py:719
#, python-format
msgid "Unknown comment file format: %s"
msgstr "未知的弹幕文件格式:%s"
#: danmaku2ass.py:537
#: danmaku2ass.py:736
msgid "OUTPUT"
msgstr "输出"
#: danmaku2ass.py:537
#: danmaku2ass.py:736
msgid "Output file"
msgstr "输出文件"
#: danmaku2ass.py:538
msgid "Stage size in pixels"
msgstr "舞台尺寸的像素数目"
#: danmaku2ass.py:538
#: danmaku2ass.py:737
msgid "WIDTHxHEIGHT"
msgstr "宽x高"
#: danmaku2ass.py:539
#: danmaku2ass.py:737
msgid "Stage size in pixels"
msgstr "舞台尺寸的像素数目"
#: danmaku2ass.py:738
msgid "FONT"
msgstr "字体"
#: danmaku2ass.py:539
#: danmaku2ass.py:738
#, python-format
msgid "Specify font face [default: %s]"
msgstr "指定字体名称 [默认: %s]"
#: danmaku2ass.py:540
#: danmaku2ass.py:739
msgid "SIZE"
msgstr "尺寸"
#: danmaku2ass.py:739
#, python-format
msgid "Default font size [default: %s]"
msgstr "默认字号 [默认: %s]"
#: danmaku2ass.py:540
msgid "SIZE"
msgstr "尺寸"
#: danmaku2ass.py:541
#: danmaku2ass.py:740
msgid "ALPHA"
msgstr "ALPHA"
#: danmaku2ass.py:541
#: danmaku2ass.py:740
msgid "Text opaque"
msgstr "文字不透明度"
#: danmaku2ass.py:542
#: danmaku2ass.py:741
msgid "SECONDS"
msgstr "秒数"
#: danmaku2ass.py:741
#, python-format
msgid "Duration of comment display [default: %s]"
msgstr "弹幕显示时长 [默认: %s]"
#: danmaku2ass.py:542
msgid "SECONDS"
msgstr "秒数"
#: danmaku2ass.py:543
#: danmaku2ass.py:742
msgid "HEIGHT"
msgstr "高度"
#: danmaku2ass.py:543
#: danmaku2ass.py:742
msgid "Reserve blank on the bottom of the stage"
msgstr "在舞台底部预留空位"
#: danmaku2ass.py:544
#: danmaku2ass.py:743
msgid "Reduce the amount of comments if stage is full"
msgstr "在舞台满时减少弹幕数量"
#: danmaku2ass.py:545
msgid "Comment file to be processed"
msgstr "将要处理的弹幕文件"
#: danmaku2ass.py:545
#: danmaku2ass.py:744
msgid "FILE"
msgstr "文件"
#: danmaku2ass.py:552
#: danmaku2ass.py:744
msgid "Comment file to be processed"
msgstr "将要处理的弹幕文件"
#: danmaku2ass.py:751
#, python-format
msgid "Invalid stage size: %r"
msgstr "无效舞台尺寸:%r"

View File

@ -2,105 +2,105 @@ msgid ""
msgstr ""
"Project-Id-Version: Danmaku2ASS\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-24 15:30+0800\n"
"POT-Creation-Date: 2014-02-02 18:51+0800\n"
"Last-Translator: Star Brilliant <m13253@hotmail.com>\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: danmaku2ass.py:130 danmaku2ass.py:165 danmaku2ass.py:195
#: danmaku2ass.py:139 danmaku2ass.py:178 danmaku2ass.py:208
#, python-format
msgid "Invalid comment: %s"
msgstr "無效彈幕:%s"
#: danmaku2ass.py:145 danmaku2ass.py:179 danmaku2ass.py:211 danmaku2ass.py:317
#: danmaku2ass.py:319 danmaku2ass.py:348
#: danmaku2ass.py:158 danmaku2ass.py:192 danmaku2ass.py:235 danmaku2ass.py:317
#: danmaku2ass.py:319 danmaku2ass.py:436 danmaku2ass.py:483 danmaku2ass.py:540
#, python-format
msgid "Invalid comment: %r"
msgstr "無效彈幕:%r"
#: danmaku2ass.py:496 danmaku2ass.py:539
#: danmaku2ass.py:690 danmaku2ass.py:738
msgid "(FONT) sans-serif"
msgstr "(FONT) Microsoft JhengHei"
#: danmaku2ass.py:522
#: danmaku2ass.py:719
#, python-format
msgid "Unknown comment file format: %s"
msgstr "未知的彈幕檔案格式:%s"
#: danmaku2ass.py:537
#: danmaku2ass.py:736
msgid "OUTPUT"
msgstr "輸出"
#: danmaku2ass.py:537
#: danmaku2ass.py:736
msgid "Output file"
msgstr "輸出檔案"
#: danmaku2ass.py:538
msgid "Stage size in pixels"
msgstr "舞臺尺寸的畫素數目"
#: danmaku2ass.py:538
#: danmaku2ass.py:737
msgid "WIDTHxHEIGHT"
msgstr "寬x高"
#: danmaku2ass.py:539
#: danmaku2ass.py:737
msgid "Stage size in pixels"
msgstr "舞臺尺寸的畫素數目"
#: danmaku2ass.py:738
msgid "FONT"
msgstr "字型"
#: danmaku2ass.py:539
#: danmaku2ass.py:738
#, python-format
msgid "Specify font face [default: %s]"
msgstr "指定字型名稱 [默認: %s]"
#: danmaku2ass.py:540
#: danmaku2ass.py:739
msgid "SIZE"
msgstr "尺寸"
#: danmaku2ass.py:739
#, python-format
msgid "Default font size [default: %s]"
msgstr "默認字型大小 [默認: %s]"
#: danmaku2ass.py:540
msgid "SIZE"
msgstr "尺寸"
#: danmaku2ass.py:541
#: danmaku2ass.py:740
msgid "ALPHA"
msgstr "ALPHA"
#: danmaku2ass.py:541
#: danmaku2ass.py:740
msgid "Text opaque"
msgstr "文字不透明度"
#: danmaku2ass.py:542
#: danmaku2ass.py:741
msgid "SECONDS"
msgstr "秒數"
#: danmaku2ass.py:741
#, python-format
msgid "Duration of comment display [default: %s]"
msgstr "彈幕顯示時長 [默認: %s]"
#: danmaku2ass.py:542
msgid "SECONDS"
msgstr "秒數"
#: danmaku2ass.py:543
#: danmaku2ass.py:742
msgid "HEIGHT"
msgstr "高度"
#: danmaku2ass.py:543
#: danmaku2ass.py:742
msgid "Reserve blank on the bottom of the stage"
msgstr "在舞臺底部預留空位"
#: danmaku2ass.py:544
#: danmaku2ass.py:743
msgid "Reduce the amount of comments if stage is full"
msgstr "在舞臺滿時減少彈幕數量"
#: danmaku2ass.py:545
msgid "Comment file to be processed"
msgstr "將要處理的彈幕檔案"
#: danmaku2ass.py:545
#: danmaku2ass.py:744
msgid "FILE"
msgstr "檔案"
#: danmaku2ass.py:552
#: danmaku2ass.py:744
msgid "Comment file to be processed"
msgstr "將要處理的彈幕檔案"
#: danmaku2ass.py:751
#, python-format
msgid "Invalid stage size: %r"
msgstr "無效舞臺尺寸:%r"