@clipen/clipen-cli 1.0.7 → 1.0.9

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.
Files changed (99) hide show
  1. package/README.md +16 -6
  2. package/apps/web/dist/assets/index-DPgSvXZ1.js +15 -0
  3. package/apps/web/dist/assets/index-DmPWV61v.css +1 -0
  4. package/apps/web/dist/index.html +2 -2
  5. package/bin/clipen.js +229 -68
  6. package/package.json +8 -2
  7. package/pyproject.toml +1 -1
  8. package/src/clipen/__init__.py +1 -1
  9. package/src/clipen/analysis/qwen_worker.py +13 -4
  10. package/src/clipen/analysis/setup.py +2 -1
  11. package/src/clipen/analysis/setup_cli.py +58 -12
  12. package/src/clipen/bootstrap.py +499 -167
  13. package/src/clipen/cli.py +40 -15
  14. package/src/clipen/controller/app.py +120 -38
  15. package/src/clipen/controller/server.py +70 -27
  16. package/src/clipen/editing/agent_repository.py +8 -0
  17. package/src/clipen/editing/agent_tools.py +1 -1
  18. package/src/clipen/editing/caption_design.py +134 -0
  19. package/src/clipen/editing/change_report.py +17 -0
  20. package/src/clipen/editing/component_looks.py +3 -3
  21. package/src/clipen/editing/component_review.py +0 -38
  22. package/src/clipen/editing/coordinator.py +20 -0
  23. package/src/clipen/editing/evidence_jobs.py +3 -1
  24. package/src/clipen/editing/history_changes.py +56 -27
  25. package/src/clipen/editing/production_catalog.py +67 -13
  26. package/src/clipen/editing/production_media.py +13 -2
  27. package/src/clipen/editing/production_preview.py +11 -9
  28. package/src/clipen/editing/production_progress.py +48 -3
  29. package/src/clipen/editing/production_tools.py +11 -20
  30. package/src/clipen/editing/program_subtitles.py +5 -13
  31. package/src/clipen/editing/resolve_export.py +2 -183
  32. package/src/clipen/editing/skill_tools.py +142 -218
  33. package/src/clipen/editing/tool_receipts.py +2 -1
  34. package/src/clipen/editing/versions.py +55 -10
  35. package/src/clipen/editing/visual_preview.py +62 -0
  36. package/src/clipen/editing/workbench.py +21 -1
  37. package/src/clipen/i18n.py +155 -0
  38. package/src/clipen/locale_en.py +546 -0
  39. package/src/clipen/mcp_editing/__main__.py +8 -0
  40. package/src/clipen/media/storage.py +2 -2
  41. package/src/clipen/own_ffmpeg.py +113 -0
  42. package/src/clipen/projects/models.py +16 -1
  43. package/src/clipen/projects/picker.py +3 -1
  44. package/src/clipen/projects/storage.py +17 -1
  45. package/src/clipen/providers/claude_editing.py +3 -1
  46. package/src/clipen/providers/codex_editing.py +3 -1
  47. package/src/clipen/providers/editing_agent.py +42 -5
  48. package/src/clipen/providers/liveness.py +39 -0
  49. package/src/clipen/rendering/custom_components.py +216 -25
  50. package/src/clipen/rendering/custom_render.py +90 -54
  51. package/src/clipen/rendering/fetched_fonts.py +127 -0
  52. package/src/clipen/rendering/production_effects.py +24 -2
  53. package/src/clipen/rendering/program_components.py +18 -240
  54. package/src/clipen/rendering/renderer.py +23 -17
  55. package/src/clipen/rendering/titles.py +29 -12
  56. package/src/clipen/skills/builtin/SKILL.md +3 -3
  57. package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
  58. package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
  59. package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
  60. package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
  61. package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
  62. package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
  63. package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
  64. package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
  65. package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
  66. package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
  67. package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
  68. package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
  69. package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
  70. package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
  71. package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
  72. package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
  73. package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
  74. package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
  75. package/src/clipen/skills/builtin/display.en.json +89 -0
  76. package/src/clipen/skills/builtin/references/captions.md +12 -0
  77. package/src/clipen/skills/builtin/references/graphics.md +6 -6
  78. package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +9 -4
  79. package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +10 -5
  80. package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +9 -4
  81. package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +10 -6
  82. package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +10 -6
  83. package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +9 -7
  84. package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +10 -5
  85. package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +10 -5
  86. package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +10 -7
  87. package/src/clipen/skills/catalog.py +22 -8
  88. package/src/clipen/skills/package.py +1 -10
  89. package/src/clipen/terminal.py +344 -0
  90. package/src/clipen/workspace.py +97 -28
  91. package/apps/web/dist/assets/index-C3Zw0WaM.js +0 -14
  92. package/apps/web/dist/assets/index-CaxEZKLc.css +0 -1
  93. package/src/clipen/editing/resolve_titles.py +0 -291
  94. package/src/clipen/rendering/program_creator.py +0 -804
  95. package/src/clipen/rendering/program_identities.py +0 -350
  96. package/src/clipen/rendering/program_motion.py +0 -186
  97. package/src/clipen/rendering/program_studio.py +0 -227
  98. package/src/clipen/rendering/program_styles.py +0 -321
  99. 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.parent != self.directory or path.is_symlink():
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
 
