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

Function ProcessComments

bilibili/xml2ass.py:558–590  ·  view source on GitHub ↗
(comments, f, width, height, bottomReserved, fontface, fontsize, alpha, lifetime, reduced, progress_callback)

Source from the content-addressed store, hash-verified

556
557
558def ProcessComments(comments, f, width, height, bottomReserved, fontface, fontsize, alpha, lifetime, reduced, progress_callback):
559 styleid = 'Danmaku2ASS_%04x' % random.randint(0, 0xffff)
560 WriteASSHead(f, width, height, fontface, fontsize, alpha, styleid)
561 rows = [[None]*(height-bottomReserved+1) for i in range(4)]
562 for idx, i in enumerate(comments):
563 if progress_callback and idx % 1000 == 0:
564 progress_callback(idx, len(comments))
565 if isinstance(i[4], int):
566 row = 0
567 rowmax = height-bottomReserved-i[7]
568 while row <= rowmax:
569 freerows = TestFreeRows(rows, i, row, width, height, bottomReserved, lifetime)
570 if freerows >= i[7]:
571 MarkCommentRow(rows, i, row)
572 WriteComment(f, i, row, width, height, bottomReserved, fontsize, lifetime, styleid)
573 break
574 else:
575 row += freerows or 1
576 else:
577 if not reduced:
578 row = FindAlternativeRow(rows, i, height, bottomReserved)
579 MarkCommentRow(rows, i, row)
580 WriteComment(f, i, row, width, height, bottomReserved, fontsize, lifetime, styleid)
581 elif i[4] == 'bilipos':
582 WriteCommentBilibiliPositioned(f, i, width, height, styleid)
583 elif i[4] == 'acfunpos':
584 WriteCommentAcfunPositioned(f, i, width, height, styleid)
585 elif i[4] == 'sH5Vpos':
586 WriteCommentSH5VPositioned(f, i, width, height, styleid)
587 else:
588 logging.warning(_('Invalid comment: %r') % i[3])
589 if progress_callback:
590 progress_callback(len(comments), len(comments))
591
592
593def TestFreeRows(rows, c, row, width, height, bottomReserved, lifetime):

Callers 1

Danmaku2ASSFunction · 0.70

Calls 8

WriteASSHeadFunction · 0.70
TestFreeRowsFunction · 0.70
MarkCommentRowFunction · 0.70
WriteCommentFunction · 0.70
FindAlternativeRowFunction · 0.70

Tested by

no test coverage detected