@clipen/clipen-cli 1.0.8 → 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.
- package/README.md +13 -4
- package/apps/web/dist/assets/index-DPgSvXZ1.js +15 -0
- package/apps/web/dist/assets/index-DmPWV61v.css +1 -0
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +6 -15
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/bootstrap.py +130 -23
- package/src/clipen/controller/app.py +83 -21
- package/src/clipen/controller/server.py +5 -0
- package/src/clipen/editing/agent_tools.py +1 -1
- 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 +67 -13
- package/src/clipen/editing/production_media.py +13 -2
- package/src/clipen/editing/production_preview.py +11 -9
- package/src/clipen/editing/production_progress.py +2 -0
- package/src/clipen/editing/production_tools.py +11 -20
- 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 +142 -218
- package/src/clipen/editing/tool_receipts.py +2 -1
- package/src/clipen/editing/versions.py +2 -0
- package/src/clipen/editing/visual_preview.py +62 -0
- package/src/clipen/editing/workbench.py +21 -1
- package/src/clipen/locale_en.py +18 -0
- package/src/clipen/media/storage.py +2 -2
- package/src/clipen/own_ffmpeg.py +113 -0
- package/src/clipen/providers/editing_agent.py +6 -4
- 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/renderer.py +23 -17
- 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 +6 -5
- 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/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/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
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
"""Turn Clipen's components into DaVinci Resolve titles whose words stay editable.
|
|
2
|
-
|
|
3
|
-
Resolve keeps Fusion titles only in its own timeline format (.drt), which it
|
|
4
|
-
writes but never reads from FCPXML. So the hand-off goes through Resolve: the
|
|
5
|
-
FCPXML places each component as a transparent PNG, the person exports that
|
|
6
|
-
timeline from Resolve as .drt, and convert() swaps every component PNG on it
|
|
7
|
-
for a Fusion title. The title draws the component's rows with Text+ (font,
|
|
8
|
-
size, tracking, colour and shadow as Clipen set them) over a picture of
|
|
9
|
-
everything else (boxes, rules, icons), and publishes each row's words to the
|
|
10
|
-
Edit page Inspector.
|
|
11
|
-
|
|
12
|
-
A .drt is a zip of XML. A clip's Fusion composition is a qCompress'd Qt
|
|
13
|
-
QVariantMap whose "0_data" is the composition header, a NUL, a little-endian
|
|
14
|
-
length and the zlib'd tool list; DaVinci Resolve 21 writes and reads that.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
from __future__ import annotations
|
|
18
|
-
|
|
19
|
-
import html
|
|
20
|
-
import json
|
|
21
|
-
import re
|
|
22
|
-
import struct
|
|
23
|
-
import unicodedata
|
|
24
|
-
import uuid
|
|
25
|
-
import zipfile
|
|
26
|
-
import zlib
|
|
27
|
-
from pathlib import Path
|
|
28
|
-
|
|
29
|
-
from clipen.projects import ProjectError
|
|
30
|
-
|
|
31
|
-
MANIFEST = ".clipen 元件.json"
|
|
32
|
-
# Text+ Size is a fraction of the frame width, and a glyph's em is 1/1.76 of it; Text+ tracking adds
|
|
33
|
-
# (CharacterSpacing - 1) x Size x width between letters. Measured in Resolve 21 on PingFang TC and Songti TC.
|
|
34
|
-
_SIZE = 1.76
|
|
35
|
-
_ITEM = re.compile(r'<Sm2TiVideoClip DbId="[^"]+">.*?</Sm2TiVideoClip>', re.S)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def _lua(value: str) -> str:
|
|
39
|
-
return '"' + value.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n") + '"'
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def _number(value: float) -> str:
|
|
43
|
-
return f"{value:.6g}"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def tools(rows: list[dict], picture: Path | None, width: int, height: int, frames: int) -> str:
|
|
47
|
-
"""The Fusion tool list for one component: rows of Text+ merged over its picture."""
|
|
48
|
-
last = frames - 1
|
|
49
|
-
frame = f"GlobalOut = Input {{ Value = {last}, }}, Width = Input {{ Value = {width}, }}, Height = Input {{ Value = {height}, }}, UseFrameFormatSettings = Input {{ Value = 1, }}, "
|
|
50
|
-
nodes, inputs = [], []
|
|
51
|
-
if picture:
|
|
52
|
-
nodes.append(
|
|
53
|
-
f'Picture = Loader {{ Clips = {{ Clip {{ ID = "Clip1", Filename = {_lua(str(picture))}, FormatID = "PNGFormat", '
|
|
54
|
-
f"StartFrame = -1, LengthSetManually = true, TrimIn = 0, TrimOut = 0, ExtendFirst = 0, ExtendLast = {last}, "
|
|
55
|
-
f"Loop = 0, AspectMode = 0, Depth = 0, TimeCode = 0, GlobalStart = 0, GlobalEnd = {last} }} }}, "
|
|
56
|
-
"ViewInfo = OperatorInfo { Pos = { 0, 0 } }, }"
|
|
57
|
-
)
|
|
58
|
-
# Each row merges over what lies below it: the picture, or the first row when there is none.
|
|
59
|
-
below = "Picture" if picture else None
|
|
60
|
-
for number, row in enumerate(rows, 1):
|
|
61
|
-
name, label = f"Row{number}", "" if len(rows) == 1 else f"第 {number} 行"
|
|
62
|
-
red, green, blue, alpha = (v / 255 for v in row["fill"])
|
|
63
|
-
shading = ""
|
|
64
|
-
if row["shadow"]:
|
|
65
|
-
sr, sg, sb, sa = (v / 255 for v in row["shadow"]["colour"])
|
|
66
|
-
offset = row["shadow"]["offset"]
|
|
67
|
-
shading = (
|
|
68
|
-
f'Enabled2 = Input {{ Value = 1, }}, Name2 = Input {{ Value = "Shadow", }}, ElementShape2 = Input {{ Value = 0, }}, '
|
|
69
|
-
f"Red2 = Input {{ Value = {_number(sr)}, }}, Green2 = Input {{ Value = {_number(sg)}, }}, Blue2 = Input {{ Value = {_number(sb)}, }}, "
|
|
70
|
-
f"Alpha2 = Input {{ Value = {_number(sa)}, }}, Offset2 = Input {{ Value = {{ {_number(offset / width)}, {_number(-offset / height)} }}, }}, "
|
|
71
|
-
f"Softness2 = Input {{ Value = 1, }}, SoftnessX2 = Input {{ Value = {row['shadow']['blur']}, }}, SoftnessY2 = Input {{ Value = {row['shadow']['blur']}, }}, "
|
|
72
|
-
)
|
|
73
|
-
nodes.append(
|
|
74
|
-
f"{name} = TextPlus {{ Inputs = {{ {frame}"
|
|
75
|
-
f"Center = Input {{ Value = {{ {_number(row['x'] / width)}, {_number(1 - row['baseline'] / height)} }}, }}, "
|
|
76
|
-
"CenterOnBaseOfFirstLine = Input { Value = 1, }, HorizontalLeftCenterRight = Input { Value = -1, }, "
|
|
77
|
-
"VerticalJustificationNew = Input { Value = 3, }, HorizontalJustificationNew = Input { Value = 3, }, "
|
|
78
|
-
f"StyledText = Input {{ Value = {_lua(row['text'])}, }}, Font = Input {{ Value = {_lua(row['family'])}, }}, "
|
|
79
|
-
f"Style = Input {{ Value = {_lua(row['style'])}, }}, Size = Input {{ Value = {_number(row['size'] * _SIZE / width)}, }}, "
|
|
80
|
-
f"CharacterSpacing = Input {{ Value = {_number(1 + row['track'] / _SIZE)}, }}, "
|
|
81
|
-
f"Red1 = Input {{ Value = {_number(red)}, }}, Green1 = Input {{ Value = {_number(green)}, }}, Blue1 = Input {{ Value = {_number(blue)}, }}, "
|
|
82
|
-
f"Alpha1 = Input {{ Value = {_number(alpha)}, }}, {shading}}}, ViewInfo = OperatorInfo {{ Pos = {{ 110, {60 * number} }} }}, }}"
|
|
83
|
-
)
|
|
84
|
-
if below:
|
|
85
|
-
nodes.append(
|
|
86
|
-
f'Merge{number} = Merge {{ Inputs = {{ Background = Input {{ SourceOp = "{below}", Source = "Output", }}, '
|
|
87
|
-
f'Foreground = Input {{ SourceOp = "{name}", Source = "Output", }}, PerformDepthMerge = Input {{ Value = 0, }}, }}, '
|
|
88
|
-
f"ViewInfo = OperatorInfo {{ Pos = {{ 220, {60 * number} }} }}, }}"
|
|
89
|
-
)
|
|
90
|
-
below = f"Merge{number}" if below else name
|
|
91
|
-
group = 10 * number
|
|
92
|
-
inputs += [
|
|
93
|
-
f'{name}Text = InstanceInput {{ SourceOp = "{name}", Source = "StyledText", Name = {_lua((label + " 文字").strip())}, }}',
|
|
94
|
-
f'{name}Font = InstanceInput {{ SourceOp = "{name}", Source = "Font", Name = {_lua((label + " 字型").strip())}, ControlGroup = {group}, }}',
|
|
95
|
-
f'{name}Style = InstanceInput {{ SourceOp = "{name}", Source = "Style", ControlGroup = {group}, }}',
|
|
96
|
-
f'{name}Size = InstanceInput {{ SourceOp = "{name}", Source = "Size", Name = {_lua((label + " 大小").strip())}, }}',
|
|
97
|
-
f'{name}Red = InstanceInput {{ SourceOp = "{name}", Source = "Red1Clone", Name = {_lua((label + " 顏色").strip())}, ControlGroup = {group + 1}, }}',
|
|
98
|
-
f'{name}Green = InstanceInput {{ SourceOp = "{name}", Source = "Green1Clone", ControlGroup = {group + 1}, }}',
|
|
99
|
-
f'{name}Blue = InstanceInput {{ SourceOp = "{name}", Source = "Blue1Clone", ControlGroup = {group + 1}, }}',
|
|
100
|
-
f'{name}Alpha = InstanceInput {{ SourceOp = "{name}", Source = "Alpha1Clone", ControlGroup = {group + 1}, }}',
|
|
101
|
-
]
|
|
102
|
-
# Resolve shows a Text+ title's controls from a tool called Template, and MediaOut reads the tool inside the group.
|
|
103
|
-
return (
|
|
104
|
-
"{ Template = GroupOperator { CtrlWZoom = false, Inputs = ordered() { " + ", ".join(inputs) + " }, "
|
|
105
|
-
f'Outputs = {{ MainOutput1 = InstanceOutput {{ SourceOp = "{below}", Source = "Output", }} }}, '
|
|
106
|
-
"ViewInfo = GroupInfo { Pos = { 0, 0 } }, Tools = ordered() { " + ", ".join(nodes) + " }, }, "
|
|
107
|
-
f'MediaOut1 = MediaOut {{ Inputs = {{ Index = Input {{ Value = "0", }}, Input = Input {{ SourceOp = "{below}", Source = "Output", }} }}, '
|
|
108
|
-
"ViewInfo = OperatorInfo { Pos = { 330, 0 } }, } }"
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def _qstring(value: str) -> bytes:
|
|
113
|
-
data = value.encode("utf-16-be")
|
|
114
|
-
return struct.pack(">I", len(data)) + data
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def composition(tool_list: str, width: int, height: int, frames: int) -> str:
|
|
118
|
-
"""A clip's CompositionBA: the tool list wrapped the way Resolve stores a Text+ title's comp."""
|
|
119
|
-
last = frames - 1
|
|
120
|
-
header = (
|
|
121
|
-
f"Composition {{ CurrentTime = 0, RenderRange = {{ 0, {last} }}, GlobalRange = {{ 0, {last} }}, CurrentID = 1, HiQ = true, "
|
|
122
|
-
'PlaybackUpdateMode = 0, StereoMode = false, Version = "DaVinci Resolve 21.1.2.0010", SavedOutputs = 1, HeldTools = 0, '
|
|
123
|
-
'DisabledTools = 0, LockedTools = 0, AudioOffset = 0, Resumable = true, OutputClips = { }, CustomData = { TEMPLATE_ID = "Text+" }, '
|
|
124
|
-
f"Prefs = {{ Comp = {{ FrameFormat = {{ Width = {width}, Height = {height}, GuideRatio = {_number(width / height)}, "
|
|
125
|
-
f"DepthFull = 3, DepthPreview = 3, DepthInteractive = 3, }}, Unsorted = {{ GlobalEnd = {last} }}, }} }}, Compressed = true, }}"
|
|
126
|
-
)
|
|
127
|
-
inner = tool_list.encode("utf-8")
|
|
128
|
-
data = header.encode("utf-8") + b"\x00" + struct.pack("<I", len(inner)) + zlib.compress(inner, 9)
|
|
129
|
-
variant = struct.pack(">II", 1, 4)
|
|
130
|
-
variant += _qstring("count") + struct.pack(">IBi", 2, 0, 1)
|
|
131
|
-
variant += _qstring("0_name") + struct.pack(">IB", 10, 0) + _qstring("Composition 1")
|
|
132
|
-
variant += _qstring("0_mediaIdList") + struct.pack(">IBI", 11, 0, 0)
|
|
133
|
-
variant += _qstring("0_data") + struct.pack(">IBI", 12, 0, len(data)) + data
|
|
134
|
-
return (struct.pack(">I", len(variant)) + zlib.compress(variant, 9)).hex()
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def _varint(value: int) -> bytes:
|
|
138
|
-
out = bytearray()
|
|
139
|
-
while True:
|
|
140
|
-
byte, value = value & 0x7F, value >> 7
|
|
141
|
-
out.append(byte | (0x80 if value else 0))
|
|
142
|
-
if not value:
|
|
143
|
-
return bytes(out)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def _fields(start: int) -> str:
|
|
147
|
-
"""A Text+ Fusion Title clip's FieldsBlob: its template name and the frame it starts on."""
|
|
148
|
-
name = b"Text+"
|
|
149
|
-
title = b"\x22" + bytes([len(name)]) + name + b"\x4a" + bytes([len(name)]) + name + b"\xa8\x01" + _varint(start)
|
|
150
|
-
clip = b"\x0a" + _varint(len(title)) + title + b"\x20\x01"
|
|
151
|
-
body = b"\x0a" + _varint(len(clip)) + clip + b"\x12\x10" + bytes.fromhex("0000000000000006ffffffffffffffff")
|
|
152
|
-
return (struct.pack(">II", 2, len(body) + 1) + b"\x80" + body).hex()
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def title_item(start: int, duration: int, frame_rate: str, comp: str, indent: str) -> str:
|
|
156
|
-
"""A Fusion Title clip in a .drt sequence, shaped like the ones Resolve 21 writes."""
|
|
157
|
-
lines = [
|
|
158
|
-
f'<Sm2TiVideoClip DbId="{uuid.uuid4()}">',
|
|
159
|
-
f" <FieldsBlob>{_fields(start)}</FieldsBlob>",
|
|
160
|
-
" <PrettyType>Fusion Title</PrettyType>",
|
|
161
|
-
" <Name>Fusion Title</Name>",
|
|
162
|
-
f" <Start>{start}</Start>",
|
|
163
|
-
f" <Duration>{duration}</Duration>",
|
|
164
|
-
" <LinkedItemSync/>",
|
|
165
|
-
" <WasDisbanded>false</WasDisbanded>",
|
|
166
|
-
" <MarkersBA/>",
|
|
167
|
-
" <UiMemento>0</UiMemento>",
|
|
168
|
-
" <Flags>0</Flags>",
|
|
169
|
-
" <PriorityIndex>0</PriorityIndex>",
|
|
170
|
-
" <EffectFiltersBA/>",
|
|
171
|
-
" <ImportExportMetadataBA/>",
|
|
172
|
-
" <RenderTextEnabled>true</RenderTextEnabled>",
|
|
173
|
-
" <RenderTextGanged>true</RenderTextGanged>",
|
|
174
|
-
" <RenderTextPrefixed>true</RenderTextPrefixed>",
|
|
175
|
-
" <CompositionTable>",
|
|
176
|
-
f' <Sm2TiCompositionTable DbId="{uuid.uuid4()}">',
|
|
177
|
-
" <FieldsBlob>000000010000000200000016004c006100730074004d006f006400540069006d0065000000040000000000b5a8a2230000002c00460075007300"
|
|
178
|
-
"69006f006e00530074006100720074004600720061006d0065004f00660066007300650074000000020000000000</FieldsBlob>",
|
|
179
|
-
" <DbSavedTime>0</DbSavedTime>",
|
|
180
|
-
f" <CompositionBA>{comp}</CompositionBA>",
|
|
181
|
-
" <ActiveCompositionIdx>0</ActiveCompositionIdx>",
|
|
182
|
-
" </Sm2TiCompositionTable>",
|
|
183
|
-
" </CompositionTable>",
|
|
184
|
-
" <In/>",
|
|
185
|
-
" <MixedFrameRateAlignment>0</MixedFrameRateAlignment>",
|
|
186
|
-
" <MediaStartTime>0</MediaStartTime>",
|
|
187
|
-
" <MediaFilePath/>",
|
|
188
|
-
" <MediaReelNumber/>",
|
|
189
|
-
f" <MediaFrameRate>{frame_rate}</MediaFrameRate>",
|
|
190
|
-
" <MediaTimemapBA>024013ddddddddddde</MediaTimemapBA>",
|
|
191
|
-
" <LastChangedTime>0</LastChangedTime>",
|
|
192
|
-
" <LastRenderedTime>0</LastRenderedTime>",
|
|
193
|
-
" <IsMarkedForCaching>false</IsMarkedForCaching>",
|
|
194
|
-
" <IsForceConformed>true</IsForceConformed>",
|
|
195
|
-
" <MatchConflictState>0</MatchConflictState>",
|
|
196
|
-
" <UseOppositeSrcForLeftEye>false</UseOppositeSrcForLeftEye>",
|
|
197
|
-
" <UseOppositeSrcForRightEye>false</UseOppositeSrcForRightEye>",
|
|
198
|
-
" <RenderCacheBA/>",
|
|
199
|
-
" <CurrentSelectorIdx>1</CurrentSelectorIdx>",
|
|
200
|
-
" <IsPreConformed>false</IsPreConformed>",
|
|
201
|
-
" <PreConformMediaExtents>00000100000030c20000010000003042</PreConformMediaExtents>",
|
|
202
|
-
" <MediaMetadata/>",
|
|
203
|
-
" <Thumbnail>",
|
|
204
|
-
f' <BtThumnail DbId="{uuid.uuid4()}">',
|
|
205
|
-
" <FieldsBlob/>",
|
|
206
|
-
" <ImgWidth>-1</ImgWidth>",
|
|
207
|
-
" <ImgHeight>-1</ImgHeight>",
|
|
208
|
-
" <Buffer/>",
|
|
209
|
-
" </BtThumnail>",
|
|
210
|
-
" </Thumbnail>",
|
|
211
|
-
" <ThumbnailDirtyFlag>true</ThumbnailDirtyFlag>",
|
|
212
|
-
"</Sm2TiVideoClip>",
|
|
213
|
-
]
|
|
214
|
-
return ("\n" + indent).join(lines)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
def _tag(item: str, name: str) -> str | None:
|
|
218
|
-
found = re.search(f"<{name}>([^<]*)</{name}>", item)
|
|
219
|
-
return html.unescape(found.group(1)) if found else None
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def _sequences(archive: zipfile.ZipFile):
|
|
223
|
-
return [
|
|
224
|
-
info
|
|
225
|
-
for info in archive.infolist()
|
|
226
|
-
if info.filename.startswith("SeqContainer/") and info.filename.endswith(".xml")
|
|
227
|
-
]
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
def uses(source: Path, components: Path) -> bool:
|
|
231
|
-
"""Whether a .drt has clips that point at the component PNGs in components."""
|
|
232
|
-
marker = "<MediaFilePath>" + unicodedata.normalize("NFC", html.escape(str(components), quote=False)) + "/"
|
|
233
|
-
try:
|
|
234
|
-
with zipfile.ZipFile(source) as archive:
|
|
235
|
-
return any(
|
|
236
|
-
marker in unicodedata.normalize("NFC", archive.read(info).decode("utf-8", "replace"))
|
|
237
|
-
for info in _sequences(archive)
|
|
238
|
-
)
|
|
239
|
-
except (OSError, zipfile.BadZipFile):
|
|
240
|
-
return False
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
def convert(source: Path, target: Path) -> int:
|
|
244
|
-
"""Write target: the Resolve timeline at source with every Clipen component PNG made a Fusion title.
|
|
245
|
-
|
|
246
|
-
The components' type lives in the manifest beside their PNGs, found through each clip's file
|
|
247
|
-
path. Returns how many clips were replaced."""
|
|
248
|
-
manifests: dict[Path, dict] = {}
|
|
249
|
-
|
|
250
|
-
def entry(path: Path):
|
|
251
|
-
folder = path.parent
|
|
252
|
-
if folder not in manifests:
|
|
253
|
-
try:
|
|
254
|
-
manifests[folder] = json.loads((folder / MANIFEST).read_text(encoding="utf-8"))
|
|
255
|
-
except (OSError, ValueError):
|
|
256
|
-
manifests[folder] = {}
|
|
257
|
-
return manifests[folder].get(path.name)
|
|
258
|
-
|
|
259
|
-
replaced = 0
|
|
260
|
-
|
|
261
|
-
def swap(match: re.Match) -> str:
|
|
262
|
-
nonlocal replaced
|
|
263
|
-
item = match.group(0)
|
|
264
|
-
path = _tag(item, "MediaFilePath")
|
|
265
|
-
component = entry(Path(path)) if path else None
|
|
266
|
-
if not component:
|
|
267
|
-
return item
|
|
268
|
-
start, duration = int(_tag(item, "Start")), int(_tag(item, "Duration"))
|
|
269
|
-
picture = Path(path).parent / component["picture"] if component["picture"] else None
|
|
270
|
-
width, height = component["width"], component["height"]
|
|
271
|
-
comp = composition(tools(component["rows"], picture, width, height, duration), width, height, duration)
|
|
272
|
-
indent = match.string[match.string.rfind("\n", 0, match.start()) + 1 : match.start()]
|
|
273
|
-
replaced += 1
|
|
274
|
-
return title_item(
|
|
275
|
-
start, duration, _tag(item, "MediaFrameRate") or "0000000000003e400000000000000000", comp, indent
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
try:
|
|
279
|
-
archive = zipfile.ZipFile(source)
|
|
280
|
-
except (OSError, zipfile.BadZipFile) as error:
|
|
281
|
-
raise ProjectError(
|
|
282
|
-
"resolve_timeline_unreadable", "這個檔案不是 DaVinci Resolve 匯出的 .drt 時間線。", status_code=409
|
|
283
|
-
) from error
|
|
284
|
-
with archive, zipfile.ZipFile(target, "w", zipfile.ZIP_DEFLATED) as out:
|
|
285
|
-
sequences = {info.filename for info in _sequences(archive)}
|
|
286
|
-
for info in archive.infolist():
|
|
287
|
-
data = archive.read(info)
|
|
288
|
-
if info.filename in sequences:
|
|
289
|
-
data = _ITEM.sub(swap, data.decode("utf-8")).encode("utf-8")
|
|
290
|
-
out.writestr(info, data)
|
|
291
|
-
return replaced
|