@clipen/clipen-cli 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -50
- package/package.json +7 -4
- package/pyproject.toml +18 -2
- package/requirements/dev.txt +2 -0
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/__init__.py +7 -7
- package/src/clipen/analysis/artifacts.py +4 -10
- package/src/clipen/analysis/audio.py +10 -8
- package/src/clipen/analysis/evidence_service.py +345 -167
- package/src/clipen/analysis/image_similarity.py +5 -14
- package/src/clipen/analysis/keyframes.py +5 -17
- package/src/clipen/analysis/models.py +5 -7
- package/src/clipen/analysis/qwen_worker.py +19 -54
- package/src/clipen/analysis/resources.py +2 -1
- package/src/clipen/analysis/runtime.py +1 -3
- package/src/clipen/analysis/service.py +16 -48
- package/src/clipen/analysis/setup.py +11 -25
- package/src/clipen/analysis/setup_cli.py +5 -15
- package/src/clipen/analysis/storage.py +96 -278
- package/src/clipen/analysis/transcription.py +40 -82
- package/src/clipen/analysis/visual.py +109 -48
- package/src/clipen/annotations/__init__.py +5 -2
- package/src/clipen/annotations/models.py +1 -1
- package/src/clipen/annotations/storage.py +132 -84
- package/src/clipen/annotations/suggestions.py +3 -8
- package/src/clipen/asr_release.py +4 -11
- package/src/clipen/bootstrap.py +65 -54
- package/src/clipen/{planning/models.py → candidates.py} +29 -47
- package/src/clipen/cli.py +2 -2
- package/src/clipen/controller/app.py +401 -214
- package/src/clipen/controller/server.py +28 -38
- package/src/clipen/domain/__init__.py +1 -1
- package/src/clipen/domain/media_time.py +3 -10
- package/src/clipen/domain/timeline.py +45 -47
- package/src/clipen/domain/validation.py +0 -1
- package/src/clipen/editing/__init__.py +1 -1
- package/src/clipen/editing/agent_models.py +4 -11
- package/src/clipen/editing/agent_repository.py +391 -170
- package/src/clipen/editing/agent_tools.py +180 -99
- package/src/clipen/editing/alignment.py +92 -52
- package/src/clipen/editing/alignment_setup.py +118 -70
- package/src/clipen/editing/alignment_worker.py +11 -9
- package/src/clipen/editing/change_report.py +95 -38
- package/src/clipen/editing/compiler.py +0 -1
- package/src/clipen/editing/component_looks.py +58 -34
- package/src/clipen/editing/component_review.py +34 -38
- package/src/clipen/editing/coordinator.py +213 -90
- package/src/clipen/editing/editorial_review.py +217 -95
- package/src/clipen/editing/evidence_jobs.py +457 -200
- package/src/clipen/editing/history_changes.py +129 -68
- package/src/clipen/editing/music_choices.py +8 -5
- package/src/clipen/editing/production_catalog.py +573 -136
- package/src/clipen/editing/production_limits.py +43 -17
- package/src/clipen/editing/production_media.py +376 -167
- package/src/clipen/editing/production_preview.py +322 -129
- package/src/clipen/editing/production_progress.py +164 -69
- package/src/clipen/editing/production_requirements.py +106 -39
- package/src/clipen/editing/production_tools.py +1064 -462
- package/src/clipen/editing/program_audio.py +211 -81
- package/src/clipen/editing/program_direction.py +59 -25
- package/src/clipen/editing/program_story.py +83 -45
- package/src/clipen/editing/program_subtitles.py +194 -96
- package/src/clipen/editing/programme_review.py +98 -50
- package/src/clipen/editing/prompt_history.py +64 -27
- package/src/clipen/editing/recut.py +65 -25
- package/src/clipen/editing/refinement_references.py +176 -86
- package/src/clipen/editing/resolve_export.py +449 -218
- package/src/clipen/editing/resolve_titles.py +162 -105
- package/src/clipen/editing/skill_tools.py +530 -154
- package/src/clipen/editing/source_dialogue.py +177 -67
- package/src/clipen/editing/speech_coverage.py +42 -22
- package/src/clipen/editing/speech_quality.py +6 -1
- package/src/clipen/editing/tool_receipts.py +78 -32
- package/src/clipen/editing/versions.py +122 -64
- package/src/clipen/editing/visual_preview.py +157 -61
- package/src/clipen/editing/workbench.py +104 -42
- package/src/clipen/finishing/audio.py +69 -30
- package/src/clipen/finishing/catalog.py +176 -93
- package/src/clipen/finishing/models.py +1 -1
- package/src/clipen/finishing/renderer.py +33 -14
- package/src/clipen/mcp_editing/__main__.py +3 -1
- package/src/clipen/mcp_editing/server.py +77 -34
- package/src/clipen/media/__init__.py +3 -3
- package/src/clipen/media/discovery.py +7 -20
- package/src/clipen/media/models.py +7 -18
- package/src/clipen/media/preview.py +14 -24
- package/src/clipen/media/probe.py +16 -44
- package/src/clipen/media/service.py +6 -19
- package/src/clipen/media/storage.py +33 -81
- package/src/clipen/music_vocabulary.py +33 -4
- package/src/clipen/power.py +8 -3
- package/src/clipen/projects/__init__.py +1 -1
- package/src/clipen/projects/deletion.py +19 -32
- package/src/clipen/projects/finishing_schema.py +3 -1
- package/src/clipen/projects/models.py +2 -5
- package/src/clipen/projects/picker.py +13 -37
- package/src/clipen/projects/service.py +8 -24
- package/src/clipen/projects/storage.py +226 -246
- package/src/clipen/provider_registry.py +4 -2
- package/src/clipen/providers/account.py +86 -35
- package/src/clipen/providers/claude.py +59 -25
- package/src/clipen/providers/claude_editing.py +14 -7
- package/src/clipen/providers/codex.py +73 -118
- package/src/clipen/providers/codex_editing.py +2 -2
- package/src/clipen/providers/editing_agent.py +19 -17
- package/src/clipen/providers/recovery.py +7 -8
- package/src/clipen/rendering/cover.py +18 -5
- package/src/clipen/rendering/custom_components.py +167 -79
- package/src/clipen/rendering/custom_render.py +62 -41
- package/src/clipen/rendering/production_effects.py +77 -45
- package/src/clipen/rendering/program_components.py +134 -73
- package/src/clipen/rendering/program_creator.py +432 -277
- package/src/clipen/rendering/program_identities.py +277 -182
- package/src/clipen/rendering/program_motion.py +140 -95
- package/src/clipen/rendering/program_studio.py +175 -116
- package/src/clipen/rendering/program_styles.py +231 -145
- package/src/clipen/rendering/program_subtitles.py +71 -34
- package/src/clipen/rendering/renderer.py +150 -121
- package/src/clipen/rendering/storage.py +9 -22
- package/src/clipen/rendering/titles.py +193 -86
- package/src/clipen/skills/__init__.py +1 -0
- package/src/clipen/skills/catalog.py +151 -55
- package/src/clipen/skills/library.py +13 -7
- package/src/clipen/skills/package.py +46 -23
- package/src/clipen/skills/visual_styles.py +29 -18
- package/src/clipen/workspace.py +15 -44
- package/src/clipen/planning/__init__.py +0 -9
|
@@ -1,180 +1,373 @@
|
|
|
1
1
|
"""Revision-bound render/review tools; no model-visible filesystem handles."""
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import hashlib
|
|
4
|
+
import json
|
|
4
5
|
import os
|
|
5
|
-
import sys
|
|
6
6
|
import secrets
|
|
7
|
-
|
|
7
|
+
import sys
|
|
8
8
|
import threading
|
|
9
9
|
import time
|
|
10
|
+
from pathlib import Path
|
|
10
11
|
|
|
12
|
+
from clipen.finishing.audio import run_process
|
|
13
|
+
from clipen.finishing.renderer import verify_output
|
|
14
|
+
from clipen.media import MediaPreviewRepository
|
|
11
15
|
from clipen.projects import ProjectError
|
|
12
16
|
from clipen.projects.storage import utc_now
|
|
13
17
|
from clipen.rendering import FfmpegPreviewRenderer, PreviewRenderRepository
|
|
14
|
-
|
|
15
|
-
from clipen.finishing.audio import run_process
|
|
16
|
-
from clipen.finishing.renderer import verify_output
|
|
18
|
+
|
|
17
19
|
from .agent_models import ToolResult
|
|
18
20
|
|
|
19
21
|
|
|
20
|
-
def _event(tools,kind,payload):
|
|
22
|
+
def _event(tools, kind, payload):
|
|
21
23
|
with tools.repository.projects.connect(tools.project_id) as db:
|
|
22
|
-
tools.repository._append_event(db,tools.run_id,kind,payload,utc_now())
|
|
24
|
+
tools.repository._append_event(db, tools.run_id, kind, payload, utc_now())
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
def render_recipe_id():
|
|
26
28
|
"""Cache executable rendering code as well as the immutable edit payload."""
|
|
27
|
-
from clipen.rendering import
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
from clipen.rendering import (
|
|
30
|
+
production_effects,
|
|
31
|
+
program_components,
|
|
32
|
+
program_identities,
|
|
33
|
+
program_motion,
|
|
34
|
+
program_studio,
|
|
35
|
+
program_styles,
|
|
36
|
+
program_subtitles,
|
|
37
|
+
renderer,
|
|
38
|
+
titles,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
from . import production_media, program_audio
|
|
42
|
+
|
|
43
|
+
digest = hashlib.sha256()
|
|
44
|
+
for module in (
|
|
45
|
+
renderer,
|
|
46
|
+
titles,
|
|
47
|
+
program_components,
|
|
48
|
+
program_motion,
|
|
49
|
+
program_styles,
|
|
50
|
+
program_studio,
|
|
51
|
+
program_identities,
|
|
52
|
+
program_subtitles,
|
|
53
|
+
production_effects,
|
|
54
|
+
program_audio,
|
|
55
|
+
production_media,
|
|
56
|
+
):
|
|
31
57
|
digest.update(Path(module.__file__).read_bytes())
|
|
32
58
|
return digest.hexdigest()
|
|
33
59
|
|
|
34
60
|
|
|
35
61
|
def render_preview(tools):
|
|
36
|
-
revision=tools.repository.current_revision(tools.project_id,tools.run_id)
|
|
37
|
-
recipe_id=render_recipe_id()
|
|
38
|
-
validation=tools._production_validate_sequence({}).payload
|
|
39
|
-
issues=validation[
|
|
40
|
-
if issues:
|
|
41
|
-
|
|
62
|
+
revision = tools.repository.current_revision(tools.project_id, tools.run_id)
|
|
63
|
+
recipe_id = render_recipe_id()
|
|
64
|
+
validation = tools._production_validate_sequence({}).payload
|
|
65
|
+
issues = validation["render_issues"]
|
|
66
|
+
if issues:
|
|
67
|
+
raise ProjectError("agent_sequence_invalid", "請先使用 validate_sequence 修正時間軸。", status_code=422)
|
|
68
|
+
store = PreviewRenderRepository(tools.repository.projects)
|
|
42
69
|
# The exact revision is the cache key. Polling/reviewing never rerenders it.
|
|
43
70
|
with tools.repository.projects.connect(tools.project_id) as db:
|
|
44
|
-
prior=db.execute(
|
|
71
|
+
prior = db.execute(
|
|
72
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='production_preview' ORDER BY sequence DESC",
|
|
73
|
+
(tools.run_id,),
|
|
74
|
+
).fetchall()
|
|
45
75
|
for row in prior:
|
|
46
|
-
entry=json.loads(row[
|
|
47
|
-
if entry[
|
|
48
|
-
saved=store.get(tools.project_id,entry[
|
|
49
|
-
if saved[
|
|
50
|
-
return ToolResult({
|
|
51
|
-
current=store.current(tools.project_id)
|
|
52
|
-
if current and current[
|
|
53
|
-
mine=current[
|
|
54
|
-
raise ProjectError(
|
|
55
|
-
|
|
76
|
+
entry = json.loads(row["payload_json"])
|
|
77
|
+
if entry["revision_id"] == revision.revision_id and entry.get("recipe_id") == recipe_id:
|
|
78
|
+
saved = store.get(tools.project_id, entry["render_id"])
|
|
79
|
+
if saved["state"] in {"queued", "running", "succeeded"}:
|
|
80
|
+
return ToolResult({"render": saved, "revision_id": revision.revision_id, "reused": True})
|
|
81
|
+
current = store.current(tools.project_id)
|
|
82
|
+
if current and current["state"] in {"queued", "running", "cancelling"}:
|
|
83
|
+
mine = current["render_id"] in {json.loads(r["payload_json"])["render_id"] for r in prior}
|
|
84
|
+
raise ProjectError(
|
|
85
|
+
"preview_busy",
|
|
86
|
+
f"目前有預覽正在合成({current['render_id']},進度 {round(current.get('progress', 0) * 100)}%)。"
|
|
87
|
+
+ (
|
|
88
|
+
"這是本次製作的輸出:用 inspect_preview 等它完成,或用 cancel_preview 取消後再輸出。"
|
|
89
|
+
if mine
|
|
90
|
+
else "這是使用者或其他工作的輸出,請稍後再試。"
|
|
91
|
+
),
|
|
92
|
+
status_code=409,
|
|
93
|
+
)
|
|
56
94
|
with tools.repository.projects.connect(tools.project_id) as db:
|
|
57
|
-
db.execute(
|
|
58
|
-
run=tools.repository._read_run(db,tools.run_id)
|
|
59
|
-
if not getattr(tools,
|
|
60
|
-
raise ProjectError(
|
|
61
|
-
|
|
95
|
+
db.execute("BEGIN IMMEDIATE")
|
|
96
|
+
run = tools.repository._read_run(db, tools.run_id)
|
|
97
|
+
if not getattr(tools, "_user_edit", False) and run.preview_renders >= run.max_preview_renders:
|
|
98
|
+
raise ProjectError(
|
|
99
|
+
"preview_budget_exhausted",
|
|
100
|
+
"已達本次預覽上限,請使用已完成的版本或回報尚未完成的檢視。",
|
|
101
|
+
status_code=409,
|
|
102
|
+
)
|
|
103
|
+
if not getattr(tools, "_user_edit", False):
|
|
104
|
+
db.execute("UPDATE edit_agent_runs SET preview_renders=preview_renders+1 WHERE run_id=?", (tools.run_id,))
|
|
62
105
|
db.commit()
|
|
63
|
-
request_id=
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
106
|
+
request_id = (
|
|
107
|
+
("user-preview-" + secrets.token_hex(16))
|
|
108
|
+
if getattr(tools, "_user_edit", False)
|
|
109
|
+
else "agent-preview-" + tools.run_id + "-" + revision.revision_id + "-" + str(run.preview_renders + 1)
|
|
110
|
+
)
|
|
111
|
+
render = store.create(tools.project_id, request_id, revision.revision_id)
|
|
112
|
+
_event(
|
|
113
|
+
tools,
|
|
114
|
+
"production_preview",
|
|
115
|
+
{"render_id": render["render_id"], "revision_id": revision.revision_id, "recipe_id": recipe_id},
|
|
116
|
+
)
|
|
117
|
+
cancel = threading.Event()
|
|
118
|
+
if not hasattr(tools, "_preview_jobs"):
|
|
119
|
+
tools._preview_jobs = {}
|
|
120
|
+
renderer = getattr(tools, "preview_renderer", None) or FfmpegPreviewRenderer(
|
|
121
|
+
MediaPreviewRepository(tools.repository.projects), hardware_acceleration=sys.platform == "darwin"
|
|
122
|
+
)
|
|
123
|
+
|
|
69
124
|
def worker():
|
|
70
|
-
staging=final=None
|
|
125
|
+
staging = final = None
|
|
126
|
+
|
|
71
127
|
def progress(value):
|
|
72
|
-
state=tools.repository.get(tools.project_id,tools.run_id).state
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
128
|
+
state = tools.repository.get(tools.project_id, tools.run_id).state
|
|
129
|
+
if (
|
|
130
|
+
state not in {"queued", "running"} and not getattr(tools, "_user_edit", False)
|
|
131
|
+
) or tools._cancel_event().is_set():
|
|
132
|
+
cancel.set()
|
|
133
|
+
if store.get(tools.project_id, render["render_id"])["state"] == "cancelling":
|
|
134
|
+
cancel.set()
|
|
135
|
+
store.update_progress(tools.project_id, render["render_id"], value)
|
|
136
|
+
|
|
76
137
|
try:
|
|
77
|
-
staging=store.output_path(tools.project_id,render[
|
|
78
|
-
final=store.output_path(tools.project_id,render[
|
|
79
|
-
store.mark_running(tools.project_id,render[
|
|
80
|
-
renderer.render(tools.project_id,revision.timeline,staging,cancel,progress)
|
|
81
|
-
if cancel.is_set():
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
138
|
+
staging = store.output_path(tools.project_id, render["render_id"], staging=True)
|
|
139
|
+
final = store.output_path(tools.project_id, render["render_id"])
|
|
140
|
+
store.mark_running(tools.project_id, render["render_id"])
|
|
141
|
+
renderer.render(tools.project_id, revision.timeline, staging, cancel, progress)
|
|
142
|
+
if cancel.is_set():
|
|
143
|
+
raise ProjectError("user_cancelled", "已取消預覽。", status_code=409)
|
|
144
|
+
verify_output(staging, revision.timeline, cancel)
|
|
145
|
+
os.replace(staging, final)
|
|
146
|
+
final.chmod(0o600)
|
|
147
|
+
for suffix in (".music.wav", ".camera.wav", ".mix.wav", ".mix.json"):
|
|
148
|
+
stem = staging.with_suffix(suffix)
|
|
86
149
|
if stem.is_file():
|
|
87
|
-
os.replace(stem,final.with_suffix(suffix))
|
|
88
|
-
|
|
150
|
+
os.replace(stem, final.with_suffix(suffix))
|
|
151
|
+
final.with_suffix(suffix).chmod(0o600)
|
|
152
|
+
store.complete(tools.project_id, render["render_id"], "previews/" + final.name, final.stat().st_size)
|
|
89
153
|
except Exception as error:
|
|
90
|
-
_event(
|
|
91
|
-
|
|
92
|
-
|
|
154
|
+
_event(
|
|
155
|
+
tools,
|
|
156
|
+
"production_preview_failed",
|
|
157
|
+
{
|
|
158
|
+
"render_id": render["render_id"],
|
|
159
|
+
"revision_id": revision.revision_id,
|
|
160
|
+
"error_code": getattr(error, "code", "agent_render_failed"),
|
|
161
|
+
"error_type": type(error).__name__,
|
|
162
|
+
"message": getattr(error, "message", "Local render failed"),
|
|
163
|
+
},
|
|
164
|
+
)
|
|
93
165
|
if final is not None:
|
|
94
166
|
final.unlink(missing_ok=True)
|
|
95
|
-
for suffix in (
|
|
96
|
-
|
|
167
|
+
for suffix in (".music.wav", ".camera.wav", ".mix.wav", ".mix.json"):
|
|
168
|
+
final.with_suffix(suffix).unlink(missing_ok=True)
|
|
169
|
+
store.finish_unsuccessful(
|
|
170
|
+
tools.project_id,
|
|
171
|
+
render["render_id"],
|
|
172
|
+
"cancelled" if cancel.is_set() else "failed",
|
|
173
|
+
error_code=getattr(error, "code", "agent_render_failed"),
|
|
174
|
+
)
|
|
97
175
|
finally:
|
|
98
|
-
if staging is not None:staging.unlink(missing_ok=True)
|
|
99
176
|
if staging is not None:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
177
|
+
staging.unlink(missing_ok=True)
|
|
178
|
+
if staging is not None:
|
|
179
|
+
for suffix in (".music.wav", ".camera.wav", ".mix.wav", ".mix.json"):
|
|
180
|
+
staging.with_suffix(suffix).unlink(missing_ok=True)
|
|
181
|
+
|
|
182
|
+
thread = threading.Thread(target=worker, name="clipen-agent-preview", daemon=True)
|
|
183
|
+
tools._preview_jobs[render["render_id"]] = (cancel, thread)
|
|
184
|
+
thread.start()
|
|
185
|
+
return ToolResult(
|
|
186
|
+
{
|
|
187
|
+
"render": render,
|
|
188
|
+
"revision_id": revision.revision_id,
|
|
189
|
+
"reused": False,
|
|
190
|
+
"next": "inspect_preview with wait_seconds up to 30; do not call render_preview to poll",
|
|
191
|
+
}
|
|
192
|
+
)
|
|
104
193
|
|
|
105
194
|
|
|
106
|
-
def inspect_preview(tools,args):
|
|
107
|
-
store=PreviewRenderRepository(tools.repository.projects)
|
|
195
|
+
def inspect_preview(tools, args):
|
|
196
|
+
store = PreviewRenderRepository(tools.repository.projects)
|
|
108
197
|
with tools.repository.projects.connect(tools.project_id) as db:
|
|
109
|
-
entries=[
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
198
|
+
entries = [
|
|
199
|
+
json.loads(r["payload_json"])
|
|
200
|
+
for r in db.execute(
|
|
201
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='production_preview'",
|
|
202
|
+
(tools.run_id,),
|
|
203
|
+
)
|
|
204
|
+
]
|
|
205
|
+
entry = next((e for e in entries if e["render_id"] == args["render_id"]), None)
|
|
206
|
+
if entry is None:
|
|
207
|
+
raise ProjectError("preview_not_found", "預覽不屬於這次剪輯。", status_code=404)
|
|
208
|
+
deadline = time.monotonic() + args.get("wait_seconds", 0)
|
|
113
209
|
while True:
|
|
114
|
-
render=store.get(tools.project_id,args[
|
|
115
|
-
if render[
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
210
|
+
render = store.get(tools.project_id, args["render_id"])
|
|
211
|
+
if render["state"] not in {"queued", "running", "cancelling"} or time.monotonic() >= deadline:
|
|
212
|
+
break
|
|
213
|
+
tools._cancel_event().wait(min(0.2, max(0, deadline - time.monotonic())))
|
|
214
|
+
current = tools.repository.current_revision(tools.project_id, tools.run_id)
|
|
215
|
+
payload = {
|
|
216
|
+
"render": render,
|
|
217
|
+
"revision_id": entry["revision_id"],
|
|
218
|
+
"recipe_id": entry.get("recipe_id"),
|
|
219
|
+
"stale": entry["revision_id"] != current.revision_id or entry.get("recipe_id") != render_recipe_id(),
|
|
220
|
+
"coverage": "selected instants only; audio not listened to",
|
|
221
|
+
}
|
|
222
|
+
if render["state"] != "succeeded":
|
|
223
|
+
return ToolResult(payload)
|
|
224
|
+
path = store.output_path(tools.project_id, args["render_id"], prepare=False)
|
|
225
|
+
if path.is_symlink() or not path.is_file() or path.stat().st_size != render["size_bytes"]:
|
|
226
|
+
raise ProjectError("preview_missing", "預覽檔案已遺失或變更。", status_code=409)
|
|
124
227
|
with tools.repository.projects.connect(tools.project_id) as db:
|
|
125
|
-
row=db.execute(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
228
|
+
row = db.execute(
|
|
229
|
+
"SELECT payload_json FROM edit_agent_revisions WHERE revision_id=? AND run_id=?",
|
|
230
|
+
(entry["revision_id"], tools.run_id),
|
|
231
|
+
).fetchone()
|
|
232
|
+
timeline = json.loads(row["payload_json"])
|
|
233
|
+
seconds = timeline["duration_frames"] * timeline["frame_rate"]["den"] / timeline["frame_rate"]["num"]
|
|
234
|
+
if any(t >= seconds for t in args["offsets_seconds"]):
|
|
235
|
+
raise ProjectError("agent_input_invalid", "檢視時間超出預覽範圍。", status_code=422)
|
|
236
|
+
images = []
|
|
237
|
+
for n, offset in enumerate(args["offsets_seconds"]):
|
|
238
|
+
image = tools._workdir("reviews") / (args["render_id"] + "-" + str(n) + "-" + str(time.time_ns()) + ".png")
|
|
239
|
+
run_process(
|
|
240
|
+
[
|
|
241
|
+
"ffmpeg",
|
|
242
|
+
"-v",
|
|
243
|
+
"error",
|
|
244
|
+
"-nostdin",
|
|
245
|
+
"-ss",
|
|
246
|
+
str(offset),
|
|
247
|
+
"-i",
|
|
248
|
+
str(path),
|
|
249
|
+
"-frames:v",
|
|
250
|
+
"1",
|
|
251
|
+
"-vf",
|
|
252
|
+
"scale=640:-2",
|
|
253
|
+
"-threads",
|
|
254
|
+
"1",
|
|
255
|
+
str(image),
|
|
256
|
+
],
|
|
257
|
+
tools._cancel_event(),
|
|
258
|
+
timeout=30,
|
|
259
|
+
)
|
|
260
|
+
if not image.is_file():
|
|
261
|
+
raise ProjectError("preview_frame_missing", "指定時間沒有可解碼畫面。", status_code=409)
|
|
133
262
|
images.append(image)
|
|
134
|
-
if images:
|
|
135
|
-
|
|
263
|
+
if images:
|
|
264
|
+
_event(
|
|
265
|
+
tools,
|
|
266
|
+
"production_review",
|
|
267
|
+
{
|
|
268
|
+
"render_id": args["render_id"],
|
|
269
|
+
"revision_id": entry["revision_id"],
|
|
270
|
+
"recipe_id": entry.get("recipe_id"),
|
|
271
|
+
"offsets_seconds": args["offsets_seconds"],
|
|
272
|
+
},
|
|
273
|
+
)
|
|
274
|
+
return ToolResult({**payload, "sample_offsets_seconds": args["offsets_seconds"]}, tuple(images))
|
|
136
275
|
|
|
137
276
|
|
|
138
277
|
def finish_review_status(tools):
|
|
139
|
-
from .editorial_review import coverage_targets,text_targets
|
|
140
|
-
|
|
278
|
+
from .editorial_review import coverage_targets, text_targets
|
|
279
|
+
|
|
280
|
+
revision = tools.repository.current_revision(tools.project_id, tools.run_id)
|
|
141
281
|
with tools.repository.projects.connect(tools.project_id) as db:
|
|
142
|
-
entries=[
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
282
|
+
entries = [
|
|
283
|
+
json.loads(r["payload_json"])
|
|
284
|
+
for r in db.execute(
|
|
285
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='production_review'",
|
|
286
|
+
(tools.run_id,),
|
|
287
|
+
)
|
|
288
|
+
]
|
|
289
|
+
reports = [
|
|
290
|
+
json.loads(r["payload_json"])
|
|
291
|
+
for r in db.execute(
|
|
292
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='editorial_review' ORDER BY sequence",
|
|
293
|
+
(tools.run_id,),
|
|
294
|
+
)
|
|
295
|
+
]
|
|
296
|
+
store = PreviewRenderRepository(tools.repository.projects)
|
|
297
|
+
offsets = []
|
|
298
|
+
recipe_id = render_recipe_id()
|
|
146
299
|
for entry in entries:
|
|
147
|
-
if entry[
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
300
|
+
if entry["revision_id"] != revision.revision_id or entry.get("recipe_id") != recipe_id:
|
|
301
|
+
continue
|
|
302
|
+
saved = store.get(tools.project_id, entry["render_id"])
|
|
303
|
+
path = store.output_path(tools.project_id, entry["render_id"], prepare=False)
|
|
304
|
+
if (
|
|
305
|
+
saved["state"] == "succeeded"
|
|
306
|
+
and not path.is_symlink()
|
|
307
|
+
and path.is_file()
|
|
308
|
+
and path.stat().st_size == saved["size_bytes"]
|
|
309
|
+
):
|
|
310
|
+
offsets.extend(entry["offsets_seconds"])
|
|
311
|
+
fps = revision.timeline.frame_rate.numerator / revision.timeline.frame_rate.denominator
|
|
312
|
+
|
|
313
|
+
def seen(target):
|
|
314
|
+
return any(abs(o - target) < 0.45 / fps for o in offsets)
|
|
315
|
+
|
|
153
316
|
# Shots and texts accepted in an earlier review and unchanged since need no new stills.
|
|
154
317
|
from .editorial_review import carried_reviews
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
missing_shots={
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
318
|
+
|
|
319
|
+
carried_shots, carried_texts = carried_reviews(tools, revision, recipe_id)
|
|
320
|
+
missing_shots = {
|
|
321
|
+
identifier: [o for o in samples if not seen(o)]
|
|
322
|
+
for identifier, samples in coverage_targets(revision.timeline).items()
|
|
323
|
+
if identifier not in carried_shots
|
|
324
|
+
}
|
|
325
|
+
missing_shots = {k: v for k, v in missing_shots.items() if v}
|
|
326
|
+
missing_texts = {k: v for k, v in text_targets(revision.timeline).items() if k not in carried_texts and not seen(v)}
|
|
327
|
+
complete = not missing_shots and not missing_texts
|
|
328
|
+
report = next(
|
|
329
|
+
(r for r in reversed(reports) if r["revision_id"] == revision.revision_id and r.get("recipe_id") == recipe_id),
|
|
330
|
+
None,
|
|
331
|
+
)
|
|
332
|
+
unresolved = (
|
|
333
|
+
[]
|
|
334
|
+
if report is None
|
|
335
|
+
else [s["item_id"] for s in report["shots"] if s["decision"] == "revise"]
|
|
336
|
+
+ [c["item_id"] for c in report["text_checks"] if not c["matches"]]
|
|
337
|
+
)
|
|
338
|
+
return {
|
|
339
|
+
"reviewed_revision": complete and report is not None and not unresolved,
|
|
340
|
+
"render_coverage_complete": complete,
|
|
341
|
+
"missing_shots": missing_shots,
|
|
342
|
+
"missing_texts": missing_texts,
|
|
343
|
+
"editorial_assessment_recorded": report is not None,
|
|
344
|
+
"unresolved": unresolved,
|
|
345
|
+
"carried_shots": sorted(carried_shots),
|
|
346
|
+
"carried_texts": sorted(carried_texts),
|
|
347
|
+
"carried_note": "Unchanged shots and texts accepted in an earlier review of this run; review_cut may omit them.",
|
|
348
|
+
"coverage": "start/middle/end rendered stills and text samples; continuous motion and audio not reviewed",
|
|
349
|
+
"assessment_authority": "model_authored",
|
|
350
|
+
"human_review": "pending",
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def cancel_preview(tools, args):
|
|
171
355
|
with tools.repository.projects.connect(tools.project_id) as db:
|
|
172
|
-
entries=[
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if
|
|
180
|
-
|
|
356
|
+
entries = [
|
|
357
|
+
json.loads(r["payload_json"])
|
|
358
|
+
for r in db.execute(
|
|
359
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='production_preview'",
|
|
360
|
+
(tools.run_id,),
|
|
361
|
+
)
|
|
362
|
+
]
|
|
363
|
+
if not any(e["render_id"] == args["render_id"] for e in entries):
|
|
364
|
+
raise ProjectError("preview_not_found", "預覽不屬於這次剪輯。", status_code=404)
|
|
365
|
+
store = PreviewRenderRepository(tools.repository.projects)
|
|
366
|
+
saved = store.get(tools.project_id, args["render_id"])
|
|
367
|
+
if saved["state"] not in {"queued", "running", "cancelling"}:
|
|
368
|
+
return ToolResult({"render": saved})
|
|
369
|
+
store.request_cancel(tools.project_id, args["render_id"])
|
|
370
|
+
job = getattr(tools, "_preview_jobs", {}).get(args["render_id"])
|
|
371
|
+
if job:
|
|
372
|
+
job[0].set()
|
|
373
|
+
return ToolResult({"render": store.get(tools.project_id, args["render_id"])})
|