From f0c9fb96827ff798a48626e7e5d32a9c5de7b97e Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 16 Jun 2022 02:25:43 +0530 Subject: [utils] `Popen`: Refactor to use contextmanager Fixes https://github.com/yt-dlp/yt-dlp/issues/3531#issuecomment-1156223597 --- yt_dlp/postprocessor/embedthumbnail.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'yt_dlp/postprocessor/embedthumbnail.py') diff --git a/yt_dlp/postprocessor/embedthumbnail.py b/yt_dlp/postprocessor/embedthumbnail.py index e031d344f..606d90d3d 100644 --- a/yt_dlp/postprocessor/embedthumbnail.py +++ b/yt_dlp/postprocessor/embedthumbnail.py @@ -157,14 +157,12 @@ class EmbedThumbnailPP(FFmpegPostProcessor): self._report_run('atomicparsley', filename) self.write_debug('AtomicParsley command line: %s' % shell_quote(cmd)) - p = Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = p.communicate_or_kill() - if p.returncode != 0: - msg = stderr.decode('utf-8', 'replace').strip() - self.report_warning(f'Unable to embed thumbnails using AtomicParsley; {msg}') + stdout, stderr, returncode = Popen.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if returncode: + self.report_warning(f'Unable to embed thumbnails using AtomicParsley; {stderr.strip()}') # for formats that don't support thumbnails (like 3gp) AtomicParsley # won't create to the temporary file - if b'No changes' in stdout: + if 'No changes' in stdout: self.report_warning('The file format doesn\'t support embedding a thumbnail') success = False -- cgit v1.2.3