-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathrename_meta_to_content.py
156 lines (118 loc) · 4.84 KB
/
rename_meta_to_content.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
bl_info = {
'name': 'Rename meta to content',
'author': 'Sybren A. Stüvel',
'version': (1, 0),
'blender': (2, 77, 0),
'location': 'Video Sequence Editor',
'category': 'Sequencer',
}
import bpy
class SEQUENCER_OT_setup_meta(bpy.types.Operator):
bl_idname = 'sequencer.setup_meta'
bl_label = 'Set up meta strip'
bl_description = 'Renames the selected meta strip to the video strip it contains, and sets up proxies'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return any(s.type == 'META' for s in context.selected_sequences)
def execute(self, context):
meta_strips = (s for s in context.selected_sequences
if s.type == 'META')
for strip in meta_strips:
strip.use_proxy = False
candidates = []
for sub in strip.sequences:
if sub.type == 'MOVIE':
candidates.insert(0, bpy.path.basename(sub.filepath))
sub.use_proxy = True
sub.proxy.build_25 = False
sub.proxy.build_50 = True
sub.proxy.quality = 80
else:
candidates.append(sub.name)
if candidates:
strip.name = candidates[0]
return {'FINISHED'}
class SEQUENCER_OT_mute_audio(bpy.types.Operator):
bl_idname = 'sequencer.mute_audio'
bl_label = 'Toggle audio in meta strips'
bl_description = 'Mutes/unmutes the audio inside selected meta strips'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not context.scene.sequence_editor:
return False
return any(s.type == 'META' for s in context.selected_sequences)
def execute(self, context):
# Figure out what to do (mute/unmute)
se = context.scene.sequence_editor
act_strip = se.active_strip
mute = True
for sub in act_strip.sequences:
if sub.type != 'SOUND':
continue
mute = not sub.mute
break
for strip in context.selected_sequences:
if strip.type != 'META':
continue
for sub in strip.sequences:
if sub.type != 'SOUND':
continue
sub.mute = mute
return {'FINISHED'}
class SEQUENCER_OT_unmeta(bpy.types.Operator):
bl_idname = 'sequencer.unmeta'
bl_label = 'Crop contents'
bl_description = 'Crops contents to start/end of meta strip'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
if not context.scene.sequence_editor:
return False
return any(s.type == 'META' for s in context.selected_sequences)
def execute(self, context):
for strip in context.selected_sequences:
if strip.type != 'META':
continue
for sub in strip.sequences:
sub.frame_start = strip.frame_start
sub.frame_offset_start = strip.frame_offset_start
sub.frame_offset_end = strip.frame_offset_end
return {'FINISHED'}
class SEQUENCER_OT_select_here(bpy.types.Operator):
bl_idname = 'sequencer.select_here'
bl_label = 'Select strips at current frame'
bl_description = 'Selects only those strips that overlap with the current frame'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
return context.scene.sequence_editor and context.scene.sequence_editor.sequences
def execute(self, context):
fra = context.scene.frame_current
for strip in context.scene.sequence_editor.sequences:
strip.select = strip.frame_final_start <= fra < strip.frame_final_end
strip.select_left_handle = strip.select
strip.select_right_handle = False
return {'FINISHED'}
def render_header(self, context):
layout = self.layout
layout.operator(SEQUENCER_OT_setup_meta.bl_idname)
layout.operator(SEQUENCER_OT_mute_audio.bl_idname)
layout.operator(SEQUENCER_OT_unmeta.bl_idname)
def render_select_menu(self, context):
layout = self.layout
layout.operator(SEQUENCER_OT_select_here.bl_idname)
def register():
bpy.utils.register_class(SEQUENCER_OT_setup_meta)
bpy.utils.register_class(SEQUENCER_OT_mute_audio)
bpy.utils.register_class(SEQUENCER_OT_unmeta)
bpy.utils.register_class(SEQUENCER_OT_select_here)
bpy.types.SEQUENCER_HT_header.append(render_header)
bpy.types.SEQUENCER_MT_select.append(render_select_menu)
def unregister():
bpy.utils.unregister_class(SEQUENCER_OT_setup_meta)
bpy.utils.unregister_class(SEQUENCER_OT_mute_audio)
bpy.utils.unregister_class(SEQUENCER_OT_unmeta)
bpy.utils.unregister_class(SEQUENCER_OT_select_here)
bpy.types.SEQUENCER_HT_header.remove(render_header)