【修复】角色被格线切断(脚、手杖、飘起的斗篷被削掉) 新增 expand_beyond_cell(默认开启):格子只用来判定「这是哪个方向」, 角色的实际范围由它自身的连通区域决定,按质心归属确保邻居不混入。 实测 8/8 方向的裁剪框边缘 alpha 从 1.00(内容顶到边界=被切断) 降到 0.00,S 方向高度 326→356、E 方向宽度 150→188 把缺的部分找了回来。 代价是需要两遍扫描(先求全序列并集框再提取),耗时 4.7s→14.9s。 【规则】每个参数都必须有中文 tooltip,作为以后的统一约定 全仓库 26 个节点 169 个参数,此前缺 115 个,现已 100% 覆盖。 tooltip 写「怎么调」而不只是「是什么」:给取值区间的实际影响、 推荐值与踩坑提示(如 OpenAI/ZenMux 的地址栏不能带 :// , 素材拆分节点用于动画序列时顺序会漂移等)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
101 lines
3.3 KiB
Python
101 lines
3.3 KiB
Python
import re
|
|
import torch
|
|
|
|
class DialogueExtractorNode:
|
|
"""
|
|
对白提取器节点:从分镜描述中提取旁白/对白部分
|
|
"""
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"input_text": ("STRING", {
|
|
"multiline": True,
|
|
"default": "",
|
|
"tooltip": "分镜描述原文。节点会从中挑出旁白/对白部分,\n"
|
|
"画面描述、镜头调度等非台词内容会被滤掉。\n"
|
|
"输出为对白列表,可直接接配音或字幕环节。"
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("LIST", "STRING")
|
|
RETURN_NAMES = ("dialogues", "summary")
|
|
FUNCTION = "extract_dialogues"
|
|
CATEGORY = "Rui-Node🐶/文本处理📝"
|
|
|
|
def extract_dialogues(self, input_text):
|
|
"""
|
|
从分镜描述中提取旁白/对白部分
|
|
|
|
参数:
|
|
input_text: 输入的分镜描述文本
|
|
|
|
返回:
|
|
dialogues: 提取的旁白/对白列表
|
|
summary: 总结信息
|
|
"""
|
|
# 使用正则表达式匹配所有分镜内容
|
|
shot_pattern = r'<SHOT_(\d+)>([\s\S]*?)</SHOT_\1>'
|
|
shot_matches = re.findall(shot_pattern, input_text)
|
|
|
|
# 如果没有找到分镜标记,则直接在整个文本中查找旁白
|
|
if not shot_matches:
|
|
return self._extract_from_text(input_text)
|
|
|
|
# 从每个分镜中提取旁白
|
|
dialogues = []
|
|
for shot_num, content in shot_matches:
|
|
dialogue = self._extract_from_text(content)
|
|
if dialogue[0]: # 如果提取到了旁白
|
|
dialogues.extend(dialogue[0])
|
|
|
|
# 生成总结信息
|
|
summary = f"一共提取了{len(dialogues)}条旁白/对白。"
|
|
|
|
return (dialogues, summary)
|
|
|
|
def _extract_from_text(self, text):
|
|
"""
|
|
从文本中提取旁白/对白
|
|
|
|
参数:
|
|
text: 输入文本
|
|
|
|
返回:
|
|
dialogues: 提取的旁白/对白列表
|
|
summary: 总结信息
|
|
"""
|
|
# 使用正则表达式匹配旁白部分
|
|
# 匹配"旁白:"后面的方括号内容
|
|
dialogue_pattern = r'旁白:\s*\[([^\[\]]*?)\]'
|
|
dialogue_matches = re.findall(dialogue_pattern, text)
|
|
|
|
# 如果没有找到旁白,尝试匹配其他可能的格式
|
|
if not dialogue_matches:
|
|
# 尝试匹配没有方括号的格式
|
|
alt_pattern = r'旁白:\s*([^\[\]\n]*?)(?:\n|$)'
|
|
dialogue_matches = re.findall(alt_pattern, text)
|
|
|
|
dialogues = []
|
|
for dialogue in dialogue_matches:
|
|
# 去除开头和结尾的空白字符
|
|
dialogue = dialogue.strip()
|
|
if dialogue: # 如果不是空字符串
|
|
dialogues.append(dialogue)
|
|
|
|
# 生成总结信息
|
|
summary = f"提取了{len(dialogues)}条旁白/对白。"
|
|
|
|
return (dialogues, summary)
|
|
|
|
# 节点映射字典,用于 ComfyUI 注册节点
|
|
NODE_CLASS_MAPPINGS = {
|
|
"DialogueExtractor": DialogueExtractorNode
|
|
}
|
|
|
|
# 节点显示名称映射,用于在 UI 中显示友好名称
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
"DialogueExtractor": "对白提取器 / Dialogue Extractor"
|
|
} |