1

I found that this command using eyed3 works fine on my mp3 file writing the images found to the directory DIR

eyeD3 --write-images=DIR  file.mp3

But I would like to use this in a python program could someone give me an example on how to do that.

This snippet works fine

audiofile = eyed3.load("file.mp3")
        print(audiofile.tag.album)
        print(audiofile.tag.artist) 
        print(audiofile.tag.title)  
        print(audiofile.tag.track_num)  

1 Answer 1

4

This oughta do it. I've added the image type as well, as there can be multiple images in a single MP3 file, and you didn't specify which one you needed. For most files this would be the album cover.

import eyed3

audio_file = eyed3.load("test.mp3")
album_name = audio_file.tag.album
artist_name = audio_file.tag.artist
for image in audio_file.tag.images:
    image_file = open("{0} - {1}({2}).jpg".format(artist_name, album_name, image.picture_type), "wb")
    print("Writing image file: {0} - {1}({2}).jpg".format(artist_name, album_name, image.picture_type))
    image_file.write(image.image_data)
    image_file.close()
5
  • Hi SteveMany thanks for that which worked perfectly I am very new to this so
    – profTC
    Jun 30, 2020 at 9:51
  • -can you tell me how to extract the actual .jpg reference so I can display it in my gui - many thanks! Terry
    – profTC
    Jun 30, 2020 at 9:52
  • Sorry for the late reply. Had it really busy lately. You should be able to use the image.image_data as a reference Jul 13, 2020 at 23:17
  • Hi Thanks for that information but I still have a problem as I want to load the image directly into a Qlabel using QPixmap. This works if I write the file as you suggested above and read it back in with image = QPixmap(fileName) and then use setPixmap. But I am sure there is a more elegant way to do that? Many thanks for any further help
    – profTC
    Jul 25, 2020 at 7:32
  • @profTC label.setPixmap(QPixmap.fromImage(QImage.fromData( image.image_data))).
    – ekhumoro
    Sep 25 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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