|
1 | 1 | # filename: extension_logic.py |
2 | 2 | # Main logic for the Fast Start Blender Extension, using bundled qtfaststart. |
3 | 3 |
|
| 4 | +# This is a lot of comments but I'm leaving it as a favor to future revisits |
4 | 5 | # --- Blender File Naming Conventions (as of Blender 4.x) --- |
5 | 6 | # This script attempts to replicate Blender's output file naming logic. |
6 | | -# IF THERE'S SOME WAY TO JUST PULL THAT OUT OF PYTHON LET ME KNOW |
| 7 | +# |
7 | 8 | # Key behaviors observed and implemented: |
8 | 9 | # |
9 | 10 | # General Principle: If frame numbers are to be added, Blender typically processes |
|
61 | 62 | from bpy.types import PropertyGroup, AddonPreferences |
62 | 63 | from bpy.app.handlers import persistent |
63 | 64 |
|
64 | | -# Imports for bundled qtfaststart |
65 | | -import sys |
66 | | -from pathlib import Path |
| 65 | +# Imports for bundled qtfaststart using relative import |
| 66 | +from pathlib import Path # Path is still used elsewhere in the script |
| 67 | +from .qtfaststart_lib import process as qtfaststart_process |
| 68 | +from .qtfaststart_lib import FastStartSetupError, MalformedFileError, UnsupportedFormatError, FastStartException |
67 | 69 |
|
68 | 70 | # --- Module-level globals --- |
69 | 71 | _render_job_cancelled_by_addon = False |
@@ -181,67 +183,25 @@ def run_qtfaststart_processing(input_path_str, output_path_str): |
181 | 183 | except Exception as e_dir: |
182 | 184 | print(f"QTFASTSTART ERROR: Could not create output directory '{output_dir}': {e_dir}"); return False |
183 | 185 |
|
184 | | - # Locates the bundled qtfaststart library |
185 | | - addon_root_dir = Path(__file__).parent.resolve() |
186 | | - libs_dir = addon_root_dir / "libs" |
187 | | - |
188 | | - original_sys_path = list(sys.path) # Store original sys.path |
189 | | - qt_processor_module = None |
190 | | - # Define custom exception types (will be overwritten by actual exceptions from qtfaststart if available) |
191 | | - QtFastStartSetupError = Exception |
192 | | - QtMalformedFileError = Exception |
193 | | - QtUnsupportedFormatError = Exception |
194 | | - |
195 | | - # Temporarily add libs_dir to sys.path to allow importing qtfaststart |
196 | | - if str(libs_dir) not in sys.path: |
197 | | - sys.path.insert(0, str(libs_dir)) |
198 | | - |
199 | | - try: |
200 | | - import qtfaststart # Attempt to import the library |
201 | | - |
202 | | - # Check if the processor submodule exists |
203 | | - if hasattr(qtfaststart, 'processor'): |
204 | | - qt_processor_module = qtfaststart.processor |
205 | | - else: |
206 | | - print(f"QTFASTSTART ERROR: 'qtfaststart' package does not have a 'processor' attribute/submodule.") |
207 | | - if str(libs_dir) in sys.path: sys.path = original_sys_path # Restore sys.path |
208 | | - return False |
209 | | - |
210 | | - # Try to get specific exception types from the library for better error handling |
211 | | - if hasattr(qtfaststart, 'exceptions'): |
212 | | - if hasattr(qtfaststart.exceptions, 'FastStartSetupError'): QtFastStartSetupError = qtfaststart.exceptions.FastStartSetupError |
213 | | - if hasattr(qtfaststart.exceptions, 'MalformedFileError'): QtMalformedFileError = qtfaststart.exceptions.MalformedFileError |
214 | | - if hasattr(qtfaststart.exceptions, 'UnsupportedFormatError'): QtUnsupportedFormatError = qtfaststart.exceptions.UnsupportedFormatError |
215 | | - except ImportError as e_import: |
216 | | - print(f"QTFASTSTART ERROR: Import failed for 'qtfaststart' from '{libs_dir}': {e_import}") |
217 | | - if str(libs_dir) in sys.path: sys.path = original_sys_path # Restore sys.path |
218 | | - return False |
219 | | - except Exception as e_generic_import: |
220 | | - print(f"QTFASTSTART ERROR: A generic error occurred during the import phase of qtfaststart: {e_generic_import}") |
221 | | - if str(libs_dir) in sys.path: sys.path = original_sys_path # Restore sys.path |
222 | | - return False |
223 | | - |
224 | 186 | success = False |
225 | 187 | try: |
226 | | - if not qt_processor_module: |
227 | | - return False |
228 | | - # Process the video file |
229 | | - qt_processor_module.process(input_path_str, output_path_str) |
| 188 | + # Process the video file using the directly imported function and exceptions |
| 189 | + qtfaststart_process(input_path_str, output_path_str) |
230 | 190 | # Check if the output file was created and is not empty |
231 | 191 | if os.path.exists(output_path_str) and os.path.getsize(output_path_str) > 0: |
232 | 192 | success = True |
233 | 193 | else: |
234 | 194 | print(f"QTFASTSTART ERROR: Output file '{output_path_str}' not found or is empty after process seemed to complete.") |
235 | | - # Handle specific qtfaststart errors |
236 | | - except QtFastStartSetupError as e_setup: print(f"QTFASTSTART ERROR (Setup): {e_setup}") |
237 | | - except QtMalformedFileError as e_malformed: print(f"QTFASTSTART ERROR (Malformed File): {e_malformed}") |
238 | | - except QtUnsupportedFormatError as e_unsupported: print(f"QTFASTSTART ERROR (Unsupported Format): {e_unsupported}") |
| 195 | + # Handle specific qtfaststart errors (now directly available from import) |
| 196 | + except FastStartSetupError as e_setup: print(f"QTFASTSTART ERROR (Setup): {e_setup}") |
| 197 | + except MalformedFileError as e_malformed: print(f"QTFASTSTART ERROR (Malformed File): {e_malformed}") |
| 198 | + except UnsupportedFormatError as e_unsupported: print(f"QTFASTSTART ERROR (Unsupported Format): {e_unsupported}") |
239 | 199 | except FileNotFoundError as e_fnf: print(f"QTFASTSTART ERROR (File Not Found during process): {e_fnf}") |
240 | | - except Exception as e_runtime: print(f"QTFASTSTART ERROR: An unexpected error occurred during qtfaststart.process execution: {e_runtime}") |
241 | | - finally: |
242 | | - # Restore the original sys.path |
243 | | - if str(libs_dir) in sys.path: |
244 | | - sys.path = original_sys_path |
| 200 | + except FastStartException as e_general_fs: # Catching the base qtfaststart exception |
| 201 | + print(f"QTFASTSTART ERROR (General qtfaststart lib): {e_general_fs}") |
| 202 | + except Exception as e_runtime: # Catch any other unexpected errors |
| 203 | + print(f"QTFASTSTART ERROR: An unexpected error occurred during qtfaststart_process execution: {e_runtime}") |
| 204 | + |
245 | 205 | return success |
246 | 206 |
|
247 | 207 | # --- Application Handlers --- |
|
0 commit comments