2010-06-15 12:06:30 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# ##### 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 #####
|
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
|
|
|
|
# This module can get render info without running from inside blender.
|
|
|
|
#
|
|
|
|
# This struct wont change according to Ton.
|
|
|
|
# Note that the size differs on 32/64bit
|
|
|
|
#
|
|
|
|
# typedef struct BHead {
|
|
|
|
# int code, len;
|
|
|
|
# void *old;
|
|
|
|
# int SDNAnr, nr;
|
|
|
|
# } BHead;
|
|
|
|
|
2010-07-05 22:22:22 +00:00
|
|
|
|
2010-06-15 12:06:30 +00:00
|
|
|
def read_blend_rend_chunk(path):
|
|
|
|
|
|
|
|
import struct
|
|
|
|
|
2010-07-05 22:22:22 +00:00
|
|
|
blendfile = open(path, 'rb')
|
|
|
|
|
|
|
|
head = blendfile.read(7)
|
2010-06-15 12:06:30 +00:00
|
|
|
|
2010-09-07 15:17:42 +00:00
|
|
|
if head[0:2] == b'\x1f\x8b': # gzip magic
|
2010-06-15 12:06:30 +00:00
|
|
|
import gzip
|
2010-07-05 22:22:22 +00:00
|
|
|
blendfile.close()
|
|
|
|
blendfile = gzip.open(path, 'rb')
|
|
|
|
head = blendfile.read(7)
|
2010-06-15 12:06:30 +00:00
|
|
|
|
|
|
|
if head != b'BLENDER':
|
|
|
|
print("not a blend file:", path)
|
2010-07-05 22:22:22 +00:00
|
|
|
blendfile.close()
|
2010-06-15 12:06:30 +00:00
|
|
|
return []
|
|
|
|
|
2010-07-05 22:22:22 +00:00
|
|
|
is_64_bit = (blendfile.read(1) == b'-')
|
2010-06-15 12:06:30 +00:00
|
|
|
|
|
|
|
# true for PPC, false for X86
|
2010-07-05 22:22:22 +00:00
|
|
|
is_big_endian = (blendfile.read(1) == b'V')
|
2010-06-15 12:06:30 +00:00
|
|
|
|
|
|
|
# Now read the bhead chunk!!!
|
2010-09-07 15:17:42 +00:00
|
|
|
blendfile.read(3) # skip the version
|
2010-06-15 12:06:30 +00:00
|
|
|
|
|
|
|
scenes = []
|
2010-07-05 22:22:22 +00:00
|
|
|
|
2010-06-15 12:06:30 +00:00
|
|
|
sizeof_bhead = 24 if is_64_bit else 20
|
|
|
|
|
2010-07-05 22:22:22 +00:00
|
|
|
while blendfile.read(4) == b'REND':
|
2010-06-15 12:06:30 +00:00
|
|
|
sizeof_bhead_left = sizeof_bhead - 4
|
2010-07-05 22:22:22 +00:00
|
|
|
|
|
|
|
struct.unpack('>i' if is_big_endian else '<i', blendfile.read(4))[0]
|
2010-06-15 12:06:30 +00:00
|
|
|
sizeof_bhead_left -= 4
|
|
|
|
|
2011-10-17 06:58:07 +00:00
|
|
|
# We don't care about the rest of the bhead struct
|
2010-07-05 22:22:22 +00:00
|
|
|
blendfile.read(sizeof_bhead_left)
|
|
|
|
|
2010-06-15 12:06:30 +00:00
|
|
|
# Now we want the scene name, start and end frame. this is 32bites long
|
2010-07-05 22:22:22 +00:00
|
|
|
start_frame, end_frame = struct.unpack('>2i' if is_big_endian else '<2i', blendfile.read(8))
|
2010-06-15 12:06:30 +00:00
|
|
|
|
2010-07-05 22:22:22 +00:00
|
|
|
scene_name = blendfile.read(24)
|
2010-06-15 12:06:30 +00:00
|
|
|
|
|
|
|
scene_name = scene_name[:scene_name.index(b'\0')]
|
|
|
|
|
|
|
|
try:
|
|
|
|
scene_name = str(scene_name, 'utf8')
|
|
|
|
except TypeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
scenes.append((start_frame, end_frame, scene_name))
|
|
|
|
|
|
|
|
return scenes
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
import sys
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
if arg.lower().endswith('.blend'):
|
|
|
|
for value in read_blend_rend_chunk(arg):
|
|
|
|
print("%d %d %s" % value)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|