@clipen/clipen-cli 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +79 -2
- package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
- package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
- package/apps/web/dist/favicon.svg +1 -0
- package/apps/web/dist/index.html +16 -0
- package/bin/clipen.js +157 -0
- package/clipen +18 -0
- package/install +25 -0
- package/package.json +52 -4
- package/pyproject.toml +28 -0
- package/requirements/asr-runtime.txt +13 -0
- package/requirements/runtime.txt +20 -0
- package/src/clipen/__init__.py +3 -0
- package/src/clipen/analysis/__init__.py +89 -0
- package/src/clipen/analysis/artifacts.py +416 -0
- package/src/clipen/analysis/audio.py +392 -0
- package/src/clipen/analysis/evidence.py +102 -0
- package/src/clipen/analysis/evidence_service.py +751 -0
- package/src/clipen/analysis/image_similarity.py +143 -0
- package/src/clipen/analysis/keyframes.py +171 -0
- package/src/clipen/analysis/models.py +230 -0
- package/src/clipen/analysis/qwen_worker.py +629 -0
- package/src/clipen/analysis/resources.py +21 -0
- package/src/clipen/analysis/runtime.py +64 -0
- package/src/clipen/analysis/service.py +626 -0
- package/src/clipen/analysis/setup.py +935 -0
- package/src/clipen/analysis/setup_cli.py +117 -0
- package/src/clipen/analysis/storage.py +2046 -0
- package/src/clipen/analysis/transcription.py +948 -0
- package/src/clipen/analysis/visual.py +176 -0
- package/src/clipen/annotations/__init__.py +10 -0
- package/src/clipen/annotations/models.py +22 -0
- package/src/clipen/annotations/storage.py +380 -0
- package/src/clipen/annotations/suggestions.py +120 -0
- package/src/clipen/asr_release.py +139 -0
- package/src/clipen/bootstrap.py +967 -0
- package/src/clipen/cli.py +84 -0
- package/src/clipen/controller/__init__.py +17 -0
- package/src/clipen/controller/app.py +1470 -0
- package/src/clipen/controller/server.py +543 -0
- package/src/clipen/domain/__init__.py +30 -0
- package/src/clipen/domain/errors.py +5 -0
- package/src/clipen/domain/media_time.py +117 -0
- package/src/clipen/domain/timeline.py +584 -0
- package/src/clipen/domain/validation.py +15 -0
- package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
- package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
- package/src/clipen/editing/README.md +115 -0
- package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
- package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
- package/src/clipen/editing/__init__.py +15 -0
- package/src/clipen/editing/agent.py +13 -0
- package/src/clipen/editing/agent_models.py +134 -0
- package/src/clipen/editing/agent_repository.py +757 -0
- package/src/clipen/editing/agent_tools.py +532 -0
- package/src/clipen/editing/alignment.py +110 -0
- package/src/clipen/editing/alignment_setup.py +108 -0
- package/src/clipen/editing/alignment_worker.py +22 -0
- package/src/clipen/editing/change_report.py +71 -0
- package/src/clipen/editing/compiler.py +41 -0
- package/src/clipen/editing/component_looks.py +107 -0
- package/src/clipen/editing/component_review.py +78 -0
- package/src/clipen/editing/coordinator.py +374 -0
- package/src/clipen/editing/editorial_review.py +187 -0
- package/src/clipen/editing/evidence_jobs.py +295 -0
- package/src/clipen/editing/history_changes.py +131 -0
- package/src/clipen/editing/music_choices.py +15 -0
- package/src/clipen/editing/production_catalog.py +192 -0
- package/src/clipen/editing/production_limits.py +59 -0
- package/src/clipen/editing/production_media.py +226 -0
- package/src/clipen/editing/production_preview.py +180 -0
- package/src/clipen/editing/production_progress.py +141 -0
- package/src/clipen/editing/production_requirements.py +50 -0
- package/src/clipen/editing/production_tools.py +596 -0
- package/src/clipen/editing/program_audio.py +118 -0
- package/src/clipen/editing/program_direction.py +49 -0
- package/src/clipen/editing/program_story.py +53 -0
- package/src/clipen/editing/program_subtitles.py +134 -0
- package/src/clipen/editing/programme_review.py +73 -0
- package/src/clipen/editing/prompt_history.py +47 -0
- package/src/clipen/editing/recut.py +127 -0
- package/src/clipen/editing/refinement_references.py +188 -0
- package/src/clipen/editing/resolve_export.py +616 -0
- package/src/clipen/editing/resolve_titles.py +234 -0
- package/src/clipen/editing/skill_tools.py +575 -0
- package/src/clipen/editing/source_dialogue.py +82 -0
- package/src/clipen/editing/speech_coverage.py +30 -0
- package/src/clipen/editing/speech_quality.py +6 -0
- package/src/clipen/editing/tool_receipts.py +52 -0
- package/src/clipen/editing/versions.py +161 -0
- package/src/clipen/editing/visual_preview.py +93 -0
- package/src/clipen/editing/workbench.py +74 -0
- package/src/clipen/filesystem.py +25 -0
- package/src/clipen/finishing/README.md +103 -0
- package/src/clipen/finishing/__init__.py +1 -0
- package/src/clipen/finishing/audio.py +149 -0
- package/src/clipen/finishing/catalog.py +181 -0
- package/src/clipen/finishing/models.py +14 -0
- package/src/clipen/finishing/renderer.py +26 -0
- package/src/clipen/mcp_editing/__init__.py +5 -0
- package/src/clipen/mcp_editing/__main__.py +40 -0
- package/src/clipen/mcp_editing/server.py +353 -0
- package/src/clipen/media/__init__.py +50 -0
- package/src/clipen/media/discovery.py +266 -0
- package/src/clipen/media/models.py +360 -0
- package/src/clipen/media/preview.py +147 -0
- package/src/clipen/media/probe.py +446 -0
- package/src/clipen/media/service.py +317 -0
- package/src/clipen/media/storage.py +742 -0
- package/src/clipen/music_vocabulary.py +5 -0
- package/src/clipen/planning/__init__.py +9 -0
- package/src/clipen/planning/models.py +240 -0
- package/src/clipen/power.py +23 -0
- package/src/clipen/projects/__init__.py +26 -0
- package/src/clipen/projects/agent_schema.py +94 -0
- package/src/clipen/projects/annotation_schema.py +40 -0
- package/src/clipen/projects/deletion.py +269 -0
- package/src/clipen/projects/evidence_schema.py +52 -0
- package/src/clipen/projects/finishing_schema.py +34 -0
- package/src/clipen/projects/models.py +192 -0
- package/src/clipen/projects/picker.py +256 -0
- package/src/clipen/projects/preview_schema.py +29 -0
- package/src/clipen/projects/service.py +175 -0
- package/src/clipen/projects/storage.py +1478 -0
- package/src/clipen/projects/timeline_schema.py +32 -0
- package/src/clipen/projects/validation_schema.py +28 -0
- package/src/clipen/provider_registry.py +75 -0
- package/src/clipen/providers/__init__.py +43 -0
- package/src/clipen/providers/account.py +194 -0
- package/src/clipen/providers/claude.py +375 -0
- package/src/clipen/providers/claude_editing.py +111 -0
- package/src/clipen/providers/codex.py +1036 -0
- package/src/clipen/providers/codex_editing.py +91 -0
- package/src/clipen/providers/editing_agent.py +565 -0
- package/src/clipen/providers/errors.py +51 -0
- package/src/clipen/providers/recovery.py +270 -0
- package/src/clipen/py.typed +1 -0
- package/src/clipen/rendering/__init__.py +12 -0
- package/src/clipen/rendering/cover.py +126 -0
- package/src/clipen/rendering/custom_components.py +240 -0
- package/src/clipen/rendering/custom_render.py +197 -0
- package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/manifest.json +145 -0
- package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
- package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
- package/src/clipen/rendering/production_effects.py +64 -0
- package/src/clipen/rendering/program_components.py +193 -0
- package/src/clipen/rendering/program_creator.py +649 -0
- package/src/clipen/rendering/program_identities.py +255 -0
- package/src/clipen/rendering/program_motion.py +141 -0
- package/src/clipen/rendering/program_studio.py +168 -0
- package/src/clipen/rendering/program_styles.py +235 -0
- package/src/clipen/rendering/program_subtitles.py +52 -0
- package/src/clipen/rendering/renderer.py +708 -0
- package/src/clipen/rendering/storage.py +243 -0
- package/src/clipen/rendering/titles.py +360 -0
- package/src/clipen/skills/__init__.py +4 -0
- package/src/clipen/skills/builtin/SKILL.md +72 -0
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
- package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
- package/src/clipen/skills/builtin/components.json +133 -0
- package/src/clipen/skills/builtin/font_sources.json +20 -0
- package/src/clipen/skills/builtin/font_styles.json +329 -0
- package/src/clipen/skills/builtin/manifest.json +32 -0
- package/src/clipen/skills/builtin/presets.json +8 -0
- package/src/clipen/skills/builtin/references/captions.md +14 -0
- package/src/clipen/skills/builtin/references/channel-design.md +37 -0
- package/src/clipen/skills/builtin/references/editing.md +30 -0
- package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/graphics.md +59 -0
- package/src/clipen/skills/builtin/references/review.md +16 -0
- package/src/clipen/skills/builtin/references/sound.md +8 -0
- package/src/clipen/skills/builtin/references/story.md +7 -0
- package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
- package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/templates.json +284 -0
- package/src/clipen/skills/builtin/visual_styles.json +1074 -0
- package/src/clipen/skills/catalog.py +218 -0
- package/src/clipen/skills/library.py +131 -0
- package/src/clipen/skills/package.py +231 -0
- package/src/clipen/skills/visual_styles.py +44 -0
- package/src/clipen/workspace.py +210 -0
- package/uninstall +25 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""User-owned, source-anchored review notes for incremental AI revisions.
|
|
2
|
+
|
|
3
|
+
A note marks a moment the person paused at while watching (at_offset_frames),
|
|
4
|
+
the range it covers inside one shot, and optionally the caption or programme
|
|
5
|
+
component they pointed at. Location facts stay for later rounds; every other
|
|
6
|
+
note belongs to the round it was sent with.
|
|
7
|
+
"""
|
|
8
|
+
import hashlib
|
|
9
|
+
import json
|
|
10
|
+
import math
|
|
11
|
+
from fractions import Fraction
|
|
12
|
+
from clipen.domain import TrackKind
|
|
13
|
+
from clipen.projects import ProjectError
|
|
14
|
+
from clipen.projects.models import validate_request_id
|
|
15
|
+
from clipen.projects.storage import command_digest, utc_now
|
|
16
|
+
from clipen.rendering.renderer import FfmpegPreviewRenderer
|
|
17
|
+
from .agent_models import bounded_text, encoded
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
KINDS = {'change','remove','keep','highlight','location','audio','note'}
|
|
21
|
+
LASTING = {'location'}
|
|
22
|
+
_OPTIONAL = {'source_gain_db','fill_music','audio_layer_id','at_offset_frames','explicit_range','element_id'}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def references(intent):
|
|
26
|
+
return intent.get('user_references', {'version': 0, 'items': []})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def source_pts(clip, fps, offset):
|
|
30
|
+
"""Map a cut-relative frame boundary through the native speed ramp."""
|
|
31
|
+
span = clip.source.span
|
|
32
|
+
unit = Fraction(span.time_base.numerator, span.time_base.denominator)
|
|
33
|
+
duration = span.duration_pts * unit
|
|
34
|
+
elapsed = Fraction(offset, 1) / fps
|
|
35
|
+
speed = FfmpegPreviewRenderer._speed_profile(clip)
|
|
36
|
+
if speed:
|
|
37
|
+
outside, center = map(lambda rate: Fraction(str(rate)), speed)
|
|
38
|
+
first = duration * Fraction(2, 5) / outside
|
|
39
|
+
middle = duration * Fraction(1, 5) / center
|
|
40
|
+
if elapsed < first:
|
|
41
|
+
elapsed *= outside
|
|
42
|
+
elif elapsed < first + middle:
|
|
43
|
+
elapsed = duration * Fraction(2, 5) + (elapsed - first) * center
|
|
44
|
+
else:
|
|
45
|
+
elapsed = duration * Fraction(3, 5) + (elapsed - first - middle) * outside
|
|
46
|
+
return Fraction(int(span.start_pts)) + min(duration, max(Fraction(0), elapsed)) / unit
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def locate(reference, timeline):
|
|
50
|
+
"""Only claim a current position when the anchored source cut still matches."""
|
|
51
|
+
for track in timeline.tracks:
|
|
52
|
+
if track.kind is not TrackKind.VIDEO:
|
|
53
|
+
continue
|
|
54
|
+
for clip in track.items:
|
|
55
|
+
if clip.item_id == reference['item_id'] and clip.source.to_payload() == reference['clip_source'] and clip.duration_frames == reference['clip_duration_frames'] and timeline.frame_rate.to_storage() == reference['frame_rate'] and list(FfmpegPreviewRenderer._speed_profile(clip) or ()) == reference['speed_profile']:
|
|
56
|
+
layer = reference.get('audio_layer_id')
|
|
57
|
+
if layer and not any(l['layer_id'] == layer for effect in clip.effects if effect.effect_id == 'audio.layers' for l in effect.parameters['layers']):
|
|
58
|
+
return None
|
|
59
|
+
located = {'item_id': clip.item_id, 'start_frame': clip.start_frame + reference['start_offset_frames'], 'duration_frames': reference['duration_frames'],
|
|
60
|
+
'at_frame': clip.start_frame + reference.get('at_offset_frames', reference['start_offset_frames'])}
|
|
61
|
+
element = reference.get('element_id')
|
|
62
|
+
if element:
|
|
63
|
+
located['element_present'] = any(item.item_id == element for t in timeline.tracks for item in t.items)
|
|
64
|
+
return located
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def sent(intent):
|
|
69
|
+
"""What the last revision request handed to the AI, for review."""
|
|
70
|
+
request = intent.get('latest_revision_request')
|
|
71
|
+
if not request:
|
|
72
|
+
return None
|
|
73
|
+
return {'instruction': request.get('instruction'), 'created_at': request.get('created_at'), 'items': request.get('references', {}).get('items', [])}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def hand_over(intent):
|
|
77
|
+
"""Close the round: only lasting facts stay for the next one."""
|
|
78
|
+
state = references(intent)
|
|
79
|
+
kept = [item for item in state['items'] if item['kind'] in LASTING]
|
|
80
|
+
if len(kept) != len(state['items']):
|
|
81
|
+
intent['user_references'] = {'version': state['version'] + 1, 'items': kept}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def public_state(intent, timeline):
|
|
85
|
+
state = references(intent)
|
|
86
|
+
return {**state, 'items': [{**item, 'current_range': locate(item, timeline)} for item in state['items']]}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def update(repository, project_id, run_id, expected_revision_id, expected_version, mutation_id, reference=None, delete_id=None):
|
|
90
|
+
run_id = repository._validate_run_id(run_id)
|
|
91
|
+
mutation_id = validate_request_id(mutation_id)
|
|
92
|
+
if isinstance(expected_version, bool) or not isinstance(expected_version, int) or expected_version < 0:
|
|
93
|
+
raise ProjectError('reference_invalid', '參考註記版本無效。', status_code=422)
|
|
94
|
+
if (reference is None) == (delete_id is None):
|
|
95
|
+
raise ProjectError('reference_invalid', '請指定一筆要儲存或刪除的註記。', status_code=422)
|
|
96
|
+
request_hash = command_digest({'run_id':run_id,'revision':expected_revision_id,'version':expected_version,'reference':reference,'delete_id':delete_id})
|
|
97
|
+
event_id = 'reference_' + hashlib.sha256(mutation_id.encode()).hexdigest()[:32]
|
|
98
|
+
with repository.projects.connect(project_id) as db:
|
|
99
|
+
db.execute('BEGIN IMMEDIATE')
|
|
100
|
+
prior = db.execute('SELECT payload_json FROM operation_events WHERE event_id=?', (event_id,)).fetchone()
|
|
101
|
+
if prior:
|
|
102
|
+
payload = json.loads(prior['payload_json'])
|
|
103
|
+
if payload['request_hash'] != request_hash:
|
|
104
|
+
raise ProjectError('request_reused', '操作識別已用於其他註記。', status_code=409)
|
|
105
|
+
return payload['result']
|
|
106
|
+
run = repository._read_run(db, run_id)
|
|
107
|
+
latest = db.execute('SELECT run_id FROM edit_agent_runs ORDER BY created_at DESC,rowid DESC LIMIT 1').fetchone()
|
|
108
|
+
if latest['run_id'] != run_id or db.execute("SELECT 1 FROM edit_agent_runs WHERE state IN ('queued','running')").fetchone():
|
|
109
|
+
raise ProjectError('edit_agent_busy', '請先停止 AI 製作,再修改參考註記。', status_code=409)
|
|
110
|
+
if run.current_revision_id != expected_revision_id:
|
|
111
|
+
raise ProjectError('revision_conflict', '影片已更新,請重新讀取後標記。', status_code=409)
|
|
112
|
+
row = db.execute('SELECT intent_json FROM production_sessions WHERE run_id=?', (run_id,)).fetchone()
|
|
113
|
+
if row is None:
|
|
114
|
+
raise ProjectError('production_required', '這個版本不支援參考註記。', status_code=422)
|
|
115
|
+
intent = json.loads(row['intent_json']); state = references(intent)
|
|
116
|
+
if state['version'] != expected_version:
|
|
117
|
+
raise ProjectError('reference_conflict', '註記已在其他視窗更新,請重新讀取後再修改。', status_code=409)
|
|
118
|
+
revision = repository._read_revision(db, run.current_revision_id)
|
|
119
|
+
items = list(state['items'])
|
|
120
|
+
if delete_id is not None:
|
|
121
|
+
if not isinstance(delete_id, str) or not any(item['reference_id'] == delete_id for item in items):
|
|
122
|
+
raise ProjectError('reference_not_found', '找不到這筆註記。', status_code=404)
|
|
123
|
+
items = [item for item in items if item['reference_id'] != delete_id]
|
|
124
|
+
else:
|
|
125
|
+
item = normalize(reference, revision)
|
|
126
|
+
old = next((r for r in items if r['reference_id'] == item['reference_id']), None)
|
|
127
|
+
if old:
|
|
128
|
+
items = [item if r['reference_id'] == item['reference_id'] else r for r in items]
|
|
129
|
+
else:
|
|
130
|
+
if len(items) >= 100:
|
|
131
|
+
raise ProjectError('reference_limit', '每支影片最多保留 100 筆參考註記。', status_code=422)
|
|
132
|
+
items.append(item)
|
|
133
|
+
intent['user_references'] = {'version':state['version'] + 1, 'items':items}
|
|
134
|
+
db.execute('UPDATE production_sessions SET intent_json=? WHERE run_id=?', (encoded(intent),run_id))
|
|
135
|
+
result = public_state(intent, revision.timeline)
|
|
136
|
+
payload = {'authority':'user','run_id':run_id,'request_hash':request_hash,'result':result}
|
|
137
|
+
db.execute('INSERT INTO operation_events(event_id,project_id,operation_id,event_type,payload_json,created_at) VALUES(?,?,?,?,?,?)', (event_id,project_id,mutation_id,'production_reference_changed',encoded(payload),utc_now()))
|
|
138
|
+
db.commit()
|
|
139
|
+
return result
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def normalize(value, revision):
|
|
143
|
+
required = {'reference_id','kind','item_id','start_offset_frames','duration_frames','note'}
|
|
144
|
+
if not isinstance(value, dict) or not required <= value.keys() or value.keys() - required - _OPTIONAL:
|
|
145
|
+
raise ProjectError('reference_invalid', '參考註記欄位無效。', status_code=422)
|
|
146
|
+
identifier = validate_request_id(value['reference_id'])
|
|
147
|
+
kind = value['kind']
|
|
148
|
+
if not isinstance(kind, str) or kind not in KINDS:
|
|
149
|
+
raise ProjectError('reference_invalid', '請選擇註記類型。', status_code=422)
|
|
150
|
+
# "Remove this" and "this is fine" say enough on their own.
|
|
151
|
+
note = bounded_text(value['note'], '參考說明', 2000, empty=kind in {'remove','keep'})
|
|
152
|
+
clip = next((item for track in revision.timeline.tracks if track.kind is TrackKind.VIDEO for item in track.items if item.item_id == value['item_id']), None)
|
|
153
|
+
if clip is None:
|
|
154
|
+
raise ProjectError('reference_invalid', '請選擇這支影片中的畫面片段。', status_code=422)
|
|
155
|
+
start, length = value['start_offset_frames'], value['duration_frames']
|
|
156
|
+
if any(isinstance(v,bool) or not isinstance(v,int) for v in (start,length)) or start < 0 or length < 1 or start + length > clip.duration_frames:
|
|
157
|
+
raise ProjectError('reference_invalid', '標記範圍必須在選定片段內。', status_code=422)
|
|
158
|
+
at = value.get('at_offset_frames', start)
|
|
159
|
+
if isinstance(at,bool) or not isinstance(at,int) or not start <= at < start + length:
|
|
160
|
+
raise ProjectError('reference_invalid', '標記的時間點必須在範圍內。', status_code=422)
|
|
161
|
+
if not isinstance(value.get('explicit_range', False), bool):
|
|
162
|
+
raise ProjectError('reference_invalid', '參考註記欄位無效。', status_code=422)
|
|
163
|
+
item = {k:value[k] for k in required}
|
|
164
|
+
item.update(at_offset_frames=at, explicit_range=value.get('explicit_range', False))
|
|
165
|
+
if value.get('element_id') is not None:
|
|
166
|
+
element_id = value['element_id']
|
|
167
|
+
found = next(((t,i) for t in revision.timeline.tracks for i in t.items if i.item_id == element_id), None) if isinstance(element_id,str) else None
|
|
168
|
+
begin = clip.start_frame + start
|
|
169
|
+
if found is None or found[1].start_frame >= begin + length or found[1].start_frame + found[1].duration_frames <= begin:
|
|
170
|
+
raise ProjectError('reference_invalid', '指定的字幕或元件不在這段時間。', status_code=422)
|
|
171
|
+
track, element = found
|
|
172
|
+
item.update(element_id=element_id, element_track=track.track_id, element_text=(getattr(element,'text',None) or '')[:120] or None)
|
|
173
|
+
item.update(reference_id=identifier,note=note,authority='user',base_revision_id=revision.revision_id,clip_source=clip.source.to_payload(),clip_duration_frames=clip.duration_frames,frame_rate=revision.timeline.frame_rate.to_storage(),speed_profile=list(FfmpegPreviewRenderer._speed_profile(clip) or ()))
|
|
174
|
+
fps = Fraction(revision.timeline.frame_rate.numerator, revision.timeline.frame_rate.denominator)
|
|
175
|
+
item['source_range'] = {**clip.source.span.to_storage(), 'start_pts':str(math.floor(source_pts(clip,fps,start))), 'end_pts':str(math.ceil(source_pts(clip,fps,start+length)))}
|
|
176
|
+
if kind == 'audio':
|
|
177
|
+
gain = value.get('source_gain_db', -12)
|
|
178
|
+
if isinstance(gain,bool) or not isinstance(gain,(int,float)) or not math.isfinite(gain) or not -60 <= gain <= 0 or not isinstance(value.get('fill_music',True),bool):
|
|
179
|
+
raise ProjectError('reference_invalid', '原音音量需介於 -60 至 0 dB。', status_code=422)
|
|
180
|
+
item.update(source_gain_db=gain,fill_music=value.get('fill_music',True))
|
|
181
|
+
layer = value.get('audio_layer_id')
|
|
182
|
+
if layer:
|
|
183
|
+
if not isinstance(layer,str) or not any(l['layer_id']==layer for e in clip.effects if e.effect_id=='audio.layers' for l in e.parameters['layers']):
|
|
184
|
+
raise ProjectError('reference_invalid', '找不到選定片段的音軌。', status_code=422)
|
|
185
|
+
item['audio_layer_id'] = layer
|
|
186
|
+
elif any(key in value for key in ('source_gain_db','fill_music','audio_layer_id')):
|
|
187
|
+
raise ProjectError('reference_invalid', '只有聲音註記可以指定混音設定。', status_code=422)
|
|
188
|
+
return item
|