File size: 877 Bytes
8f86c8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import re
import math

def group_sentences(text, target_sec=10):
    raw_sentences = re.split(r'(?<=[.?!])\s+', text.strip())
    scenes = []
    curr_text, curr_time = "", 0
    for s in raw_sentences:
        if not s: continue
        s_time = max(5, math.ceil(len(s)/35)*5)
        if curr_time + s_time > target_sec and curr_text:
            scenes.append({"text": curr_text, "time": curr_time})
            curr_text, curr_time = s, s_time
        else:
            curr_text = (curr_text + " " + s).strip()
            curr_time += s_time
    if curr_text: scenes.append({"text": curr_text, "time": curr_time})
    return scenes

def get_smart_filename(index, text):
    clean_text = re.sub(r'[\\/*?:"<>|]', "", text).strip()
    name_part = clean_text[:12] if len(clean_text) <= 12 else f"{clean_text[:6]}~{clean_text[-4:]}"
    return f"{index+1:02d}_{name_part}.png"