Add jinja templating to script writer

This commit is contained in:
Esa Kataja
2025-07-02 20:49:47 +03:00
parent cefd878059
commit aa47fd5ddb
6 changed files with 212 additions and 112 deletions
+18 -10
View File
@@ -11,22 +11,22 @@ The first priority is to refactor the existing codebase to improve its structure
This phase will be broken down into the following steps:
1. **Centralize Encoding Settings:**
* Create a new Pydantic model, `EncodingSettings`, in a new file `src/models/settings.py`.
* This model will consolidate all encoding-related parameters (`preset`, `crf`, `film_grain`, etc.) that are currently passed individually into the `main` function in `app.py`.
* The `main` function will be updated to create an instance of this model.
* **Create `EncodingSettings` Model:** In a new file, `src/models/settings.py`, create a new Pydantic model named `EncodingSettings`.
* **Define Fields:** This model will have the following fields, corresponding to the Typer options in `app.py`:
* `preset: int`
* `crf: int`
* `original_media_type: OriginalMediaType`
* `film_grain: int`
* **Integrate into `app.py`:**
* In the `main` function, create an instance of `EncodingSettings` by passing the values from the Typer options.
* The `apply_stream_settings` function will be updated to accept this `EncodingSettings` object instead of individual parameters, simplifying its signature.
2. **Refactor IMDb Search:**
* Create a Pydantic model, `IMDbSearchResult`, to represent a single search result (e.g., with `title`, `year`, `imdb_id`).
* Modify the `search_imdb` function in `src/lib/movie_details.py` to no longer print to the console. Instead, it will return a list of `IMDbSearchResult` objects.
* The interactive selection logic will be handled separately in `app.py` after calling the refactored `search_imdb`.
3. **Implement Template-Based Command Generation:**
* Add `Jinja2` as a project dependency in `pyproject.toml`.
* Create a new directory `src/templates/`.
* Create a template file, `ffmpeg_command.sh.j2`, inside this directory. This template will contain the full structure of the `ffmpeg` command, using Jinja2 syntax for loops, conditionals, and variables.
* Create a new function (e.g., `generate_ffmpeg_command`) that takes the necessary data models (`VideoDetails`, `EncodingSettings`) as input.
* This function will be responsible for loading the Jinja2 template, rendering it with the provided data, and returning the final command string.
* The `VideoDetails.cmd()` method will be removed and replaced with a call to this new function.
3. **[x] Implement Template-Based Command Generation:** The `ffmpeg` command is now generated using a Jinja2 template, separating the command logic from the Python code.
## Phase 2: Logging
@@ -71,6 +71,14 @@ Add an option to execute the generated `ffmpeg` command directly from the applic
Develop a graphical user interface (GUI) to make the application more accessible and user-friendly for a broader audience. This will be a significant undertaking and will be considered after the core CLI functionality is mature and stable. Research into the best GUI framework (e.g., Dear PyGui, CustomTkinter, PySide6) will be the first step.
### Deinterlacing
A `bwdif` deinterlacing filter is currently hardcoded in the video processing pipeline as a temporary solution.
**To-Do:**
- Implement detection for interlaced video streams (e.g., by checking the `field_order` property from `ffprobe` output).
- Apply the deinterlacing filter conditionally, only when interlaced content is detected, to avoid unnecessary processing on progressive sources.
---