如何使用eyed3从python中的.mp3文件中获取细节(标题、艺术家)

2024-05-17 06:05:52 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码

import eyed3

audiofile = eyed3.load("19 Calvin Harris - Summer.mp3")

print(audiofile.tag.artist)

这是个错误

Traceback (most recent call last):
  File "C:\Python34\testmp3.py", line 5, in <module>
    print(audiofile.tag.artist)
AttributeError: 'NoneType' object has no attribute 'artist'

Visual Studio中显示了一些属性。但当我运行它时,出现了一个错误

当我写print(audiofile)的时候,它就工作了。我不知道为什么 Python3.4。


Tags: import密码mostartisttag错误loadmp3
3条回答

Title和Artists可以通过Tag()返回值的访问器函数获得。下面的示例演示如何使用getArtist()getTitle()方法获取它们。

 import eyed3
 tag = eyed3.Tag()
 tag.link("/some/file.mp3")
 print tag.getArtist()
 print tag.getTitle()

试试这个代码,对我有用

import eyed3

def show_info():
    audio = eyed3.load("[PATH_TO_MP3]")
    print audio.tag.artist
    print audio.tag.album
    print audio.tag.title

show_info()

我认为问题出在模块内。

我使用以下代码进行了一些调试:

from eyed3 import id3

tag = id3.Tag()
tag.parse("myfile.mp3")
print(tag.artist)

在parse函数中,打开文件,然后将其传递给loadV2Tag(fileobject)。然后,模块读取文件头的前几行并检查它是否以ID3开头。

if f.read(3) != "ID3":
    return False

这里它返回false,我认为这是错误所在,因为如果我自己尝试读取头,它肯定是ID3。

>>> f = open("myfile.mp3", "rb")
>>> print(f.read(3))
b'ID3'

但是,在0.8版之前,不需要完全支持python3,这是根据https://bitbucket.org/nicfit/eyed3/issues/25/python-3-compatibilty提供的:https://bitbucket.org/nicfit/eyed3/branch/py3

相关问题 更多 >