-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBatch_Exporter_chs.py
443 lines (388 loc) · 17.9 KB
/
Batch_Exporter_chs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# -*- coding:utf-8 -*-
# Author: 张来吃
# Version: 1.0.0
# Contact: laciechang@163.com
# -----------------------------------------------------
# 本工具仅支持在达芬奇内运行 请将工具移至以下路径:
# macOS: /Users/{USER}/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Edit
# Windows: C:\Users\{USER}\AppData\Roaming\Blackmagic Design\DaVinci Resolve\Support\Fusion\Scripts\Edit
# -----------------------------------------------------
import os, subprocess, platform
resolve = bmd.scriptapp('Resolve')
fu = bmd.scriptapp('Fusion')
ui = fu.UIManager
disp = bmd.UIDispatcher(ui)
class Project():
def __init__(self) -> None:
self.project_manager = resolve.GetProjectManager()
self.current_project = self.project_manager.GetCurrentProject()
self.project_name = self.current_project.GetName()
self.projects = self.project_manager.GetProjectListInCurrentFolder()
def export_project(self, name, path, option=True):
self.project_manager.LoadProject(name)
o = self.project_manager.ExportProject(name, path+str(name)+".drp", option)
def current_timeline(self):
return self.project_manager.GetCurrentProject().GetCurrentTimeline()
def all_timelines_in_current_project(self):
for i in range(1, self.project_manager.GetCurrentProject().GetTimelineCount()+1):
yield self.project_manager.GetCurrentProject().GetTimelineByIndex(i)
def export_timeline(self, name, path, types):
if type(types) is list:
self.current_timeline().Export(path + name, types[0], types[1])
else:
self.current_timeline().Export(path + name, types)
def add_render_job(self, preset, path):
current_project = self.project_manager.GetCurrentProject()
current_project.LoadRenderPreset(preset)
current_project.SetRenderSettings({"TargetDir": path})
current_project.AddRenderJob()
def get_render_preset(self) -> list:
ls = self.project_manager.GetCurrentProject().GetRenderPresetList()
ls.reverse()
return ls
PROJECT = Project()
Current_folder_name = str(PROJECT.project_manager.GetCurrentFolder())
TimelineErrorMsg = "时间线获取失败,试试时间线能否打开,或者确认工程内是否还未新建时间线"
ProjectErrorMsg = "项目获取失败 请确认当前文件夹内有已保存的项目"
UnknowErrorMsg = "怪了 选项没勾上么"
CheckState = {"Checked": True, "Unchecked": False}
Timeline_Type = {
"FCP7 XML": {"suffix": ".xml","type": resolve.EXPORT_FCP_7_XML,},
"EDL - CMX 3600": {"suffix": ".edl","type": [resolve.EXPORT_EDL, resolve.EXPORT_NONE],},
"FCPXML 1.3": {"suffix": ".fcpxml","type": resolve.EXPORT_FCPXML_1_3,},
"FCPXML 1.4": {"suffix": ".fcpxml","type": resolve.EXPORT_FCPXML_1_4,},
"FCPXML 1.5": {"suffix": ".fcpxml","type": resolve.EXPORT_FCPXML_1_5,},
"FCPXML 1.6": {"suffix": ".fcpxml","type": resolve.EXPORT_FCPXML_1_6,},
"FCPXML 1.7": {"suffix": ".fcpxml","type": resolve.EXPORT_FCPXML_1_7,},
"FCPXML 1.8": {"suffix": ".fcpxml","type": resolve.EXPORT_FCPXML_1_8,},
"AAF": {"suffix": ".aaf","type": [resolve.EXPORT_AAF, resolve.EXPORT_AAF_NEW],},
"DaVinci Resolve Timeline": {"suffix": ".drt", "type": resolve.EXPORT_DRT,},
"EDL - CDL": {"suffix": ".edl","type": [resolve.EXPORT_EDL, resolve.EXPORT_CDL],},
"EDL - SDL": {"suffix": ".edl","type": [resolve.EXPORT_EDL, resolve.EXPORT_SDL],},
"EDL - Missing Clips": {"suffix": ".edl","type": [resolve.EXPORT_EDL, resolve.EXPORT_MISSING_CLIPS],},
"HDR10 Profile A": {"suffix": ".xml", "type": resolve.EXPORT_HDR_10_PROFILE_A,},
"HDR10 Profile B": {"suffix": ".xml", "type": resolve.EXPORT_HDR_10_PROFILE_B,},
"Dolby Vision 2.9": {"suffix": ".xml", "type": resolve.EXPORT_DOLBY_VISION_VER_2_9,},
"Dolby Vision 4.0": {"suffix": ".xml", "type": resolve.EXPORT_DOLBY_VISION_VER_4_0},
"CSV": {"suffix": ".csv","type": resolve.EXPORT_TEXT_CSV,},
"Tabbed Text": {"suffix": ".txt","type": resolve.EXPORT_TEXT_TAB,},
}
SplitLine = {"StyleSheet": "max-height: 1px; background-color: rgb(10,10,10)",}
AllProject = 'AllProject'
CurrentProject = 'CurrentProject'
AllTimeline = 'AllTimeline'
CurrentTimeline = 'CurrentTimeline'
OutputPath = 'OutputPath'
RenderPreset = 'RenderPreset'
OutputPick = 'OutputPick'
NamePrefix = 'NamePrefix'
NameSuffix = 'NameSuffix'
ExportProj = 'ExportProj'
ExportTimelineFiles = 'ExportTimelineFiles'
ExportTimeline = 'ExportTimeline'
ExportTimelineType = 'ExportTimelineType'
RenderTimeline = 'RenderTimeline'
ProgressBarBG = 'ProgressBarBG'
ProgressBar = 'ProgressBar'
ExportTimelineFilesGroup = 'ExportTimelineFilesGroup'
MainFilter = 'MainFilter'
FilteredList = 'FilteredList'
InvertFilter = 'InvertFilter'
ExportTimelineGroup = 'ExportTimelineGroup'
filteredlist_group = ui.VGroup({"Spacing": 5},[
ui.Tree({"ID": FilteredList, "AlternatingRowColors": True, "HeaderHidden": True,}),
ui.HGroup({"Weight": 0, "Visible": False}, [
ui.LineEdit({"ID": MainFilter, "PlaceholderText": "过滤一下"}),
ui.CheckBox({"ID":InvertFilter, "Text": "反选", "Weight": 0})
]),
])
naming_group = ui.VGroup({"Spacing": 5, },[
ui.ComboBox({"ID": ExportTimelineType, }),
ui.LineEdit({"ID": NamePrefix, "PlaceholderText": "文件名前缀"}),
ui.LineEdit({"ID": NameSuffix, "PlaceholderText": "文件名后缀"}),
])
location_group = ui.HGroup({"Spacing": 5, "Weight": 3},[
ui.Button({"ID": OutputPick, "Text": "选取位置", "Weight": 0}),
ui.LineEdit({"ID": OutputPath, "PlaceholderText": "导出路径"}),
])
project_level_group = ui.HGroup({"Spacing": 5, "Weight": 0},[
ui.VGroup({"Weight": 1},[
ui.Label({"Text": "要导出的项目范围", "Alignment": {"AlignRight": True, "AlignVCenter": True}}),
ui.VGap()
]),
ui.VGroup({"Spacing": 5, "Weight": 1},[
ui.CheckBox({"ID": CurrentProject, "Checked": True, "AutoExclusive": True, "Checkable": True, "Events": {"Toggled": True}}),
ui.CheckBox({"ID": AllProject, "AutoExclusive": True, "Checkable": True, "Events": {"Toggled": True}}),
])
])
project_content_or_itself = ui.HGroup({"Spacing": 5, "Weight": 0},[
ui.VGroup({"Weight": 1},[
ui.Label({"Text": "要导出的项目内容", "Alignment": {"AlignRight": True}}),
ui.VGap()
]),
ui.VGroup({"Spacing": 5, "Weight": 1},[
ui.CheckBox({"ID": ExportTimelineFiles, "Checked": True,"Text": "导出时间线", "AutoExclusive": True, "Checkable": True, "Events": {"Toggled": True}}),
ui.CheckBox({"ID": RenderTimeline, "AutoExclusive": True, "Checkable": True, "Events": {"Toggled": True}}),
ui.CheckBox({"ID": ExportProj, "AutoExclusive": True, "Checkable": True , "Events": {"Toggled": True}, "Visible": False}),
])
])
timeline_level_group = ui.HGroup({"Spacing": 5, "Weight": 0},[
ui.VGroup({"Weight": 1},[
ui.Label({"Text": "要导出的时间线", "Alignment": {"AlignRight": True, "AlignVCenter": True}}),
ui.VGap()
]),
ui.VGroup({"Spacing": 5, "Weight": 1},[
ui.CheckBox({"ID": AllTimeline, "Checked": True , "AutoExclusive": True, "Checkable": True, "Events": {"Toggled": True}}),
ui.CheckBox({"ID": CurrentTimeline, "AutoExclusive": True, "Checkable": True, "Events": {"Toggled": True}, "Visible": False}),
])
])
render_options = ui.HGroup({"Spacing": 5, "Weight": 0},[
ui.Label({"Text": "使用渲染预设", "Alignment": {"AlignRight": True}}),
ui.ComboBox({"ID": RenderPreset, })
])
timeline_options = ui.HGroup({"Spacing": 5, "Weight": 0},[
ui.Label({"Text": "将时间线导出为", "Alignment": {"AlignRight": True}}),
naming_group,
])
window_01 = ui.VGroup([
ui.Label({"Text": "<a href='https://github.com/laciechang/resolve-batch-exporter' style='color: #FA5B4A; text-decoration: none'>批量导出工具</a>", "Alignment": {"AlignHCenter": True, "AlignVCenter": True}, "Weight": 0.1, "OpenExternalLinks" : True,}),
ui.HGroup({"Spacing": 1},
[
ui.VGroup({"Spacing": 15, "Weight": 3},[
ui.Label(SplitLine),
project_level_group,
ui.Label({"StyleSheet": "max-height: 5px;"}),
ui.Label(SplitLine),
project_content_or_itself,
ui.Label(SplitLine),
ui.Stack({"ID": ExportTimelineFilesGroup, "Weight": 0},[
ui.VGroup({"Spacing": 5, "Weight": 0},[ui.VGap()]),
ui.VGroup({"Spacing": 5, "Weight": 0},[
timeline_level_group,
ui.Label({"StyleSheet": "max-height: 10px;"}),
ui.Stack({"ID": ExportTimelineGroup},[
ui.VGroup({"Spacing": 5, "Weight": 0},[
timeline_options,
]),
ui.VGroup({"Spacing": 5, "Weight": 0},[
render_options
]),
]),
]),
]),
ui.Label({"StyleSheet": "max-height: 5px;"}),
ui.Label(SplitLine),
]),
ui.Label({"Weight": 0, "StyleSheet": "max-width: 30px;"}),
]
),
ui.HGroup({"Weight": 0},[
location_group,
ui.Button({"ID": "Run", "Text": "导出", "Weight": 0, "Enabled": False})
]),
ui.Label({"StyleSheet": "max-height: 10px;"}),
])
dlg = disp.AddWindow({
"WindowTitle": "Batch Exporter",
"ID": "MyWin",
"Geometry": [
100, 300, # position when starting
400, 630 #width, height
],
"WindowFlags":{
"Window": True,
}
}, window_01)
itm = dlg.GetItems()
itm[CurrentProject].Text = "仅此项目"
itm[AllProject].Text = "当前{0}文件夹内的项目".format("根" if len(Current_folder_name) == 0 else Current_folder_name )
itm[ExportTimelineFiles].Text = "导出时间线"
itm[RenderTimeline].Text = "渲染时间线"
itm[AllTimeline].Text = "项目内所有时间线"
itm[CurrentTimeline].Text = "当前时间线"
itm[ExportProj].Text = "直接导出项目"
itm[CurrentProject].ToolTip = "在当前打开的项目内进行导出"
itm[ExportTimelineFiles].ToolTip = "等同于菜单中 文件 > 导出 > 时间线"
itm[RenderTimeline].ToolTip = "等同于交付页面中 添加渲染任务"
itm[AllTimeline].ToolTip = "当前项目内所有的时间线"
itm[CurrentTimeline].ToolTip = "等同于打开项目时默认开启的时间线"
itm[ExportProj].ToolTip = "将项目导出为.drp文件"
itm[AllProject].ToolTip = """即项目管理器中所处文件夹内的所有项目
注意 为了防止重名
此时导出的时间线文件将会导出到 按项目名称命名 的子文件夹"""
itm[RenderPreset].ToolTip = """建议在自定义的预设中
确认渲染出的路径、文件名等
不会因为重名而导致文件覆盖"""
itm[ExportTimelineFilesGroup].CurrentIndex = 1
itm[ExportTimelineGroup].CurrentIndex = 0
itm[ExportTimelineType].AddItems(list(Timeline_Type.keys()))
itm[RenderPreset].AddItems(list(PROJECT.get_render_preset()))
def error_dialog(msg):
msg_main = ui.VGroup({"Spacing": 10}, [
ui.Label({"ID": "msginfo","Text": msg, "Alignment": {"AlignHCenter": True, "AlignVCenter": True}}),
ui.HGroup([
ui.HGap(),
ui.Button({"Text": "好的", "ID":"closeit","Weight": 0}),
ui.HGap(),
])
])
msg_win = disp.AddWindow({
"WindowTitle": "Batch Exporter",
"ID": "err_msg",
"WindowFlags": {"SplashScreen" : True},
}, msg_main)
msg_itm = msg_win.GetItems()
width = 300 + len(msg)*5
width = width if width > 200 else 200
msg_itm["err_msg"].Resize([width, 80])
def _close(ev):
disp.ExitLoop()
msg_win.On["err_msg"].Close = _close
msg_win.On["closeit"].Clicked = _close
msg_win.Show()
disp.RunLoop()
msg_win.Hide()
def success_dialog(folder):
msg = "导出完成"
msg_main = ui.VGroup({"Spacing": 10}, [
ui.Label({"Text": msg, "Alignment": {"AlignHCenter": True, "AlignVCenter": True}}),
ui.HGroup([
ui.HGap(),
ui.Button({"Text": "打开看看", "ID":"closeit","Weight": 0}),
ui.HGap(),
])
])
msg_win = disp.AddWindow({
"WindowTitle": "Batch Exporter",
"ID": "success_msg",
"WindowFlags": {"SplashScreen" : True},
}, msg_main)
msg_itm = msg_win.GetItems()
width = 300 + len(msg)*5
width = width if width > 200 else 200
msg_itm["success_msg"].Resize([width, 80])
def _close(ev):
disp.ExitLoop()
def _close_and_open_folder(ev):
if platform.system() == "Windows":
os.startfile(folder)
elif platform.system() == "Darwin":
subprocess.Popen(["open", folder])
else:
subprocess.Popen(["xdg-open", folder])
disp.ExitLoop()
msg_win.On["success_msg"].Close = _close
msg_win.On["closeit"].Clicked = _close_and_open_folder
msg_win.Show()
disp.RunLoop()
msg_win.Hide()
def _ExportProj(ev):
if checkstate(ExportProj):
itm[ExportTimelineFilesGroup].CurrentIndex = 0
else:
itm[ExportTimelineFilesGroup].CurrentIndex = 1
if checkstate(RenderTimeline):
itm[ExportTimelineGroup].CurrentIndex = 1
else:
itm[ExportTimelineGroup].CurrentIndex = 0
def _show_project_list(ev):
if checkstate(AllProject):
itm[ExportProj].Visible = True
itm[CurrentTimeline].Visible = True
else:
itm[ExportProj].Visible = False
itm[CurrentTimeline].Visible = False
itm[ExportTimelineFiles].Checked = True
itm[AllTimeline].Checked = True
def _show_timeline_list(ev):
itm[FilteredList].Clear()
if checkstate(AllTimeline):
timelines = list(PROJECT.all_timelines_in_current_project())
toplevelitems = []
for i in timelines:
row = itm[FilteredList].NewItem()
row.Text[0] = i.GetName()
toplevelitems.append(row)
itm[FilteredList].AddTopLevelItems(toplevelitems)
def _pickfile(ev):
selected = fu.RequestDir()
itm[OutputPath].Text = str(selected)
return selected
def _fresh_run_button(ev):
if len(itm[OutputPath].Text) > 0:
itm["Run"].Enabled = True
else:
itm["Run"].Enabled = False
def _exit(ev):
disp.ExitLoop()
dlg.On.MyWin.Close = _exit
def use_project_name_subfolder(folder):
folder = folder + str(Project().project_name) + "/"
os.mkdir(folder)
return folder
def checkstate(name):
return CheckState[itm[name].GetCheckState()]
def export_in_project(projectName):
p = Project()
output_folder = itm[OutputPath].Text
if checkstate(ExportProj):
p.export_project(projectName, output_folder)
else:
p.project_manager.LoadProject(projectName)
#############################################
if checkstate(RenderTimeline):
# render
if checkstate(AllTimeline):
timelines = p.all_timelines_in_current_project()
for timeline in timelines:
try:
p.current_project.SetCurrentTimeline(timeline)
p.add_render_job(itm[RenderPreset].CurrentText, output_folder)
except:
error_dialog(TimelineErrorMsg)
elif checkstate(CurrentTimeline):
p.add_render_job(itm[RenderPreset].CurrentText, output_folder)
else:
error_dialog(UnknowErrorMsg)
#############################################
elif checkstate(ExportTimelineFiles):
if checkstate(AllProject):
output_folder = use_project_name_subfolder(output_folder)
timelines = p.all_timelines_in_current_project()
type_name = itm[ExportTimelineType].CurrentText
if checkstate(AllTimeline):
for timeline in timelines:
try:
p.current_project.SetCurrentTimeline(timeline)
name = itm[NamePrefix].Text+timeline.GetName()+itm[NameSuffix].Text + Timeline_Type[type_name]["suffix"]
o = p.export_timeline(name, output_folder, Timeline_Type[type_name]["type"])
except:
error_dialog(TimelineErrorMsg)
elif checkstate(CurrentTimeline):
name = itm[NamePrefix].Text+p.current_timeline().GetName()+itm[NameSuffix].Text + Timeline_Type[type_name]["suffix"]
o = p.export_timeline(name, output_folder, Timeline_Type[type_name]["type"])
else:
error_dialog(UnknowErrorMsg)
else:
error_dialog(UnknowErrorMsg)
def _run(ev):
try:
if checkstate(AllProject):
projects = Project().project_manager.GetProjectListInCurrentFolder()
elif checkstate(CurrentProject):
projects = [Project().current_project]
for projectName in projects:
export_in_project(projectName)
if not checkstate(RenderTimeline):
success_dialog(itm[OutputPath].Text)
except:
error_dialog(ProjectErrorMsg)
dlg.On[AllProject].Toggled = _show_project_list
dlg.On[ExportProj].Toggled = _ExportProj
dlg.On[ExportTimelineFiles].Toggled = _ExportProj
dlg.On[OutputPick].Clicked = _pickfile
dlg.On[OutputPath].TextChanged = _fresh_run_button
dlg.On["Run"].Clicked = _run
dlg.Show()
disp.RunLoop()
dlg.Hide()