Skip to content

Commit bfec630

Browse files
committed
change to relative imports + no sys.path stuff
1 parent 3092087 commit bfec630

8 files changed

Lines changed: 32 additions & 70 deletions

File tree

blender_manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
schema_version = "1.0.0"
55
id = "BL_FastStart"
6-
version = "1.8.6"
6+
version = "1.9.0"
77

88
name = "BL Fast Start (MP4/MOV)"
99
author = "usrname0 (AI assisted)"

extension_logic.py

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# filename: extension_logic.py
22
# Main logic for the Fast Start Blender Extension, using bundled qtfaststart.
33

4+
# This is a lot of comments but I'm leaving it as a favor to future revisits
45
# --- Blender File Naming Conventions (as of Blender 4.x) ---
56
# 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+
#
78
# Key behaviors observed and implemented:
89
#
910
# General Principle: If frame numbers are to be added, Blender typically processes
@@ -61,9 +62,10 @@
6162
from bpy.types import PropertyGroup, AddonPreferences
6263
from bpy.app.handlers import persistent
6364

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
6769

6870
# --- Module-level globals ---
6971
_render_job_cancelled_by_addon = False
@@ -181,67 +183,25 @@ def run_qtfaststart_processing(input_path_str, output_path_str):
181183
except Exception as e_dir:
182184
print(f"QTFASTSTART ERROR: Could not create output directory '{output_dir}': {e_dir}"); return False
183185

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-
224186
success = False
225187
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)
230190
# Check if the output file was created and is not empty
231191
if os.path.exists(output_path_str) and os.path.getsize(output_path_str) > 0:
232192
success = True
233193
else:
234194
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}")
239199
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+
245205
return success
246206

247207
# --- Application Handlers ---

libs/qtfaststart/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

qtfaststart_lib/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Expose the core processing function from processor.py
2+
from .processor import process
3+
4+
# Expose the relevant exceptions from exceptions.py
5+
from .exceptions import (
6+
FastStartException,
7+
FastStartSetupError,
8+
MalformedFileError,
9+
UnsupportedFormatError
10+
)
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111

1212
import io
1313

14-
from qtfaststart.exceptions import FastStartSetupError
15-
from qtfaststart.exceptions import MalformedFileError
16-
from qtfaststart.exceptions import UnsupportedFormatError
17-
18-
# This exception isn't directly used, included it for backward compatability
19-
# in the event someone had used it from our namespace previously
20-
from qtfaststart.exceptions import FastStartException
14+
from .exceptions import FastStartSetupError
15+
from .exceptions import MalformedFileError
16+
from .exceptions import UnsupportedFormatError
17+
from .exceptions import FastStartException
2118

2219
CHUNK_SIZE = 8192
2320

0 commit comments

Comments
 (0)