How to remove existing album art image from an Mp3 using eyed3 module
Asked Answered
S

2

5

I have been attempting to use the eyed3 module for tagging mp3 files, but unfortunately, I find the module documentation difficult to understand and was wondering if someone can help me?.. Documentation can be found at https://eyed3.readthedocs.io

I was trying to use it to remove existing album art image using:

import eyed3
x = eyed3.load('file_path')
x.tag._images.remove()
x.tag.save()

But when I run this code, it gives me the following error:

TypeError: remove() missing 1 required positional argument: 'description'

I am not sure where to find the above mentioned description to pass as a parameter. I have also looked at the source python file for eyed3 tagging, but based on investigating the code, I can't seem to find out what to pass for this argument description.

I attempted to pass an empty string as the argument, but although the script ran fine without any errors, it did not remove the album art image.

Please help.

Shanklin answered 18/9, 2018 at 19:45 Comment(0)
V
4

After digging around a bit, description is literally just the description of the image. When you call x.tag.images you get an ImageAccessor object, which is basically just an iterable containing your images. If you cast x.tag.images to a list, you can see it contains 1 ImageFrame object (in my test case). When you call x.tag.images.remove(), eyed3 needs to know which image to remove, and it selects the image to remove based on the image description. You can get the descriptions of each image using something like this.

[y.description for y in x.tag.images]

Once you know the description of the image you want to remove, you should be able to pass it into the remove function, and that specific image will be removed.

>>> x.tag.images
<eyed3.id3.tag.ImagesAccessor object at 0x1053c8400>
>>> list(x.tag.images)
[<eyed3.id3.frames.ImageFrame object at 0x1050cc4a8>]
>>> x.tag.images.remove()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jperoutek/test_env/lib/python3.6/site-packages/eyed3/utils/__init__.py", line 170, in wrapped_fn
    return fn(*args, **kwargs)
TypeError: remove() missing 1 required positional argument: 'description'
>>> x.tag.images.remove('')
<eyed3.id3.frames.ImageFrame object at 0x1050cc4a8>
>>> x.tag.images
<eyed3.id3.tag.ImagesAccessor object at 0x1053c8400>
>>> list(x.tag.images)
[]
Vi answered 19/9, 2018 at 5:36 Comment(2)
Thank you very much, this has really helped, wow I had no idea I could loop through objects like that and access their properties, the way you show in [y.description for y in x.tag.images]. Thanks to you I learnt 2 new things today, the eyed3 remove and looping through objects to access their properties.Shanklin
I'm getting the same results as you, but my file still has the same file size before & after removing the image. Any thoughts? Could it be a bug? Am I doing something wrong?Glennieglennis
R
2

Your code:

    import eyed3
    x = eyed3.load('file_path')
    x.tag._images.remove()
    x.tag.save()

Try this:

    import eyed3
    x = eyed3.load('file_path')
    x.tag.images.remove('')
    x.tag.save()

works with me!

Rummage answered 27/2, 2023 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.