diff options
Diffstat (limited to 'app/converter')
| -rw-r--r-- | app/converter/converter.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/app/converter/converter.py b/app/converter/converter.py index 80411d3..455c1fb 100644 --- a/app/converter/converter.py +++ b/app/converter/converter.py @@ -206,6 +206,9 @@ class AudiobookConverter: self.backend = backend self.voice = voice self.debug = bool(debug) + # Output file names the book being converted will produce (filled in + # by convert_book; reported on the book_done/book_failed events). + self.current_outputs: List[str] = [] # Voice design / style instruction and free-form request options # (audio.cpp only): forwarded to AudioCppTTSClient, which validates # them against the server-hosted model at connect time. @@ -383,6 +386,9 @@ class AudiobookConverter: start_time = time.time() try: + # Reset per book (an instance may have been built without + # __init__, e.g. in tests): no outputs until the plan is known. + self.current_outputs = [] # Start from a clean scratch folder so a previous crash can never # affect this run audio.cleanup_chunks() @@ -396,6 +402,19 @@ class AudiobookConverter: stem = output_name or f"{file_path.stem}_{self._narrator_tag()}" + # The output files this book will produce (single final file, + # or one per chapter). Reported on the book_done/book_failed + # events so the run view can list them in its summary. + if self.output_format == "m4b" or self.single_file \ + or len(sections) == 1: + self.current_outputs = [f"{stem}.{self.output_format}"] + else: + self.current_outputs = [ + f"{stem}_{index:02d}_" + f"{self._sanitize_filename(section.title)}." + f"{self.output_format}" + for index, section in enumerate(sections, 1)] + # --debug: chunk text/audio dumps land in a per-book folder debug_dir = DEBUG_FOLDER / stem if self.debug else None @@ -814,7 +833,8 @@ class AudiobookConverter: success = self.convert_book(book_file, output_name=output_name) results[book_file.name] = success self._emit({"kind": "book_done", "name": book_file.name, - "ok": bool(success)}) + "ok": bool(success), + "files": list(getattr(self, "current_outputs", []))}) except ConversionCancelled: self._emit({"kind": "cancelled"}) logger.info("Conversion cancelled by user at %s", book_file.name) @@ -828,7 +848,8 @@ class AudiobookConverter: logger.error("Unexpected error: %s", exc) results[book_file.name] = False self._emit({"kind": "book_failed", "name": book_file.name, - "error": str(exc)}) + "error": str(exc), + "files": list(getattr(self, "current_outputs", []))}) if not results.get(book_file.name): logger.error("Conversion of %s failed; aborting the remaining books", book_file.name) |
