-
Notifications
You must be signed in to change notification settings - Fork 4
/
recursive_loader.py
261 lines (222 loc) · 8.98 KB
/
recursive_loader.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
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
import bpy
import random
import math
import os, sys
from bpy.props import IntProperty
from bpy.props import FloatProperty
from bpy.props import EnumProperty
from bpy.props import BoolProperty
from bpy.props import StringProperty
from . import functions
from . import exiftool
class Sequencer_Extra_RecursiveLoader(bpy.types.Operator):
bl_idname = "sequencerextra.recursiveload"
bl_label = "recursive load"
bl_options = {'REGISTER', 'UNDO'}
recursive = BoolProperty(
name='recursive',
description='Load in recursive folders',
default=False)
recursive_select_by_extension = BoolProperty(
name='select by extension',
description='Load only clips with selected extension',
default=False)
ext = EnumProperty(
items=functions.movieextdict,
name="extension",
default="3")
@classmethod
def poll(self, context):
scn = context.scene
if scn and scn.sequence_editor:
return (scn.sequence_editor)
else:
return False
def invoke(self, context, event):
scn = context.scene
try:
self.recursive = scn.kr_recursive
self.recursive_select_by_extension = scn.kr_recursive_select_by_extension
self.ext = scn.kr_default_ext
except AttributeError:
functions.initSceneProperties(context)
self.recursive = scn.kr_recursive
self.recursive_select_by_extension = scn.kr_recursive_select_by_extension
self.ext = scn.kr_default_ext
return context.window_manager.invoke_props_dialog(self)
def loader(self, context, filelist):
scn = context.scene
if filelist:
for i in filelist:
functions.setpathinbrowser(context, i[0], i[1])
try:
bpy.ops.sequencerextra.placefromfilebrowser()
except:
print("Error loading file (recursive loader error): ", i[1])
functions.add_marker(context, i[1], scn.frame_current)
self.report({'ERROR_INVALID_INPUT'}, 'Error loading file ')
pass
def execute(self, context):
scn = context.scene
if self.recursive == True:
#recursive
self.loader(context, functions.sortlist(\
functions.recursive(context, self.recursive_select_by_extension,\
self.ext)))
else:
#non recursive
self.loader(context, functions.sortlist(functions.onefolder(\
context, self.recursive_select_by_extension, self.ext)))
try:
scn.kr_recursive = self.recursive
scn.kr_recursive_select_by_extension = self.recursive_select_by_extension
scn.kr_default_ext = self.ext
except AttributeError:
functions.initSceneProperties(context)
self.recursive = scn.kr_recursive
self.recursive_select_by_extension = scn.kr_recursive_select_by_extension
self.ext = scn.kr_default_ext
return {'FINISHED'}
# READ EXIF DATA
class Sequencer_Extra_ReadExifData(bpy.types.Operator):
# load exifdata from strip to scene['metadata'] property
bl_label = 'Read EXIF Data'
bl_idname = 'sequencerextra.read_exif'
bl_description = 'Load exifdata from strip to metadata property in scene'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(self, context):
scn=context.scene
if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
return scn.sequence_editor.active_strip.type in ('IMAGE', 'MOVIE')
else:
return False
def execute(self, context):
try:
exiftool.ExifTool().start()
except:
self.report({'ERROR_INVALID_INPUT'},
'exiftool not found in PATH')
return {'CANCELLED'}
def getexifdata(strip):
def getexifvalues_image(lista):
metadata = []
with exiftool.ExifTool() as et:
try:
metadata = et.get_metadata_batch(lista)
except UnicodeDecodeError as Err:
print(Err)
#print(metadata[0])
print(len(metadata))
return metadata
def getexifvalues_movie(path):
metadata = []
with exiftool.ExifTool() as et:
try:
metadata = et.get_metadata_batch([path])
except UnicodeDecodeError as Err:
print(Err)
print(metadata[0])
print(len(metadata))
return metadata
def getlist(lista):
for root, dirs, files in os.walk(path):
for f in files:
if "." + f.rpartition(".")[2].lower() \
in functions.imb_ext_image:
lista.append(f)
#if "."+f.rpartition(".")[2] in imb_ext_movie:
# lista.append(f)
strip.elements
lista.sort()
return lista
if strip.type == "IMAGE":
path = bpy.path.abspath(strip.directory)
os.chdir(path)
#get a list of files
lista = []
for i in strip.elements:
lista.append(i.filename)
print(lista)
return getexifvalues_image(lista)
if strip.type == "MOVIE":
path = bpy.path.abspath(strip.filepath)
print([path])
return getexifvalues_movie(path)
sce = bpy.context.scene
frame = sce.frame_current
text = bpy.context.active_object
strip = context.scene.sequence_editor.active_strip
sce['metadata'] = getexifdata(strip)
return {'FINISHED'}
class ExifInfoPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
""" TODO: fix poll to hide when unuseful"""
bl_label = "EXIF Info Panel"
bl_space_type = 'SEQUENCE_EDITOR'
bl_region_type = 'UI'
@classmethod
def poll(self, context):
if context.space_data.view_type in {'SEQUENCER', 'SEQUENCER_PREVIEW'}:
strip = functions.act_strip(context)
scn = context.scene
preferences = context.user_preferences
prefs = preferences.addons[__package__].preferences
if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
if prefs.use_exif_panel:
return strip.type in ('MOVIE', 'IMAGE')
else:
return False
def draw_header(self, context):
layout = self.layout
layout.label(text="", icon="RADIO")
def draw(self, context):
layout = self.layout
sce = context.scene
row = layout.row()
row.operator("sequencerextra.read_exif")
row = layout.row()
row.label(text="Exif Data", icon='RENDER_REGION')
row = layout.row()
try:
strip = context.scene.sequence_editor.active_strip
f = strip.frame_start
frame = sce.frame_current
try:
if len(sce['metadata']) == 1:
for d in sce['metadata'][0]:
split = layout.split(percentage=0.5)
col = split.column()
row = col.row()
col.label(text=d)
col = split.column()
col.label(str(sce['metadata'][0][d]))
else:
for d in sce['metadata'][frame - f]:
split = layout.split(percentage=0.5)
col = split.column()
row = col.row()
col.label(text=d)
col = split.column()
col.label(str(sce['metadata'][frame - f][d]))
except (IndexError, KeyError):
pass
except AttributeError:
pass