Skip to content

Commit 9e7c27a

Browse files
committed
♻️ refactor: extract write_normal_comment function
1 parent 0d16099 commit 9e7c27a

File tree

1 file changed

+70
-44
lines changed

1 file changed

+70
-44
lines changed

packages/biliass/src/biliass/biliass.py

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,64 @@ def write_comment(
173173
styleid,
174174
)
175175

176+
def write_normal_comment(
177+
self,
178+
rows: Rows,
179+
comment: Comment,
180+
width: int,
181+
height: int,
182+
bottom_reserved: int,
183+
fontsize: float,
184+
duration_marquee: float,
185+
duration_still: float,
186+
styleid: str,
187+
reduced: bool,
188+
):
189+
row = 0
190+
rowmax = height - bottom_reserved - comment.height
191+
while row <= rowmax:
192+
freerows = test_free_rows(
193+
rows,
194+
comment,
195+
row,
196+
width,
197+
height,
198+
bottom_reserved,
199+
duration_marquee,
200+
duration_still,
201+
)
202+
if freerows >= comment.height:
203+
mark_comment_row(rows, comment, row)
204+
self.write_comment(
205+
comment,
206+
row,
207+
width,
208+
height,
209+
bottom_reserved,
210+
fontsize,
211+
duration_marquee,
212+
duration_still,
213+
styleid,
214+
)
215+
break
216+
else:
217+
row += freerows or 1
218+
else:
219+
if not reduced:
220+
row = find_alternative_row(rows, comment, height, bottom_reserved)
221+
mark_comment_row(rows, comment, row)
222+
self.write_comment(
223+
comment,
224+
row,
225+
width,
226+
height,
227+
bottom_reserved,
228+
fontsize,
229+
duration_marquee,
230+
duration_still,
231+
styleid,
232+
)
233+
176234
def to_string(self):
177235
return self._text
178236

@@ -211,50 +269,18 @@ def process_comments(
211269
break
212270
if skip:
213271
continue
214-
row = 0
215-
rowmax = height - bottom_reserved - comment.height
216-
while row <= rowmax:
217-
freerows = test_free_rows(
218-
rows,
219-
comment,
220-
row,
221-
width,
222-
height,
223-
bottom_reserved,
224-
duration_marquee,
225-
duration_still,
226-
)
227-
if freerows >= comment.height:
228-
mark_comment_row(rows, comment, row)
229-
ass.write_comment(
230-
comment,
231-
row,
232-
width,
233-
height,
234-
bottom_reserved,
235-
fontsize,
236-
duration_marquee,
237-
duration_still,
238-
styleid,
239-
)
240-
break
241-
else:
242-
row += freerows or 1
243-
else:
244-
if not reduced:
245-
row = find_alternative_row(rows, comment, height, bottom_reserved)
246-
mark_comment_row(rows, comment, row)
247-
ass.write_comment(
248-
comment,
249-
row,
250-
width,
251-
height,
252-
bottom_reserved,
253-
fontsize,
254-
duration_marquee,
255-
duration_still,
256-
styleid,
257-
)
272+
ass.write_normal_comment(
273+
rows,
274+
comment,
275+
width,
276+
height,
277+
bottom_reserved,
278+
fontsize,
279+
duration_marquee,
280+
duration_still,
281+
styleid,
282+
reduced,
283+
)
258284
elif comment.pos == CommentPosition.Special:
259285
ass.write_comment_special(comment, width, height, styleid)
260286
else:

0 commit comments

Comments
 (0)