diff --git a/nndownload/ffmpeg_dl.py b/nndownload/ffmpeg_dl.py index 368216c..206ea1d 100644 --- a/nndownload/ffmpeg_dl.py +++ b/nndownload/ffmpeg_dl.py @@ -64,14 +64,15 @@ def convert(self, name: AnyStr, duration: float): while True: if self.proc.stdout is None: continue - prev_line = stdout_line + if stdout_line: + prev_line = stdout_line stdout_line = self.proc.stdout.readline().decode("utf-8", errors="replace").strip() out_time_data = self.REGEX_OUT_TIME.search(stdout_line) if out_time_data is not None: out_time = self.get_timedelta(out_time_data.group(1)) progress.update(out_time.total_seconds() - progress.n) continue - if stdout_line == "" and self.proc.poll() is not None: + if not stdout_line and self.proc.poll() is not None: progress.refresh() progress.close() exit_code = self.proc.poll() diff --git a/nndownload/nndownload.py b/nndownload/nndownload.py index 5c99dde..776eceb 100644 --- a/nndownload/nndownload.py +++ b/nndownload/nndownload.py @@ -1297,14 +1297,21 @@ def perform_native_hls_dl(session: requests.Session, filename: AnyStr, duration: # Video and audio if len(tasks) > 1: stream_filenames = [task["filename"] for task in tasks] - video_convert = FfmpegDL(streams=stream_filenames, - input_kwargs={}, - output_path=filename, - output_kwargs={ - "vcodec": "copy", - "acodec": "copy", - }) - video_convert.convert(name='Merging audio and video', duration=duration) + + try: + video_convert = FfmpegDL(streams=stream_filenames, + input_kwargs={}, + output_path=filename, + output_kwargs={ + "vcodec": "copy", + "acodec": "copy", + }) + video_convert.convert(name='Merging audio and video', duration=duration) + except FfmpegDLException as error: + raise FormatNotAvailableException(f"ffmpeg failed to download the video or audio stream with the following error: \"{error}\"") + except Exception: + raise FormatNotAvailableException("Failed to download video or audio stream") + for stream_filename in stream_filenames: os.remove(stream_filename) # Only audio or video