diff --git a/youtube_dl/postprocessor/embedthumbnail.py b/youtube_dl/postprocessor/embedthumbnail.py index 90002460c..c5c3cbf24 100644 --- a/youtube_dl/postprocessor/embedthumbnail.py +++ b/youtube_dl/postprocessor/embedthumbnail.py @@ -97,33 +97,33 @@ class EmbedThumbnailPP(FFmpegPostProcessor): from mutagen.oggopus import OggOpus from mutagen.flac import Picture, FLAC from base64 import b64encode + except ImportError: + raise EmbedThumbnailPPError('mutagen was not found. Please install.') - # to prevent the behaviour of in-place modification of Mutagen shutil.copyfile(filename, temp_filename) - aufile = {'opus': OggOpus, 'flac': FLAC, 'ogg': OggVorbis} \ [info['ext']](temp_filename) covart = Picture() covart.data = open(thumbnail_filename, 'rb').read() - covart.type = 3 #< use as front cover. + covart.type = 3 # Cover (front) + # Since, OGGOpus and OGGVorbis doesn't natively support + # (coverart / thumbnail)s, it's wrapped in if..else if info['ext'] == 'flac': aufile.add_picture(covart) else: - # VorbisComments don't allow raw-bytes so it's encoded - # in base64 and converted to a string. aufile['metadata_block_picture'] = \ b64encode(covart.write()).decode('ascii') + # Save changes to temporary file, it'd be overlapped as the + # original one. aufile.save() if not self._already_have_thumbnail: os.remove(encodeFilename(thumbnail_filename)) os.remove(encodeFilename(filename)) os.rename(encodeFilename(temp_filename), encodeFilename(filename)) - except ImportError: - raise EmbedThumbnailPPError('mutagen was not found. Please install.') else: raise EmbedThumbnailPPError('Only mp3, m4a/mp4, ogg, opus and flac are supported for thumbnail embedding for now.')