How to read and write front cover image files from mp3 file?

Issue #67 resolved
Dong Xiaoyu
created an issue

Hi, travis,

I was confused how to use eyed3 module in python, though I have read documentation and example. I want to write CD cover image file into mp3 file. But I do not know how to work on it with your eyed3. I would be really grateful if you give some examples.

Comments (4)

  1. Travis Shirk repo owner

    I wish it was covered in the docs but for now the --add-image arg in the classic plugin is the best example.

    classic.py:918

    with open(img_path, "rb") as img_fp:
        tag.images.set(img_type, img_fp.read(), img_mt, img_desc)
    

    There opens the image file and sets the img_type slot (e.g. FRONT_COVER), image date, mime-type, and description. ID3 does not allow duplicate type/description pairs. If such a pair exists the operation becomes an update instead of an add (hence the method name of 'set').

  2. Dong Xiaoyu reporter

    Hi, Travis,

    Thank you for reply. I can use below codes to set frontcover to mp3 files. But I met a new problem. If a mp3 file has ID3V1, APEV2 tag, but do not has ID3V2 tag, adding front cover to mp3 file is failed. How to solve this problem?

    Regards, Xiaoyu

    audiofile = eyed3.load(song_path)
    img = audiofile.tag.images
    imgframe = img.set(FRONTCOVER, cover_data, "image/jpeg")
    if imgframe == None:
        print "Setting front cover error!"
        sys.exit(0)
    audiofile.tag.save()
    
  3. Log in to comment