MCPcopy Create free account
hub / github.com/Jack-Cherish/python-spider / WriteComment

Function WriteComment

bilibili/xml2ass.py:663–680  ·  view source on GitHub ↗
(f, c, row, width, height, bottomReserved, fontsize, lifetime, styleid)

Source from the content-addressed store, hash-verified

661
662
663def WriteComment(f, c, row, width, height, bottomReserved, fontsize, lifetime, styleid):
664 text = ASSEscape(c[3])
665 styles = []
666 if c[4] == 1:
667 styles.append('\\an8\\pos(%(halfwidth)s, %(row)s)' % {'halfwidth': round(width/2), 'row': row})
668 elif c[4] == 2:
669 styles.append('\\an2\\pos(%(halfwidth)s, %(row)s)' % {'halfwidth': round(width/2), 'row': ConvertType2(row, height, bottomReserved)})
670 elif c[4] == 3:
671 styles.append('\\move(%(neglen)s, %(row)s, %(width)s, %(row)s)' % {'width': width, 'row': row, 'neglen': -math.ceil(c[8])})
672 else:
673 styles.append('\\move(%(width)s, %(row)s, %(neglen)s, %(row)s)' % {'width': width, 'row': row, 'neglen': -math.ceil(c[8])})
674 if not (-1 < c[6]-fontsize < 1):
675 styles.append('\\fs%s' % round(c[6]))
676 if c[5] != 0xffffff:
677 styles.append('\\c&H%02X%02X%02X&' % (c[5] & 0xff, (c[5] >> 8) & 0xff, (c[5] >> 16) & 0xff))
678 if c[5] == 0x000000:
679 styles.append('\\3c&HFFFFFF&')
680 f.write('Dialogue: 2,%(start)s,%(end)s,%(styleid)s,,0000,0000,0000,,{%(styles)s}%(text)s\n' % {'start': ConvertTimestamp(c[0]), 'end': ConvertTimestamp(c[0]+lifetime), 'styles': ''.join(styles), 'text': text, 'styleid': styleid})
681
682
683def ASSEscape(s):

Callers 1

ProcessCommentsFunction · 0.70

Calls 3

ASSEscapeFunction · 0.70
ConvertType2Function · 0.70
ConvertTimestampFunction · 0.70

Tested by

no test coverage detected