@clipen/clipen-cli 1.0.8 → 1.0.10
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 +57 -39
- package/README.zh-TW.md +98 -0
- package/apps/web/dist/assets/index-BHFCflzf.js +15 -0
- package/apps/web/dist/assets/index-BtenOBwP.css +1 -0
- package/apps/web/dist/favicon.svg +1 -1
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +10 -17
- package/package.json +2 -2
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/annotations/suggestions.py +1 -1
- package/src/clipen/bootstrap.py +190 -28
- package/src/clipen/controller/app.py +185 -22
- package/src/clipen/controller/server.py +19 -6
- package/src/clipen/editing/agent_repository.py +29 -3
- package/src/clipen/editing/agent_tools.py +2 -1
- package/src/clipen/editing/aspect.py +27 -0
- package/src/clipen/editing/caption_design.py +134 -0
- package/src/clipen/editing/component_looks.py +3 -3
- package/src/clipen/editing/component_review.py +0 -38
- package/src/clipen/editing/coordinator.py +14 -0
- package/src/clipen/editing/production_catalog.py +77 -16
- package/src/clipen/editing/production_media.py +14 -3
- package/src/clipen/editing/production_preview.py +18 -9
- package/src/clipen/editing/production_progress.py +2 -0
- package/src/clipen/editing/production_tools.py +18 -22
- package/src/clipen/editing/program_subtitles.py +5 -13
- package/src/clipen/editing/resolve_export.py +2 -183
- package/src/clipen/editing/skill_tools.py +150 -218
- package/src/clipen/editing/slip.py +109 -0
- package/src/clipen/editing/tool_receipts.py +3 -1
- package/src/clipen/editing/versions.py +4 -0
- package/src/clipen/editing/visual_preview.py +73 -3
- package/src/clipen/editing/workbench.py +53 -1
- package/src/clipen/locale_en.py +36 -0
- package/src/clipen/mcp_editing/server.py +3 -1
- package/src/clipen/media/discovery.py +2 -2
- package/src/clipen/media/preview.py +5 -0
- package/src/clipen/media/storage.py +5 -2
- package/src/clipen/own_ffmpeg.py +113 -0
- package/src/clipen/projects/models.py +2 -0
- package/src/clipen/projects/storage.py +84 -4
- package/src/clipen/providers/account.py +37 -6
- package/src/clipen/providers/claude.py +5 -3
- package/src/clipen/providers/claude_editing.py +5 -6
- package/src/clipen/providers/codex.py +19 -7
- package/src/clipen/providers/codex_editing.py +2 -1
- package/src/clipen/providers/editing_agent.py +30 -6
- package/src/clipen/providers/model_selection.py +67 -0
- package/src/clipen/rendering/cover.py +1 -1
- package/src/clipen/rendering/custom_components.py +216 -25
- package/src/clipen/rendering/custom_render.py +90 -54
- package/src/clipen/rendering/fetched_fonts.py +127 -0
- package/src/clipen/rendering/production_effects.py +24 -2
- package/src/clipen/rendering/program_components.py +18 -240
- package/src/clipen/rendering/program_subtitles.py +3 -1
- package/src/clipen/rendering/renderer.py +36 -20
- package/src/clipen/rendering/titles.py +29 -12
- package/src/clipen/skills/builtin/SKILL.md +3 -3
- 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-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/references/captions.md +12 -0
- package/src/clipen/skills/builtin/references/graphics.md +7 -6
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +9 -7
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +10 -7
- package/src/clipen/skills/builtin/templates.json +9 -0
- package/src/clipen/skills/catalog.py +0 -8
- package/src/clipen/skills/package.py +1 -10
- package/apps/web/dist/assets/index-CJ80KHsQ.css +0 -1
- package/apps/web/dist/assets/index-C_4u_hVf.js +0 -16
- package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +0 -38
- package/src/clipen/editing/REFACTOR_DESIGN.md +0 -241
- package/src/clipen/editing/REFACTOR_HANDOFF.md +0 -73
- package/src/clipen/editing/resolve_titles.py +0 -291
- package/src/clipen/rendering/program_creator.py +0 -804
- package/src/clipen/rendering/program_identities.py +0 -350
- package/src/clipen/rendering/program_motion.py +0 -186
- package/src/clipen/rendering/program_studio.py +0 -227
- package/src/clipen/rendering/program_styles.py +0 -321
- package/src/clipen/skills/builtin/components.json +0 -133
|
@@ -83,9 +83,20 @@ class AgentAudioStore:
|
|
|
83
83
|
raise ProjectError("agent_audio_missing", "找不到這個作品已取得的音訊。", status_code=404)
|
|
84
84
|
asset = record["asset"]
|
|
85
85
|
reference = record["reference"]
|
|
86
|
-
path = Path(reference["canonical_path"])
|
|
87
|
-
if path.
|
|
86
|
+
path = self.directory / Path(reference["canonical_path"]).name
|
|
87
|
+
if path.is_symlink():
|
|
88
88
|
raise ProjectError("storage_unsafe", "音訊來源不在本作品的管理範圍。", status_code=409)
|
|
89
|
+
if not path.is_dir():
|
|
90
|
+
raise ProjectError("agent_audio_missing", "找不到這個作品已取得的音訊。", status_code=404)
|
|
91
|
+
# The folder is this project's own, so it is found where the project now is: a project copied,
|
|
92
|
+
# restored or moved to another Mac keeps its music although the path, inode and mtimes change.
|
|
93
|
+
# The file is still checked against its saved size and fingerprint.
|
|
94
|
+
info = path.stat()
|
|
95
|
+
reference = {**reference, "canonical_path": str(path), "device": info.st_dev, "inode": info.st_ino}
|
|
96
|
+
try:
|
|
97
|
+
asset = {**asset, "mtime_ns": (path / asset["relative_path"]).lstat().st_mtime_ns}
|
|
98
|
+
except OSError:
|
|
99
|
+
pass
|
|
89
100
|
return {"assets": [asset], "directories": {asset["role"]: reference}}
|
|
90
101
|
|
|
91
102
|
|
|
@@ -416,7 +427,7 @@ def source_rows(projects, project_id):
|
|
|
416
427
|
"""The live inventory is the authority; prior planning windows are not a source boundary."""
|
|
417
428
|
with projects.connect(project_id) as db:
|
|
418
429
|
rows = db.execute(
|
|
419
|
-
"SELECT i.version_id,i.display_name,s.stream_index,s.kind,s.details_json,v.probe_json FROM current_inventory c JOIN inventory_runs r ON r.run_id=c.run_id JOIN inventory_items i ON i.run_id=r.run_id JOIN assets a ON a.asset_id=i.asset_id JOIN asset_versions v ON v.version_id=i.version_id JOIN media_streams s ON s.version_id=i.version_id WHERE c.slot=1 AND r.state='succeeded' AND a.role
|
|
430
|
+
"SELECT i.version_id,i.display_name,s.stream_index,s.kind,s.details_json,v.probe_json FROM current_inventory c JOIN inventory_runs r ON r.run_id=c.run_id JOIN inventory_items i ON i.run_id=r.run_id JOIN assets a ON a.asset_id=i.asset_id JOIN asset_versions v ON v.version_id=i.version_id JOIN media_streams s ON s.version_id=i.version_id WHERE c.slot=1 AND r.state='succeeded' AND a.role IN ('source','added') AND i.status='usable' AND s.kind IN ('video','audio') ORDER BY i.display_name,i.version_id,s.stream_index LIMIT 10001"
|
|
420
431
|
).fetchall()
|
|
421
432
|
if len(rows) > 10000:
|
|
422
433
|
raise ProjectError("agent_source_limit", "素材串流超過上限,請拆分作品。", status_code=409)
|
|
@@ -30,10 +30,6 @@ def render_recipe_id():
|
|
|
30
30
|
from clipen.rendering import (
|
|
31
31
|
production_effects,
|
|
32
32
|
program_components,
|
|
33
|
-
program_identities,
|
|
34
|
-
program_motion,
|
|
35
|
-
program_studio,
|
|
36
|
-
program_styles,
|
|
37
33
|
program_subtitles,
|
|
38
34
|
renderer,
|
|
39
35
|
titles,
|
|
@@ -46,10 +42,6 @@ def render_recipe_id():
|
|
|
46
42
|
renderer,
|
|
47
43
|
titles,
|
|
48
44
|
program_components,
|
|
49
|
-
program_motion,
|
|
50
|
-
program_styles,
|
|
51
|
-
program_studio,
|
|
52
|
-
program_identities,
|
|
53
45
|
program_subtitles,
|
|
54
46
|
production_effects,
|
|
55
47
|
program_audio,
|
|
@@ -65,7 +57,17 @@ def render_preview(tools):
|
|
|
65
57
|
validation = tools._production_validate_sequence({}).payload
|
|
66
58
|
issues = validation["render_issues"]
|
|
67
59
|
if issues:
|
|
68
|
-
|
|
60
|
+
if not getattr(tools, "_user_edit", False):
|
|
61
|
+
raise ProjectError("agent_sequence_invalid", "請先使用 validate_sequence 修正時間軸。", status_code=422)
|
|
62
|
+
# The person never sees validate_sequence; say what they can do about it.
|
|
63
|
+
audio = {"finishing_library_offline", "finishing_asset_missing", "agent_audio_missing", "media_changed"}
|
|
64
|
+
if any(issue.get("code") in audio for issue in issues):
|
|
65
|
+
raise ProjectError(
|
|
66
|
+
"sequence_audio_missing", "這一版用到的配樂或音效找不到了,請重新選一首配樂再輸出。", status_code=422
|
|
67
|
+
)
|
|
68
|
+
raise ProjectError(
|
|
69
|
+
"sequence_invalid", "這一版有地方需要修正才能輸出,請交給 AI 修改,或回到上一個版本。", status_code=422
|
|
70
|
+
)
|
|
69
71
|
store = PreviewRenderRepository(tools.repository.projects)
|
|
70
72
|
# The exact revision is the cache key. Polling/reviewing never rerenders it.
|
|
71
73
|
with tools.repository.projects.connect(tools.project_id) as db:
|
|
@@ -78,6 +80,13 @@ def render_preview(tools):
|
|
|
78
80
|
if entry["revision_id"] == revision.revision_id and entry.get("recipe_id") == recipe_id:
|
|
79
81
|
saved = store.get(tools.project_id, entry["render_id"])
|
|
80
82
|
if saved["state"] in {"queued", "running", "succeeded"}:
|
|
83
|
+
# Back on a version rendered before (after an undo or going back in History): its film is
|
|
84
|
+
# the latest one again, so the review page plays it.
|
|
85
|
+
_event(
|
|
86
|
+
tools,
|
|
87
|
+
"production_preview",
|
|
88
|
+
{"render_id": saved["render_id"], "revision_id": revision.revision_id, "recipe_id": recipe_id},
|
|
89
|
+
)
|
|
81
90
|
return ToolResult({"render": saved, "revision_id": revision.revision_id, "reused": True})
|
|
82
91
|
current = store.current(tools.project_id)
|
|
83
92
|
if current and current["state"] in {"queued", "running", "cancelling"}:
|
|
@@ -239,8 +239,13 @@ class ProductionTools:
|
|
|
239
239
|
)
|
|
240
240
|
|
|
241
241
|
def _production_set_canvas(self, args):
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
from .aspect import DEFAULT_ASPECT, SHORT_SIDES, canvas
|
|
243
|
+
|
|
244
|
+
aspect = self._session_value()["intent"].get("aspect_ratio", DEFAULT_ASPECT)
|
|
245
|
+
allowed = [canvas(aspect, side) for side in SHORT_SIDES]
|
|
246
|
+
if (args["width"], args["height"]) not in allowed:
|
|
247
|
+
sizes = "、".join(f"{w}×{h}" for w, h in allowed)
|
|
248
|
+
raise problem(f"這支影片是 {aspect},畫布只能是 {sizes}。")
|
|
244
249
|
return self._save(replace(self._timeline(), width=args["width"], height=args["height"]), args["summary"])
|
|
245
250
|
|
|
246
251
|
def _production_plan_episode(self, args):
|
|
@@ -417,9 +422,6 @@ class ProductionTools:
|
|
|
417
422
|
"cues"
|
|
418
423
|
]
|
|
419
424
|
}
|
|
420
|
-
from .program_direction import direction_for
|
|
421
|
-
|
|
422
|
-
program = direction_for(self).get("subtitle_style") == "program"
|
|
423
425
|
from .program_subtitles import make_subtitle_items
|
|
424
426
|
|
|
425
427
|
captions = []
|
|
@@ -433,22 +435,7 @@ class ProductionTools:
|
|
|
433
435
|
raise problem("單段字幕請分成可閱讀的句子,最多 80 字。")
|
|
434
436
|
if any(word not in row["text"] for word in row.get("emphasis", [])):
|
|
435
437
|
raise problem("重點字必須實際存在於字幕句內。")
|
|
436
|
-
|
|
437
|
-
program
|
|
438
|
-
or cue.get("verification") == "asr_draft"
|
|
439
|
-
or any(k in row for k in ("source_excerpt", "delivery", "emphasis"))
|
|
440
|
-
):
|
|
441
|
-
captions.extend(make_subtitle_items(self, cue, row))
|
|
442
|
-
else:
|
|
443
|
-
captions.append(
|
|
444
|
-
TextClip(
|
|
445
|
-
"subtitle-" + row["cue_id"],
|
|
446
|
-
cue["start_frame"],
|
|
447
|
-
cue["duration_frames"],
|
|
448
|
-
row["text"],
|
|
449
|
-
"title.caption",
|
|
450
|
-
)
|
|
451
|
-
)
|
|
438
|
+
captions.extend(make_subtitle_items(self, cue, row))
|
|
452
439
|
from .production_limits import limits_for
|
|
453
440
|
|
|
454
441
|
if len(captions) > limits_for(self).titles:
|
|
@@ -550,7 +537,16 @@ class ProductionTools:
|
|
|
550
537
|
return self._effect(
|
|
551
538
|
args["item_id"],
|
|
552
539
|
"video.grade",
|
|
553
|
-
{
|
|
540
|
+
{
|
|
541
|
+
"contrast": args.get("contrast", 1),
|
|
542
|
+
"saturation": args.get("saturation", 1),
|
|
543
|
+
"brightness": args.get("brightness", 0),
|
|
544
|
+
**{
|
|
545
|
+
k: args[k]
|
|
546
|
+
for k in ("gamma", "temperature", "tint", "shadows", "highlights", "vignette", "grain")
|
|
547
|
+
if k in args and args[k] != (1 if k == "gamma" else 0)
|
|
548
|
+
},
|
|
549
|
+
},
|
|
554
550
|
args["summary"],
|
|
555
551
|
)
|
|
556
552
|
|
|
@@ -75,6 +75,9 @@ def make_subtitle_items(tools, cue, row):
|
|
|
75
75
|
frame_rate = tools._timeline().frame_rate
|
|
76
76
|
aligned = aligned_pages(original, text, excerpt, pages, frame_rate.numerator / frame_rate.denominator)
|
|
77
77
|
pages = [(left, right) for left, right, _, _ in aligned]
|
|
78
|
+
from .caption_design import chosen_id
|
|
79
|
+
|
|
80
|
+
design = chosen_id(tools, row)
|
|
78
81
|
styles = load_text_styles(tools.repository.projects, tools.project_id)
|
|
79
82
|
items = []
|
|
80
83
|
for n, (left, right) in enumerate(pages):
|
|
@@ -85,7 +88,7 @@ def make_subtitle_items(tools, cue, row):
|
|
|
85
88
|
delivery = row.get("delivery", "dialogue")
|
|
86
89
|
profile = {
|
|
87
90
|
"kind": "program_subtitle",
|
|
88
|
-
"
|
|
91
|
+
"design": design,
|
|
89
92
|
"delivery": delivery,
|
|
90
93
|
"emphasis": [s for s in row.get("emphasis", []) if s in text[left:right]],
|
|
91
94
|
"verification": cue.get("verification", "reviewed_source"),
|
|
@@ -102,7 +105,6 @@ def make_subtitle_items(tools, cue, row):
|
|
|
102
105
|
if excerpt or len(pages) > 1
|
|
103
106
|
else "asr_segment",
|
|
104
107
|
"caption_text_edited": text != original["text"],
|
|
105
|
-
"motion": "none" if delivery == "quiet" else "pop",
|
|
106
108
|
}
|
|
107
109
|
profile.update(
|
|
108
110
|
{
|
|
@@ -111,17 +113,7 @@ def make_subtitle_items(tools, cue, row):
|
|
|
111
113
|
if key in original
|
|
112
114
|
}
|
|
113
115
|
)
|
|
114
|
-
|
|
115
|
-
preset = skill["presets"]["subtitle"]
|
|
116
|
-
profile.update(
|
|
117
|
-
{
|
|
118
|
-
"font_size_ratio": preset["font_size_ratio"]
|
|
119
|
-
* (1.25 if delivery == "punchline" else 0.9 if delivery == "quiet" else 1),
|
|
120
|
-
"emphasis_color": preset["emphasis_color"],
|
|
121
|
-
"outline_color": preset["outline_color"],
|
|
122
|
-
"skill_hash": skill["content_hash"],
|
|
123
|
-
}
|
|
124
|
-
)
|
|
116
|
+
profile["skill_hash"] = tools._skill_value()["content_hash"]
|
|
125
117
|
identifier = "agent.text." + digest(profile)[:24]
|
|
126
118
|
styles[identifier] = profile
|
|
127
119
|
items.append(
|
|
@@ -16,7 +16,6 @@ import shutil
|
|
|
16
16
|
import subprocess
|
|
17
17
|
import tempfile
|
|
18
18
|
import threading
|
|
19
|
-
import time
|
|
20
19
|
import xml.etree.ElementTree as ET
|
|
21
20
|
from dataclasses import replace
|
|
22
21
|
from datetime import datetime
|
|
@@ -511,7 +510,6 @@ def _write(repository, project_id, package, name, timeline, video, cancel):
|
|
|
511
510
|
target = directory / f"{number:03d} {label}.png"
|
|
512
511
|
shutil.move(str(image.path), target)
|
|
513
512
|
rendered.append((item, target, label))
|
|
514
|
-
editable = _editable_titles(directory, rendered, styles, timeline)
|
|
515
513
|
still = build.format(timeline.width, timeline.height, None)
|
|
516
514
|
for (item, target, label), lane in zip(
|
|
517
515
|
rendered, _lanes([(i.start_frame, i.start_frame + i.duration_frames) for i, _, _ in rendered], 1, 1)
|
|
@@ -618,187 +616,19 @@ def _write(repository, project_id, package, name, timeline, video, cancel):
|
|
|
618
616
|
|
|
619
617
|
fcpxml = package / f"{name}.fcpxml"
|
|
620
618
|
build.write(fcpxml)
|
|
621
|
-
_guide(package, fcpxml, bool(captions),
|
|
619
|
+
_guide(package, fcpxml, bool(captions), notes)
|
|
622
620
|
return {
|
|
623
621
|
"folder": str(package),
|
|
624
622
|
"fcpxml": str(fcpxml),
|
|
625
623
|
"shots": len(video.items),
|
|
626
624
|
"burned": burned,
|
|
627
625
|
"overlays": len(rendered),
|
|
628
|
-
"editable_overlays": editable,
|
|
629
626
|
"captions": len(captions),
|
|
630
627
|
"music_layers": len(layers),
|
|
631
628
|
"notes": notes,
|
|
632
629
|
}
|
|
633
630
|
|
|
634
631
|
|
|
635
|
-
def _editable_titles(directory: Path, rendered, styles, timeline) -> int:
|
|
636
|
-
"""Record each component's type beside its PNG so a .drt from Resolve can carry it as editable titles."""
|
|
637
|
-
from clipen.rendering import program_creator
|
|
638
|
-
from clipen.rendering.titles import TitleCardRenderer, TitleRenderError
|
|
639
|
-
|
|
640
|
-
from .resolve_titles import MANIFEST
|
|
641
|
-
|
|
642
|
-
font_path = TitleCardRenderer._font_path()
|
|
643
|
-
manifest = {}
|
|
644
|
-
for item, target, _ in rendered:
|
|
645
|
-
profile = styles.get(item.style_id)
|
|
646
|
-
# A graphic a person resized stays a picture: Resolve's titles would come back at the designed size.
|
|
647
|
-
if (
|
|
648
|
-
not profile
|
|
649
|
-
or profile.get("kind") != "program_component"
|
|
650
|
-
or not program_creator.is_creator(profile)
|
|
651
|
-
or profile.get("scale", 1) != 1
|
|
652
|
-
):
|
|
653
|
-
continue
|
|
654
|
-
try:
|
|
655
|
-
plan = program_creator.editable(font_path, timeline, item, profile)
|
|
656
|
-
except TitleRenderError:
|
|
657
|
-
plan = None
|
|
658
|
-
if plan is None:
|
|
659
|
-
continue
|
|
660
|
-
picture = None
|
|
661
|
-
if plan["picture"]:
|
|
662
|
-
picture = f"{target.stem}(底圖).png"
|
|
663
|
-
plan["picture"].save(directory / picture, "PNG", optimize=True)
|
|
664
|
-
manifest[target.name] = {
|
|
665
|
-
"rows": plan["rows"],
|
|
666
|
-
"picture": picture,
|
|
667
|
-
"width": timeline.width,
|
|
668
|
-
"height": timeline.height,
|
|
669
|
-
}
|
|
670
|
-
if manifest:
|
|
671
|
-
(directory / MANIFEST).write_text(json.dumps(manifest, ensure_ascii=False, indent=1), encoding="utf-8")
|
|
672
|
-
return len(manifest)
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
RESOLVE_DEFAULT_FOLDER = Path.home() / "Movies" / "DaVinci Resolve"
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
def _timeline_folders(package: Path) -> list[Path]:
|
|
679
|
-
"""Where a .drt saved from this package's timeline may land: the package, Resolve's own folder,
|
|
680
|
-
and, for a package in「Clipen 匯出」, that folder and the footage folder around it, since the
|
|
681
|
-
save dialog often opens beside the footage the timeline was relinked to."""
|
|
682
|
-
from clipen.media.discovery import EXPORT_FOLDER
|
|
683
|
-
|
|
684
|
-
folders = [package, RESOLVE_DEFAULT_FOLDER]
|
|
685
|
-
if package.parent.name == EXPORT_FOLDER:
|
|
686
|
-
folders += [package.parent, package.parent.parent]
|
|
687
|
-
return folders
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
def _exported_timeline(package: Path, since: float = 0.0) -> Path | None:
|
|
691
|
-
"""The newest .drt saved from this package's timeline after since (a time stamp).
|
|
692
|
-
|
|
693
|
-
A .drt counts when its clips point at this package's components, so other films' timelines
|
|
694
|
-
in the same folders are passed over."""
|
|
695
|
-
from .resolve_titles import uses
|
|
696
|
-
|
|
697
|
-
# Skip dot files such as the「._」copies macOS leaves beside files on exFAT drives.
|
|
698
|
-
candidates = [
|
|
699
|
-
p
|
|
700
|
-
for folder in _timeline_folders(package)
|
|
701
|
-
for p in folder.glob("*.drt")
|
|
702
|
-
if "(可改字)" not in p.stem and not p.name.startswith(".")
|
|
703
|
-
]
|
|
704
|
-
candidates = [p for p in candidates if p.stat().st_mtime > since]
|
|
705
|
-
return next(
|
|
706
|
-
(p for p in sorted(candidates, key=lambda p: p.stat().st_mtime, reverse=True) if uses(p, package / "元件")),
|
|
707
|
-
None,
|
|
708
|
-
)
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
def timeline_status(package: Path) -> dict:
|
|
712
|
-
"""Where Clipen looks for this package's .drt, the newest one it found, and the editable copy.
|
|
713
|
-
|
|
714
|
-
state is waiting (nothing saved yet), found (a .drt is newer than any editable copy) or
|
|
715
|
-
converted (the editable copy covers the newest save)."""
|
|
716
|
-
package = Path(package)
|
|
717
|
-
names = ["這份匯出的資料夾", "Resolve 預設的資料夾", "「Clipen 匯出」資料夾", "毛片資料夾"]
|
|
718
|
-
folders = [{"label": label, "path": str(folder)} for label, folder in zip(names, _timeline_folders(package))]
|
|
719
|
-
source = _exported_timeline(package)
|
|
720
|
-
copies = sorted(
|
|
721
|
-
(p for p in package.glob("*(可改字).drt") if not p.name.startswith(".")),
|
|
722
|
-
key=lambda p: p.stat().st_mtime,
|
|
723
|
-
reverse=True,
|
|
724
|
-
)
|
|
725
|
-
converted = copies[0] if copies else None
|
|
726
|
-
if converted is not None and (source is None or converted.stat().st_mtime >= source.stat().st_mtime):
|
|
727
|
-
state = "converted"
|
|
728
|
-
else:
|
|
729
|
-
state = "found" if source is not None else "waiting"
|
|
730
|
-
return {
|
|
731
|
-
"state": state,
|
|
732
|
-
"folders": folders,
|
|
733
|
-
"source": str(source) if source else None,
|
|
734
|
-
"converted": str(converted) if converted else None,
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
def convert_timeline(package: Path, source: Path | None = None) -> tuple[Path, int]:
|
|
739
|
-
"""Write a copy of the .drt exported from this package's timeline with editable component titles."""
|
|
740
|
-
from .resolve_titles import MANIFEST, convert
|
|
741
|
-
|
|
742
|
-
package = Path(package)
|
|
743
|
-
if not (package / "元件" / MANIFEST).is_file():
|
|
744
|
-
raise ProjectError("resolve_titles_missing", "這份匯出沒有可以換成文字的元件。", status_code=409)
|
|
745
|
-
source = source or _exported_timeline(package)
|
|
746
|
-
if source is None:
|
|
747
|
-
raise ProjectError(
|
|
748
|
-
"resolve_timeline_missing",
|
|
749
|
-
"還找不到這份匯出的 .drt。請先在 DaVinci Resolve 用「檔案 > 匯出 > 時間線…」把時間線存成 .drt。",
|
|
750
|
-
status_code=409,
|
|
751
|
-
)
|
|
752
|
-
target = _unique(package, f"{source.stem}(可改字).drt")
|
|
753
|
-
temporary = target.with_suffix(".partial")
|
|
754
|
-
try:
|
|
755
|
-
replaced = convert(source, temporary)
|
|
756
|
-
if not replaced:
|
|
757
|
-
raise ProjectError(
|
|
758
|
-
"resolve_titles_unmatched",
|
|
759
|
-
f"「{source.name}」裡找不到這份匯出的元件。請確認匯出的是從這個資料夾匯入的時間線。",
|
|
760
|
-
status_code=409,
|
|
761
|
-
)
|
|
762
|
-
temporary.replace(target)
|
|
763
|
-
finally:
|
|
764
|
-
temporary.unlink(missing_ok=True)
|
|
765
|
-
return target, replaced
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
def watch_timeline(
|
|
769
|
-
package: Path, since: float, stop: threading.Event | None = None, timeout: float = 4 * 3600, interval: float = 2.0
|
|
770
|
-
) -> Path | None:
|
|
771
|
-
"""Wait for the person to save this package's timeline as .drt in Resolve, then convert and show it.
|
|
772
|
-
|
|
773
|
-
A save counts once its size holds still for one interval, so a half-written file is never read.
|
|
774
|
-
Gives up after timeout or when stop is set; returns the converted timeline."""
|
|
775
|
-
stop = stop or threading.Event()
|
|
776
|
-
deadline, seen = time.monotonic() + timeout, None
|
|
777
|
-
while not stop.wait(interval) and time.monotonic() < deadline:
|
|
778
|
-
source = _exported_timeline(package, since)
|
|
779
|
-
if source is None:
|
|
780
|
-
continue
|
|
781
|
-
size = source.stat().st_size
|
|
782
|
-
if seen != (source, size):
|
|
783
|
-
seen = (source, size)
|
|
784
|
-
continue
|
|
785
|
-
try:
|
|
786
|
-
target, _ = convert_timeline(package, source)
|
|
787
|
-
except ProjectError:
|
|
788
|
-
return None
|
|
789
|
-
reveal(target)
|
|
790
|
-
return target
|
|
791
|
-
return None
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
def start_watching(package: Path) -> threading.Thread:
|
|
795
|
-
"""Watch for the .drt in the background so the person never has to come back to Clipen for it."""
|
|
796
|
-
since = time.time()
|
|
797
|
-
thread = threading.Thread(target=watch_timeline, args=(Path(package), since), name="resolve-titles", daemon=True)
|
|
798
|
-
thread.start()
|
|
799
|
-
return thread
|
|
800
|
-
|
|
801
|
-
|
|
802
632
|
def reveal(path: Path) -> None:
|
|
803
633
|
"""Show the new timeline file in Finder; a missing Finder only skips this courtesy."""
|
|
804
634
|
if os.uname().sysname == "Darwin":
|
|
@@ -807,7 +637,7 @@ def reveal(path: Path) -> None:
|
|
|
807
637
|
)
|
|
808
638
|
|
|
809
639
|
|
|
810
|
-
def _guide(package: Path, fcpxml: Path, captions: bool,
|
|
640
|
+
def _guide(package: Path, fcpxml: Path, captions: bool, notes: list[str]):
|
|
811
641
|
steps = [
|
|
812
642
|
"在 DaVinci Resolve 匯入",
|
|
813
643
|
"",
|
|
@@ -827,17 +657,6 @@ def _guide(package: Path, fcpxml: Path, captions: bool, editable: int, notes: li
|
|
|
827
657
|
"影片片段直接指向原始素材,前後保留可延長的長度。若搬動了素材,Resolve 會請你重新連結。",
|
|
828
658
|
"這個資料夾裡的元件、音樂和已處理片段也被時間線使用,請保持資料夾完整。",
|
|
829
659
|
]
|
|
830
|
-
if editable:
|
|
831
|
-
steps += [
|
|
832
|
-
"",
|
|
833
|
-
"想在 Resolve 改元件的字(需要時再做)",
|
|
834
|
-
"",
|
|
835
|
-
f"匯入後元件已經和 Clipen 一模一樣,只是以圖片呈現。要改其中的字,再做兩步,{editable} 個元件會一起換成可以改字的標題:",
|
|
836
|
-
"1. 選「檔案 > 匯出 > 時間線…」(File > Export > Timeline),格式選「DaVinci Resolve Timeline Files (*.drt)」,按儲存。",
|
|
837
|
-
" Clipen 開著的話會自動做好一份名稱有「(可改字)」的 .drt,並在 Finder 打開它;沒出現的話,到 Clipen 的「到 DaVinci Resolve 自己剪」按「把元件換成可改字的標題」。",
|
|
838
|
-
"2. 選「檔案 > 匯入 > 時間線…」,選那份「(可改字)」的 .drt。選取元件後,在右邊「檢查器」改字。",
|
|
839
|
-
" 改字只會改文字本身;底框、細線這類圖形是固定的圖片,字數差很多時可能要自己調整位置。",
|
|
840
|
-
]
|
|
841
660
|
if notes:
|
|
842
661
|
steps += ["", "需要留意", ""] + [f"・{note}" for note in notes]
|
|
843
662
|
steps += [
|