|
|
@@ -2960,68 +2960,90 @@ function handleScriptContentForAce($originalContent) {
|
|
|
$parts['episode_title'] = '';
|
|
|
$parts['acts'] = [];
|
|
|
|
|
|
- // 单剧集格式:顶层是大纲信息,分镜部分采用 handleEpisodeContent 的结构标准
|
|
|
+ // 单剧集格式:顶层是大纲信息,分段部分采用 handleEpisodeContentForAce 的结构标准
|
|
|
$singleStoryboard = '';
|
|
|
if (preg_match('/###\s*分镜剧本\s*\n(.*?)(?=\n\s*###[^#]|\z)/su', $originalContent, $singleStoryboardMatch)) {
|
|
|
$singleStoryboard = trim($singleStoryboardMatch[1]);
|
|
|
+ } elseif (preg_match('/###\s*分段剧本\s*\n(.*?)(?=\n\s*###[^#]|\z)/su', $originalContent, $singleStoryboardMatch)) {
|
|
|
+ $singleStoryboard = trim($singleStoryboardMatch[1]);
|
|
|
}
|
|
|
|
|
|
if ($singleStoryboard !== '') {
|
|
|
- $episodeContent = $singleStoryboard;
|
|
|
- if (!preg_match('/第\d+集[::\s]+/u', $episodeContent)) {
|
|
|
+ // 构造符合 handleEpisodeContentForAce 期望的输入格式
|
|
|
+ $episodeContent = '';
|
|
|
+
|
|
|
+ // 如果分镜剧本内容不包含剧集标题,添加默认标题
|
|
|
+ if (!preg_match('/第\d+集[::\s]+/u', $singleStoryboard)) {
|
|
|
$defaultEpisodeTitle = '第1集:' . ($parts['script_name'] ?? '未命名');
|
|
|
- $episodeContent = $defaultEpisodeTitle . "\n\n" . $episodeContent;
|
|
|
+ $episodeContent = $defaultEpisodeTitle . "\n\n";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ // 组装完整的剧集内容,按 handleEpisodeContentForAce 期望的结构
|
|
|
$episodeSections = [];
|
|
|
- $episodeSections[] = $episodeContent;
|
|
|
- if ($parts['intro'] !== '') {
|
|
|
+
|
|
|
+ // 添加故事梗概(如果有)
|
|
|
+ if (!empty($parts['intro'])) {
|
|
|
$episodeSections[] = "###故事梗概\n" . $parts['intro'];
|
|
|
}
|
|
|
- if ($parts['art_style'] !== '') {
|
|
|
+
|
|
|
+ // 添加美术风格(如果有)
|
|
|
+ if (!empty($parts['art_style'])) {
|
|
|
$episodeSections[] = "###美术风格\n" . $parts['art_style'];
|
|
|
}
|
|
|
- if ($rolesText !== '') {
|
|
|
+
|
|
|
+ // 添加主体列表(如果有)
|
|
|
+ if (!empty($rolesText)) {
|
|
|
$episodeSections[] = "###主体列表\n" . $rolesText;
|
|
|
}
|
|
|
- if ($scenesText !== '') {
|
|
|
+
|
|
|
+ // 添加场景列表(如果有)
|
|
|
+ if (!empty($scenesText)) {
|
|
|
$episodeSections[] = "###场景列表\n" . $scenesText;
|
|
|
}
|
|
|
- if (strpos($episodeContent, '###分镜剧本') === false) {
|
|
|
+
|
|
|
+ // 添加分镜剧本内容(兼容"分镜剧本"和"分段剧本")
|
|
|
+ if (strpos($singleStoryboard, '###分镜剧本') === false && strpos($singleStoryboard, '###分段剧本') === false) {
|
|
|
$episodeSections[] = "###分镜剧本\n" . $singleStoryboard;
|
|
|
+ } else {
|
|
|
+ $episodeSections[] = $singleStoryboard;
|
|
|
}
|
|
|
-
|
|
|
- $episode_arr = handleEpisodeContentForAce(implode("\n\n", $episodeSections));
|
|
|
+
|
|
|
+ // 拼接完整内容
|
|
|
+ $episodeContent .= implode("\n\n", $episodeSections);
|
|
|
+
|
|
|
+ // 调用 handleEpisodeContentForAce 方法解析
|
|
|
+ $episode_arr = handleEpisodeContentForAce($episodeContent);
|
|
|
+
|
|
|
if (!empty($episode_arr['acts'])) {
|
|
|
- $parts['episode_title'] = getProp($episode_arr, 'episode_title');
|
|
|
+ $parts['episode_title'] = getProp($episode_arr, 'episode_title', '');
|
|
|
$parts['acts'] = getProp($episode_arr, 'acts', []);
|
|
|
- if (empty($parts['roles'])) {
|
|
|
- $parts['roles'] = getProp($episode_arr, 'roles', []);
|
|
|
- }
|
|
|
- if (empty($parts['scenes'])) {
|
|
|
- $parts['scenes'] = getProp($episode_arr, 'scenes', []);
|
|
|
- }
|
|
|
}
|
|
|
+
|
|
|
+ // 更新roles和scenes
|
|
|
+ $episode_roles = getProp($episode_arr, 'roles');
|
|
|
+ $episode_scenes = getProp($episode_arr, 'scenes');
|
|
|
+ if ($episode_roles) $parts['roles'] = $episode_roles;
|
|
|
+ if ($episode_scenes) $parts['scenes'] = $episode_scenes;
|
|
|
}
|
|
|
|
|
|
+ // 如果上面的处理没有得到 acts,尝试直接用原始内容调用 handleEpisodeContentForAce
|
|
|
if (empty($parts['acts'])) {
|
|
|
$fallbackEpisodeArr = handleEpisodeContentForAce($originalContent);
|
|
|
if (!empty($fallbackEpisodeArr['acts'])) {
|
|
|
- $parts['episode_title'] = getProp($fallbackEpisodeArr, 'episode_title');
|
|
|
+ $parts['episode_title'] = getProp($fallbackEpisodeArr, 'episode_title', '');
|
|
|
$parts['acts'] = getProp($fallbackEpisodeArr, 'acts', []);
|
|
|
if (empty($parts['intro'])) {
|
|
|
- $parts['intro'] = getProp($fallbackEpisodeArr, 'intro');
|
|
|
+ $parts['intro'] = getProp($fallbackEpisodeArr, 'intro', '');
|
|
|
}
|
|
|
if (empty($parts['art_style'])) {
|
|
|
- $parts['art_style'] = getProp($fallbackEpisodeArr, 'art_style');
|
|
|
- }
|
|
|
- if (empty($parts['roles'])) {
|
|
|
- $parts['roles'] = getProp($fallbackEpisodeArr, 'roles', []);
|
|
|
- }
|
|
|
- if (empty($parts['scenes'])) {
|
|
|
- $parts['scenes'] = getProp($fallbackEpisodeArr, 'scenes', []);
|
|
|
+ $parts['art_style'] = getProp($fallbackEpisodeArr, 'art_style', '');
|
|
|
}
|
|
|
}
|
|
|
+ // 更新roles和scenes
|
|
|
+ $episode_roles = getProp($fallbackEpisodeArr, 'roles');
|
|
|
+ $episode_scenes = getProp($fallbackEpisodeArr, 'scenes');
|
|
|
+ if ($episode_roles) $parts['roles'] = $episode_roles;
|
|
|
+ if ($episode_scenes) $parts['scenes'] = $episode_scenes;
|
|
|
}
|
|
|
|
|
|
// 多剧集格式:继续兼容旧的分集剧本结构
|
|
|
@@ -3305,33 +3327,31 @@ function handleEpisodeContentForAce($originalContent) {
|
|
|
|
|
|
// 如果有主体图片提示词,添加到数组中
|
|
|
if ($picPrompt) {
|
|
|
- // // 检查开头是否有"写实,全景,正面拍摄。"
|
|
|
- // $prefix = '写实,全景,正面拍摄。';
|
|
|
- // $prefixParts = ['写实', '全景', '正面拍摄'];
|
|
|
+ // 检查开头是否有"全景,正面拍摄。"
|
|
|
+ $prefix = '全景,正面拍摄。';
|
|
|
+ $prefixParts = ['全景', '正面拍摄'];
|
|
|
|
|
|
- // // 检查是否包含完整前缀
|
|
|
- // if (strpos($picPrompt, $prefix) !== 0) {
|
|
|
- // // 检查是否包含部分前缀词汇(不论位置)
|
|
|
- // $hasPartialPrefix = false;
|
|
|
- // foreach ($prefixParts as $part) {
|
|
|
- // if (mb_strpos($picPrompt, $part) !== false) {
|
|
|
- // $hasPartialPrefix = true;
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
+ // 检查是否包含完整前缀
|
|
|
+ if (strpos($picPrompt, $prefix) !== 0) {
|
|
|
+ // 检查是否包含部分前缀词汇(不论位置)
|
|
|
+ $hasAnyPrefix = false;
|
|
|
+ foreach ($prefixParts as $part) {
|
|
|
+ if (mb_strpos($picPrompt, $part) !== false) {
|
|
|
+ $hasAnyPrefix = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // if ($hasPartialPrefix) {
|
|
|
- // // 移除开头的所有前缀词汇(包括它们后面的标点)
|
|
|
- // $picPrompt = preg_replace('/^(写实[,,、。. ]*|全景[,,、。. ]*|正面拍摄[,,、。. ]*)+/u', '', $picPrompt);
|
|
|
- // // 清理开头和结尾的标点符号和空格
|
|
|
- // $picPrompt = preg_replace('/^[。,,、 ]+|[。,,、 ]+$/u', '', $picPrompt);
|
|
|
- // // 添加完整前缀
|
|
|
- // $picPrompt = $prefix . $picPrompt;
|
|
|
- // } else {
|
|
|
- // // 如果没有前缀,直接在开头添加
|
|
|
- // $picPrompt = $prefix . $picPrompt;
|
|
|
- // }
|
|
|
- // }
|
|
|
+ if ($hasAnyPrefix) {
|
|
|
+ // 移除所有"全景"和"正面拍摄"词汇(包括它们后面的标点)
|
|
|
+ $picPrompt = preg_replace('/全景[,,、。. ]*/u', '', $picPrompt);
|
|
|
+ $picPrompt = preg_replace('/正面拍摄[,,、。. ]*/u', '', $picPrompt);
|
|
|
+ // 清理开头和结尾的标点符号和空格
|
|
|
+ $picPrompt = preg_replace('/^[。,,、 ]+|[。,,、 ]+$/u', '', $picPrompt);
|
|
|
+ }
|
|
|
+ // 在开头添加完整前缀
|
|
|
+ $picPrompt = $prefix . $picPrompt;
|
|
|
+ }
|
|
|
|
|
|
// 检查是否包含"姿态:"或"姿态:"
|
|
|
if (preg_match('/姿态[::]/u', $picPrompt)) {
|