From 6091b64448616c138d37ee020f9543a9847fd54d Mon Sep 17 00:00:00 2001 From: Alex James Date: Sun, 8 Jul 2018 19:34:39 -0500 Subject: [PATCH] [postprocessor/embedthumbnail] Add FLAC support --- youtube_dl/postprocessor/embedthumbnail.py | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/youtube_dl/postprocessor/embedthumbnail.py b/youtube_dl/postprocessor/embedthumbnail.py index 3990908b6..84f481052 100644 --- a/youtube_dl/postprocessor/embedthumbnail.py +++ b/youtube_dl/postprocessor/embedthumbnail.py @@ -124,7 +124,31 @@ class EmbedThumbnailPP(FFmpegPostProcessor): else: os.remove(encodeFilename(filename)) os.rename(encodeFilename(temp_filename), encodeFilename(filename)) + elif info['ext'] == 'flac': + if not check_executable('metaflac', ['--help']): + raise EmbedThumbnailPPError('metaflac was not found. Please install.') + + cmd = [encodeFilename('metaflac', True), + encodeArgument('--preserve-modtime'), + encodeArgument('--import-picture-from'), + encodeFilename(thumbnail_filename, True), + encodeFilename(filename, True)] + + self._downloader.to_screen('[metaflac] Adding thumbnail to "%s"' % filename) + + if self._downloader.params.get('verbose', False): + self._downloader.to_screen('[debug] metaflac command line: %s' % shell_quote(cmd)) + + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + + if p.returncode != 0: + msg = stderr.decode('utf-8', 'replace').strip() + raise EmbedThumbnailPPError(msg) + + if not self._already_have_thumbnail: + os.remove(encodeFilename(thumbnail_filename)) else: - raise EmbedThumbnailPPError('Only mp3 and m4a/mp4 are supported for thumbnail embedding for now.') + raise EmbedThumbnailPPError('Only mp3, m4a/mp4, and flac are supported for thumbnail embedding for now.') return [], info