|
|
@@ -54,6 +54,7 @@ class FixNewVideoTasks720pCommand extends Command
|
|
|
->select([
|
|
|
'id', 'video_resolution', 'status', 'api_type',
|
|
|
'alias_segment_id', 'alias_act_id', 'task_id', 'result_url', 'compressed_url',
|
|
|
+ 'extra_params', 'charge_info',
|
|
|
])
|
|
|
->where('id', '>=', $minId)
|
|
|
// 仅处理 480p 任务;task_id 为空 = 用户手动上传的视频,不处理
|
|
|
@@ -165,59 +166,68 @@ class FixNewVideoTasks720pCommand extends Command
|
|
|
$alreadyOk++;
|
|
|
}
|
|
|
|
|
|
- if (!$needChange) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
if ($apply) {
|
|
|
- DB::table('mp_generate_video_tasks')
|
|
|
- ->where('id', $task->id)
|
|
|
- ->update([
|
|
|
- 'result_url' => $newResult,
|
|
|
- 'compressed_url' => $newCompressed,
|
|
|
- ]);
|
|
|
-
|
|
|
- $segmentSynced = $this->syncSegmentUrls($task, $newResult, $newCompressed);
|
|
|
- $recordSynced = $this->syncAnimeRecordUrls($task, $newResult);
|
|
|
-
|
|
|
- // 只更新不新增;完全没有 assistant 记录时需要即时通知人工确认
|
|
|
- if ($recordSynced === 0) {
|
|
|
- $assistantTotal = DB::table('mp_anime_records')
|
|
|
- ->where('video_task_id', $task->id)
|
|
|
- ->where('role', 'assistant')
|
|
|
- ->count();
|
|
|
- if ($assistantTotal === 0) {
|
|
|
- $notice = sprintf(
|
|
|
- '任务#%d 在 mp_anime_records 中完全没有 assistant 记录(只更新不新增),请人工确认是否需要补录',
|
|
|
- $task->id
|
|
|
- );
|
|
|
- $this->warn($notice);
|
|
|
- dLog('command')->warning($notice, [
|
|
|
- 'task_id' => $task->id,
|
|
|
- 'old_result_url' => $task->result_url,
|
|
|
- 'new_result_url' => $newResult,
|
|
|
- ]);
|
|
|
- logDB('command', 'warning', $notice, [
|
|
|
- 'task_id' => $task->id,
|
|
|
- 'old_result_url' => $task->result_url,
|
|
|
- 'new_result_url' => $newResult,
|
|
|
- ]);
|
|
|
- } else {
|
|
|
- $this->warn(sprintf(
|
|
|
- '任务#%d 有 %d 条 assistant 记录但均未指向旧 result_url,跳过 anime_records 同步',
|
|
|
- $task->id,
|
|
|
- $assistantTotal
|
|
|
- ));
|
|
|
- }
|
|
|
+ $updates = $this->buildSr720pUpdates($task);
|
|
|
+ $urlChanged = false;
|
|
|
+
|
|
|
+ // 超分/重压成功时同时替换 URL
|
|
|
+ if ($needChange) {
|
|
|
+ $urlChanged = true;
|
|
|
+ $updates['result_url'] = $newResult;
|
|
|
+ $updates['compressed_url'] = $newCompressed;
|
|
|
}
|
|
|
|
|
|
- $this->line(sprintf(
|
|
|
- '#%d 已更新任务 URL(分镜同步:%s;anime_records 同步:%d 条)',
|
|
|
- $task->id,
|
|
|
- $segmentSynced ? '是' : '跳过/无关联',
|
|
|
- $recordSynced
|
|
|
- ));
|
|
|
- $updated++;
|
|
|
+ if (!empty($updates)) {
|
|
|
+ DB::table('mp_generate_video_tasks')
|
|
|
+ ->where('id', $task->id)
|
|
|
+ ->update($updates);
|
|
|
+ $updated++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($urlChanged) {
|
|
|
+ $segmentSynced = $this->syncSegmentUrls($task, $newResult, $newCompressed);
|
|
|
+ $recordSynced = $this->syncAnimeRecordUrls($task, $newResult);
|
|
|
+
|
|
|
+ // 只更新不新增;完全没有 assistant 记录时需要即时通知人工确认
|
|
|
+ if ($recordSynced === 0) {
|
|
|
+ $assistantTotal = DB::table('mp_anime_records')
|
|
|
+ ->where('video_task_id', $task->id)
|
|
|
+ ->where('role', 'assistant')
|
|
|
+ ->count();
|
|
|
+ if ($assistantTotal === 0) {
|
|
|
+ $notice = sprintf(
|
|
|
+ '任务#%d 在 mp_anime_records 中完全没有 assistant 记录(只更新不新增),请人工确认是否需要补录',
|
|
|
+ $task->id
|
|
|
+ );
|
|
|
+ $this->warn($notice);
|
|
|
+ dLog('command')->warning($notice, [
|
|
|
+ 'task_id' => $task->id,
|
|
|
+ 'old_result_url' => $task->result_url,
|
|
|
+ 'new_result_url' => $newResult,
|
|
|
+ ]);
|
|
|
+ logDB('command', 'warning', $notice, [
|
|
|
+ 'task_id' => $task->id,
|
|
|
+ 'old_result_url' => $task->result_url,
|
|
|
+ 'new_result_url' => $newResult,
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ $this->warn(sprintf(
|
|
|
+ '任务#%d 有 %d 条 assistant 记录但均未指向旧 result_url,跳过 anime_records 同步',
|
|
|
+ $task->id,
|
|
|
+ $assistantTotal
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->line(sprintf(
|
|
|
+ '#%d 已更新任务 URL 与 sr_720p 档位(分镜同步:%s;anime_records 同步:%d 条)',
|
|
|
+ $task->id,
|
|
|
+ $segmentSynced ? '是' : '跳过/无关联',
|
|
|
+ $recordSynced
|
|
|
+ ));
|
|
|
+ } else {
|
|
|
+ $this->line(sprintf('#%d 视频已合格,仅将任务档位与 JSON 副本更新为 sr_720p', $task->id));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -322,6 +332,76 @@ class FixNewVideoTasks720pCommand extends Command
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 构建将任务档位与 JSON 副本统一为 sr_720p 的更新数组
|
|
|
+ * video_resolution=480p -> sr_720p;extra_params / charge_info 中对应 480p 值同步替换
|
|
|
+ *
|
|
|
+ * @param object $task
|
|
|
+ * @return array 需要更新的字段;无变化返回空数组
|
|
|
+ */
|
|
|
+ private function buildSr720pUpdates($task): array
|
|
|
+ {
|
|
|
+ $updates = [];
|
|
|
+
|
|
|
+ $current = strtolower(trim((string)($task->video_resolution ?? '')));
|
|
|
+ if ($current !== 'sr_720p') {
|
|
|
+ $updates['video_resolution'] = 'sr_720p';
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (['extra_params' => true, 'charge_info' => false] as $column => $isExtra) {
|
|
|
+ $raw = $task->{$column} ?? null;
|
|
|
+ if (empty($raw)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $json = json_decode($raw, true);
|
|
|
+ if (!is_array($json)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ($this->normalize480ToSr720p($json, $isExtra)) {
|
|
|
+ $updates[$column] = json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $updates;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将 JSON 内 480p 分辨率副本替换为 sr_720p
|
|
|
+ * extra_params:顶层 video_resolution / resolution 及 parameters.resolution;
|
|
|
+ * charge_info:顶层 video_resolution
|
|
|
+ *
|
|
|
+ * @param array $json
|
|
|
+ * @param bool $isExtra
|
|
|
+ * @return bool 是否发生修改
|
|
|
+ */
|
|
|
+ private function normalize480ToSr720p(array &$json, bool $isExtra): bool
|
|
|
+ {
|
|
|
+ $changed = false;
|
|
|
+
|
|
|
+ $fix = function (array &$arr, string $key) use (&$changed) {
|
|
|
+ if (array_key_exists($key, $arr)
|
|
|
+ && is_string($arr[$key])
|
|
|
+ && strtolower(trim($arr[$key])) === '480p'
|
|
|
+ && $arr[$key] !== 'sr_720p') {
|
|
|
+ $arr[$key] = 'sr_720p';
|
|
|
+ $changed = true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ if ($isExtra) {
|
|
|
+ foreach (['video_resolution', 'resolution'] as $key) {
|
|
|
+ $fix($json, $key);
|
|
|
+ }
|
|
|
+ if (isset($json['parameters']) && is_array($json['parameters'])) {
|
|
|
+ $fix($json['parameters'], 'resolution');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $fix($json, 'video_resolution');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $changed;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 同步 mp_anime_records 中 assistant 对话记录的 video_url
|
|
|
* 仅更新 video_task_id 匹配、role=assistant 且 video_url 仍指向该任务旧 result_url 的行,
|
|
|
* 避免覆盖同 act 其他任务写入的记录。
|