Compare commits

...

3 Commits

Author SHA1 Message Date
gavin
f1a41230da
Merge fd3f0e936e into e079ffbda6 2024-11-17 22:45:59 +01:00
bashonly
fd3f0e936e
Merge branch 'yt-dlp:master' into pr/11485 2024-11-09 17:58:59 -06:00
7x11x13
300a988ce3 EmbedThumbnailPP: add support for WAVE and AIFF files 2024-11-09 12:01:37 -05:00

View File

@ -17,10 +17,13 @@ from ..utils import (
) )
if mutagen: if mutagen:
from mutagen.aiff import AIFF
from mutagen.flac import FLAC, Picture from mutagen.flac import FLAC, Picture
from mutagen.id3 import APIC
from mutagen.mp4 import MP4, MP4Cover from mutagen.mp4 import MP4, MP4Cover
from mutagen.oggopus import OggOpus from mutagen.oggopus import OggOpus
from mutagen.oggvorbis import OggVorbis from mutagen.oggvorbis import OggVorbis
from mutagen.wave import WAVE
class EmbedThumbnailPPError(PostProcessingError): class EmbedThumbnailPPError(PostProcessingError):
@ -217,9 +220,30 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
f['METADATA_BLOCK_PICTURE'] = base64.b64encode(pic.write()).decode('ascii') f['METADATA_BLOCK_PICTURE'] = base64.b64encode(pic.write()).decode('ascii')
f.save() f.save()
temp_filename = filename temp_filename = filename
elif info['ext'] in ['aiff', 'wav']:
if not mutagen:
raise EmbedThumbnailPPError('module mutagen was not found. Please install using `python3 -m pip install mutagen`')
self._report_run('mutagen', filename)
success = True
try:
f = {'aiff': AIFF, 'wav': WAVE}[info['ext']](filename)
with open(thumbnail_filename, 'rb') as thumbfile:
thumb_data = thumbfile.read()
f['APIC'] = APIC(
encoding=3, # utf-8
mime=f'image/{thumbnail_ext.replace("jpg", "jpeg")}',
type=3, # front cover
desc='Cover (front)',
data=thumb_data,
)
f.save()
temp_filename = filename
except Exception as err:
success = False
raise EmbedThumbnailPPError(f'unable to embed using mutagen; {err}')
else: else:
raise EmbedThumbnailPPError('Supported filetypes for thumbnail embedding are: mp3, mkv/mka, ogg/opus/flac, m4a/mp4/m4v/mov') raise EmbedThumbnailPPError('Supported filetypes for thumbnail embedding are: mp3, mkv/mka, ogg/opus/flac, m4a/mp4/m4v/mov, aiff/wav')
if success and temp_filename != filename: if success and temp_filename != filename:
os.replace(temp_filename, filename) os.replace(temp_filename, filename)