@@ -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
- raise ProjectError("agent_sequence_invalid", "請先使用 validate_sequence 修正時間軸。", status_code=422)
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:
@@ -6,6 +6,8 @@ work: an agent revisits steps and has no fixed number of them.
6
6
 
7
7
  import json
8
8
 
9
+ from clipen.i18n import english, tr
10
+
9
11
  _TOOL_GROUPS = (
10
12
  (
11
13
  "理解製作需求與影片風格",
@@ -53,6 +55,8 @@ _TOOL_GROUPS = (
53
55
  (
54
56
  "製作字幕與畫面設計",
55
57
  (
58
+ "get_font",
59
+ "set_caption_design",
56
60
  "replace_subtitles",
57
61
  "remove_program_component",
58
62
  "add_custom_component",
@@ -111,6 +115,37 @@ _FAILURE_LABELS = {
111
115
  "provider_usage_limit": "AI 額度不足,暫停製作",
112
116
  "provider_timed_out": "超過製作時間上限,暫停製作",
113
117
  }
118
+ # What each label says in English; the Chinese label stays the key that stages are read from.
119
+ _ENGLISH = {
120
+ "理解製作需求與影片風格": "Reading the brief and the style",
121
+ "尋找與檢視來源素材": "Finding and viewing footage",
122
+ "準備本機語音模型": "Preparing the local speech model",
123
+ "辨識與對齊來源口語": "Recognising and aligning speech",
124
+ "安排故事與剪輯": "Shaping the story and the cut",
125
+ "製作字幕與畫面設計": "Making captions and graphics",
126
+ "尋找與安排配樂、音效": "Finding and placing music and effects",
127
+ "輸出樣片預覽": "Rendering a preview",
128
+ "檢查畫面、字幕與聲音": "Checking picture, captions and sound",
129
+ "等待或處理本機工作結果": "Waiting on local work",
130
+ "整理交付檔案": "Preparing the delivery",
131
+ "AI 正在操作剪輯工具": "The AI is using the editing tools",
132
+ "製作工作已建立": "Production created",
133
+ "AI 已開始製作": "The AI started",
134
+ "收到你的修改要求": "Got your change request",
135
+ "接續上次的草稿": "Continuing the last draft",
136
+ "換另一個 AI 接手": "Another AI took over",
137
+ "草稿已儲存": "Draft saved",
138
+ "已提交預覽合成": "Preview render submitted",
139
+ "樣片製作已完成,等待你觀看": "The film is ready for you to watch",
140
+ "AI 這次沒有完成製作": "The AI did not finish this time",
141
+ "製作已停止": "Production stopped",
142
+ "製作已中斷": "Production interrupted",
143
+ "本次工作已達操作上限": "This job reached its operation limit",
144
+ "AI 做完草稿,但還有項目沒通過檢查": "The AI made a draft, but some checks have not passed",
145
+ "AI 先停下來了,請看 AI 的說明": "The AI stopped early; read what it says",
146
+ "AI 額度不足,暫停製作": "Out of AI usage; paused",
147
+ "超過製作時間上限,暫停製作": "Past the time limit; paused",
148
+ }
114
149
  # The furthest stage reached moves only forward. Checking the cut before any
115
150
  # preview is part of editing; reviewing only counts once a film was rendered.
116
151
  STAGES = ("understand", "sources", "edit", "graphics", "music", "render", "review")
@@ -152,7 +187,9 @@ _SHOWN = 10
152
187
 
153
188
  def _duration(seconds):
154
189
  minutes = max(1, round(seconds / 60))
155
- return f"{minutes} 分鐘" if minutes < 60 else f"{minutes // 60} 小時 {minutes % 60} 分鐘"
190
+ if minutes < 60:
191
+ return tr(f"{minutes} 分鐘", f"{minutes} min")
192
+ return tr(f"{minutes // 60} 小時 {minutes % 60} 分鐘", f"{minutes // 60} h {minutes % 60} min")
156
193
 
157
194
 
158
195
  def _provider_name(provider_id):
@@ -202,9 +239,15 @@ def production_activity(database, run_id):
202
239
  elif kind == "machine_slept":
203
240
  if row["sequence"] >= boundary:
204
241
  slept += payload.get("seconds", 0)
205
- label = f"Mac 睡眠約 {_duration(payload.get('seconds', 0))},製作暫停"
242
+ label = tr(
243
+ f"Mac 睡眠約 {_duration(payload.get('seconds', 0))},製作暫停",
244
+ f"The Mac slept for about {_duration(payload.get('seconds', 0))}; paused",
245
+ )
206
246
  elif kind == "provider_switched":
207
- label = f"改由 {_provider_name(payload.get('to'))} 接手修改"
247
+ label = tr(
248
+ f"改由 {_provider_name(payload.get('to'))} 接手修改",
249
+ f"{_provider_name(payload.get('to'))} took over the revision",
250
+ )
208
251
  else:
209
252
  label = _EVENT_LABELS[kind]
210
253
  labels.append(label)
@@ -225,6 +268,8 @@ def production_activity(database, run_id):
225
268
  }
226
269
  )
227
270
  activity = activity[-_SHOWN:]
271
+ if english():
272
+ activity = [{**entry, "label": _ENGLISH.get(entry["label"], entry["label"])} for entry in activity]
228
273
  return {
229
274
  "activity": activity,
230
275
  "updated_at": activity[-1]["created_at"] if activity else None,
@@ -417,9 +417,6 @@ class ProductionTools:
417
417
  "cues"
418
418
  ]
419
419
  }
420
- from .program_direction import direction_for
421
-
422
- program = direction_for(self).get("subtitle_style") == "program"
423
420
  from .program_subtitles import make_subtitle_items
424
421
 
425
422
  captions = []
@@ -433,22 +430,7 @@ class ProductionTools:
433
430
  raise problem("單段字幕請分成可閱讀的句子,最多 80 字。")
434
431
  if any(word not in row["text"] for word in row.get("emphasis", [])):
435
432
  raise problem("重點字必須實際存在於字幕句內。")
436
- if (
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
- )
433
+ captions.extend(make_subtitle_items(self, cue, row))
452
434
  from .production_limits import limits_for
453
435
 
454
436
  if len(captions) > limits_for(self).titles:
@@ -550,7 +532,16 @@ class ProductionTools:
550
532
  return self._effect(
551
533
  args["item_id"],
552
534
  "video.grade",
553
- {k: args[k] for k in ("contrast", "saturation", "brightness")},
535
+ {
536
+ "contrast": args.get("contrast", 1),
537
+ "saturation": args.get("saturation", 1),
538
+ "brightness": args.get("brightness", 0),
539
+ **{
540
+ k: args[k]
541
+ for k in ("gamma", "temperature", "tint", "shadows", "highlights", "vignette", "grain")
542
+ if k in args and args[k] != (1 if k == "gamma" else 0)
543
+ },
544
+ },
554
545
  args["summary"],
555
546
  )
556
547
 
@@ -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
- "font_size_ratio": 0.075 if delivery == "punchline" else 0.05 if delivery == "quiet" else 0.06,
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
- skill = tools._skill_value()
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), editable, notes)
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, editable: int, notes: list[str]):
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 += [