From 03f3fec5cc7db0801f706a7c3ead3a5d04ef1883 Mon Sep 17 00:00:00 2001 From: rlaphoenix <17136956+rlaphoenix@users.noreply.github.com> Date: Thu, 16 May 2024 18:06:26 +0100 Subject: [PATCH] refactor(dl): Only log errors/warnings from mkvmerge, list after message --- devine/commands/dl.py | 18 +++++++++++------- devine/core/tracks/tracks.py | 9 +++++---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/devine/commands/dl.py b/devine/commands/dl.py index 43b4d6a..0f007fa 100644 --- a/devine/commands/dl.py +++ b/devine/commands/dl.py @@ -701,18 +701,22 @@ def result( ): for task_id, task_tracks in multiplex_tasks: progress.start_task(task_id) # TODO: Needed? - muxed_path, return_code, output = task_tracks.mux( + muxed_path, return_code, errors = task_tracks.mux( str(title), progress=partial(progress.update, task_id=task_id), delete=False ) muxed_paths.append(muxed_path) - if return_code == 1: - self.log.warning(output) - self.log.warning("mkvmerge had at least one warning, will continue anyway...") - elif return_code >= 2: - self.log.warning(output) - self.log.error(f"Failed to Mux video to Matroska file ({return_code})") + if return_code >= 2: + self.log.error(f"Failed to Mux video to Matroska file ({return_code}):") + elif return_code == 1 or errors: + self.log.warning("mkvmerge had at least one warning or error, continuing anyway...") + for line in errors: + if line.startswith("#GUI#error"): + self.log.error(line) + else: + self.log.warning(line) + if return_code >= 2: sys.exit(1) for video_track in task_tracks.videos: video_track.delete() diff --git a/devine/core/tracks/tracks.py b/devine/core/tracks/tracks.py index abe9657..d70cad4 100644 --- a/devine/core/tracks/tracks.py +++ b/devine/core/tracks/tracks.py @@ -316,7 +316,7 @@ def by_language(tracks: list[TrackT], languages: list[str], per_language: int = ][:per_language or None]) return selected - def mux(self, title: str, delete: bool = True, progress: Optional[partial] = None) -> tuple[Path, int, str]: + def mux(self, title: str, delete: bool = True, progress: Optional[partial] = None) -> tuple[Path, int, list[str]]: """ Multiplex all the Tracks into a Matroska Container file. @@ -410,17 +410,18 @@ def mux(self, title: str, delete: bool = True, progress: Optional[partial] = Non # let potential failures go to caller, caller should handle try: - output = "" + errors = [] p = subprocess.Popen([ *cl, "--output", str(output_path), "--gui-mode" ], text=True, stdout=subprocess.PIPE) for line in iter(p.stdout.readline, ""): - output += line + if line.startswith("#GUI#error") or line.startswith("#GUI#warning"): + errors.append(line) if "progress" in line: progress(total=100, completed=int(line.strip()[14:-1])) - return output_path, p.wait(), output + return output_path, p.wait(), errors finally: if chapters_path: # regardless of delete param, we delete as it's a file we made during muxing