diff --git a/tagstudio/src/core/constants.py b/tagstudio/src/core/constants.py index d07489aa6..509ae1e84 100644 --- a/tagstudio/src/core/constants.py +++ b/tagstudio/src/core/constants.py @@ -105,6 +105,41 @@ ".7z", ".s7z", ] +BLENDER_TYPES: list[str] = [ + ".blend", + ".blend1", + ".blend2", + ".blend3", + ".blend4", + ".blend5", + ".blend6", + ".blend7", + ".blend8", + ".blend9", + ".blend10", + ".blend11", + ".blend12", + ".blend13", + ".blend14", + ".blend15", + ".blend16", + ".blend17", + ".blend18", + ".blend19", + ".blend20", + ".blend21", + ".blend22", + ".blend23", + ".blend24", + ".blend25", + ".blend26", + ".blend27", + ".blend28", + ".blend29", + ".blend30", + ".blend31", + ".blend32", +] PROGRAM_TYPES: list[str] = [".exe", ".app"] SHORTCUT_TYPES: list[str] = [".lnk", ".desktop", ".url"] diff --git a/tagstudio/src/qt/helpers/blender_thumbnailer.py b/tagstudio/src/qt/helpers/blender_thumbnailer.py new file mode 100644 index 000000000..89f171589 --- /dev/null +++ b/tagstudio/src/qt/helpers/blender_thumbnailer.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 + +# ##### 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 ##### + +# + + +## This file is a modified script that gets the thumbnail data stored in a blend file + + +import struct +from PIL import ( + Image, + ImageOps, +) +import gzip +import os + + +def blend_extract_thumb(path): + REND = b"REND" + TEST = b"TEST" + + blendfile = open(path, "rb") + + head = blendfile.read(12) + + if head[0:2] == b"\x1f\x8b": # gzip magic + blendfile.close() + blendfile = gzip.GzipFile("", "rb", 0, open(path, "rb")) + head = blendfile.read(12) + + if not head.startswith(b"BLENDER"): + blendfile.close() + return None, 0, 0 + + is_64_bit = head[7] == b"-"[0] + + # true for PPC, false for X86 + is_big_endian = head[8] == b"V"[0] + + # blender pre 2.5 had no thumbs + if head[9:11] <= b"24": + return None, 0, 0 + + sizeof_bhead = 24 if is_64_bit else 20 + int_endian = ">i" if is_big_endian else "