3

I am using youtube-dl to download ogg audio files with their respective thumbnail, but I am not sure how to embed the thumbnail into the audio file.

1
  • 1
    You have already 4 reopen votes (5 are needed), a reopen is likely. Good luck on the site!
    – peterh
    Jan 20 '19 at 8:20
2

Ogg format do not support explicitly embedding images. What you can do is to convert the image to base64 and add it under custom tag/comment.

You can check this Q/A for more details

1

This problem has been addressed and solved in this issue. However, it has not yet been merged, so it is not yet available via the official release. Also, you may have already downloaded the opus files and thumbnails.

I use this script, which goes through all files ending with opus in a folder and adds the corresponding file ending with jpg as thumbnail. You need to make sure that both files are present and have the same name, there are no safety checks implemented.

I just copy-pasted the part of the code which tripulse implemented in the issue mentioned above. All credit goes to tripulse. It requires the mutagen python package, that can be easily installed via pip.

#!/usr/bin/env python3

from glob import glob
from mutagen.oggopus import OggOpus
from mutagen.flac import Picture
from base64 import b64encode

ext_audio = 'opus'
ext_thumb = 'jpg'


for f in glob('*.{}'.format(ext_audio)):
    thumb = f.rstrip(ext_audio) + ext_thumb

    covart = Picture()
    covart.data = open(thumb, 'rb').read()
    covart.type = 3  # Cover (front)

    audio = OggOpus(f)
    audio['metadata_block_picture'] = b64encode(covart.write()).decode('ascii')

    audio.save()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.