如何使用eyed3模块从Mp3中删除现有的专辑封面图像



我一直在尝试使用 eyed3 模块来标记 mp3 文件,但不幸的是,我发现模块文档难以理解,想知道是否有人可以帮助我?..文档可在 https://eyed3.readthedocs.io

我试图使用它来删除现有的专辑封面图像:

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

但是当我运行此代码时,它给了我以下错误:

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

我不确定在哪里可以找到上面提到的description作为参数传递。我还查看了 eyed3 标记的源 python 文件,但基于对代码的调查,我似乎无法找到这个参数description传递什么。

我试图传递一个空字符串作为参数,但是尽管脚本运行良好,没有任何错误,但它并没有删除专辑封面图像。

请帮忙。

在挖掘了一下之后,description实际上只是对图像的描述。 当你调用x.tag.images你会得到一个 ImageAccessor 对象,它基本上只是一个包含图像的迭代对象。如果将x.tag.images转换为列表,则可以看到它包含 1 个 ImageFrame 对象(在我的测试用例中(。 当你调用x.tag.images.remove()时,eyed3需要知道要删除哪个图像,它会根据图像描述选择要删除的图像。 您可以使用这样的东西来获取每个图像的描述。

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

一旦你知道要删除的图像的描述,你应该能够将其传递到 remove 函数中,并且该特定图像将被删除。

>>> 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)
[]

您的代码:

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

试试这个:

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

和我一起工作!

最新更新