|
|
@@ -2153,7 +2153,8 @@ function handleScriptContent($originalContent) {
|
|
|
|
|
|
// 提取主体列表
|
|
|
preg_match('/###主体列表\s*\n(.*?)(?=\n###|$)/s', $originalContent, $subjectsMatch);
|
|
|
- $parts['roles'] = isset($subjectsMatch[1]) ? trim($subjectsMatch[1]) : '';
|
|
|
+ $rolesText = isset($subjectsMatch[1]) ? trim($subjectsMatch[1]) : '';
|
|
|
+ $parts['roles'] = parseRolesFromText($rolesText);
|
|
|
|
|
|
// 提取美术风格
|
|
|
preg_match('/###美术风格\s*\n(.*?)(?=\n###|$)/s', $originalContent, $artStyleMatch);
|
|
|
@@ -2161,7 +2162,8 @@ function handleScriptContent($originalContent) {
|
|
|
|
|
|
// 提取场景列表
|
|
|
preg_match('/###场景列表\s*\n(.*?)(?=\n###|$)/s', $originalContent, $scenesMatch);
|
|
|
- $parts['scenes'] = isset($scenesMatch[1]) ? trim($scenesMatch[1]) : '';
|
|
|
+ $scenesText = isset($scenesMatch[1]) ? trim($scenesMatch[1]) : '';
|
|
|
+ $parts['scenes'] = parseScenesFromText($scenesText);
|
|
|
|
|
|
// 提取分集剧本并按分集拆分
|
|
|
preg_match('/###分集剧本\s*\n(.*)/s', $originalContent, $storyboardMatch);
|
|
|
@@ -2501,3 +2503,85 @@ function safeDestroyImage(&$img)
|
|
|
|
|
|
// return null;
|
|
|
// }
|
|
|
+
|
|
|
+/**
|
|
|
+ * 将主体列表文本拆分为主体数组
|
|
|
+ *
|
|
|
+ * @param string $rolesText 主体列表文本内容
|
|
|
+ * @return array 主体名称数组
|
|
|
+ */
|
|
|
+function parseRolesFromText(string $rolesText): array
|
|
|
+{
|
|
|
+ if (empty($rolesText)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $roles = [];
|
|
|
+
|
|
|
+ // 按行分割文本
|
|
|
+ $lines = explode("\n", $rolesText);
|
|
|
+
|
|
|
+ foreach ($lines as $line) {
|
|
|
+ $line = trim($line);
|
|
|
+ if (empty($line)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 匹配格式:角色名-描述:详细信息
|
|
|
+ // 例如:许芸-重生者:18岁少女,原许家假千金...
|
|
|
+ if (preg_match('/^([^::]+)[::]/', $line, $matches)) {
|
|
|
+ $roleName = trim($matches[1]);
|
|
|
+
|
|
|
+ // 如果角色名包含"-",取"-"前面的部分作为主要角色名
|
|
|
+ if (strpos($roleName, '-') !== false) {
|
|
|
+ $parts = explode('-', $roleName);
|
|
|
+ $mainRole = trim($parts[0]);
|
|
|
+ if (!empty($mainRole) && !in_array($mainRole, $roles)) {
|
|
|
+ $roles[] = $mainRole;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!in_array($roleName, $roles)) {
|
|
|
+ $roles[] = $roleName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $roles;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 将场景列表文本拆分为场景数组
|
|
|
+ *
|
|
|
+ * @param string $scenesText 场景列表文本内容
|
|
|
+ * @return array 场景名称数组
|
|
|
+ */
|
|
|
+function parseScenesFromText(string $scenesText): array
|
|
|
+{
|
|
|
+ if (empty($scenesText)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $scenes = [];
|
|
|
+
|
|
|
+ // 按行分割文本
|
|
|
+ $lines = explode("\n", $scenesText);
|
|
|
+
|
|
|
+ foreach ($lines as $line) {
|
|
|
+ $line = trim($line);
|
|
|
+ if (empty($line)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 匹配格式:场景名:描述信息
|
|
|
+ // 例如:徐家馄饨店:老旧街边小店,锅炉、案板杂乱...
|
|
|
+ if (preg_match('/^([^::]+)[::]/', $line, $matches)) {
|
|
|
+ $sceneName = trim($matches[1]);
|
|
|
+ if (!empty($sceneName) && !in_array($sceneName, $scenes)) {
|
|
|
+ $scenes[] = $sceneName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $scenes;
|
|
|
+}
|