refactor(dl): Only log errors/warnings from mkvmerge, list after message

This commit is contained in:
rlaphoenix 2024-05-16 18:06:26 +01:00
parent 2acee30e54
commit 03f3fec5cc
2 changed files with 16 additions and 11 deletions

View File

@ -701,18 +701,22 @@ class dl:
): ):
for task_id, task_tracks in multiplex_tasks: for task_id, task_tracks in multiplex_tasks:
progress.start_task(task_id) # TODO: Needed? 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), str(title),
progress=partial(progress.update, task_id=task_id), progress=partial(progress.update, task_id=task_id),
delete=False delete=False
) )
muxed_paths.append(muxed_path) muxed_paths.append(muxed_path)
if return_code == 1: if return_code >= 2:
self.log.warning(output) self.log.error(f"Failed to Mux video to Matroska file ({return_code}):")
self.log.warning("mkvmerge had at least one warning, will continue anyway...") elif return_code == 1 or errors:
elif return_code >= 2: self.log.warning("mkvmerge had at least one warning or error, continuing anyway...")
self.log.warning(output) for line in errors:
self.log.error(f"Failed to Mux video to Matroska file ({return_code})") if line.startswith("#GUI#error"):
self.log.error(line)
else:
self.log.warning(line)
if return_code >= 2:
sys.exit(1) sys.exit(1)
for video_track in task_tracks.videos: for video_track in task_tracks.videos:
video_track.delete() video_track.delete()

View File

@ -316,7 +316,7 @@ class Tracks:
][:per_language or None]) ][:per_language or None])
return selected 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. Multiplex all the Tracks into a Matroska Container file.
@ -410,17 +410,18 @@ class Tracks:
# let potential failures go to caller, caller should handle # let potential failures go to caller, caller should handle
try: try:
output = "" errors = []
p = subprocess.Popen([ p = subprocess.Popen([
*cl, *cl,
"--output", str(output_path), "--output", str(output_path),
"--gui-mode" "--gui-mode"
], text=True, stdout=subprocess.PIPE) ], text=True, stdout=subprocess.PIPE)
for line in iter(p.stdout.readline, ""): 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: if "progress" in line:
progress(total=100, completed=int(line.strip()[14:-1])) progress(total=100, completed=int(line.strip()[14:-1]))
return output_path, p.wait(), output return output_path, p.wait(), errors
finally: finally:
if chapters_path: if chapters_path:
# regardless of delete param, we delete as it's a file we made during muxing # regardless of delete param, we delete as it's a file we made during muxing