This commit introduces a series of improvements across the codebase:
1. **Logging:**
* Integrated Python's `logging` module throughout the application.
* Replaced custom `print_step/print_substep` functions with standard logging calls (INFO, WARNING, ERROR, DEBUG).
* Configured file logging (rotating logs) and console logging (using RichHandler if available).
* Enhanced FFmpeg error logs to include commands and stderr.
2. **Error Handling:**
* Made error handling more robust in TTS modules, Playwright interactions (screenshotting), API calls, and file operations.
* Replaced `sys.exit()` calls in modules with exceptions to allow better control by the caller.
* Improved reporting of unhandled exceptions in `main.py` with tracebacks to the log file.
3. **Code Quality & Modularity:**
* Refactored `main.py` and `video_creation/final_video.py` into smaller, more manageable functions, reducing global state and improving readability.
* Replaced `eval()` in configuration parsing (`utils/settings.py`, `utils/gui_utils.py`) with safer type conversion methods.
* Decoupled background choice management from the static TOML template, now dynamically loaded from `backgrounds.json`.
* Standardized path handling using `pathlib.Path` across numerous modules, replacing `os.path` and manual string concatenations.
* Corrected OS dispatcher logic in `utils/ffmpeg_install.py`.
* Clarified voice selection logic in `TTS/pyttsx.py`.
4. **FFmpeg Interaction:**
* Reviewed and refined the `ProgressFfmpeg` class for more robust progress parsing and thread management.
5. **Testing Groundwork:**
* Created `tests/` directory and added initial unit tests for utility functions `name_normalize` and `_safe_str_to_bool` using `unittest`.
6. **Documentation:**
* Added/updated module-level and key function docstrings in `main.py` and `video_creation/final_video.py`.