我需要一个脚本来检查整个目录中没有嵌入图像的 mp3 文件。这个函数应该返回这样一个列表。
def checkAlbumCover( file_list ):
ret = list() #list with mp3 files without album cover
for f in file_list:
mp3 = eyed3.load( f )
if len( mp3.tag.images ) == 0:
ret.append( f )
return ret
使用另一个函数,我遍历每个目录和子目录并获取所有文件路径。然后我检查它们是否是 mp3 文件,如果不是,我删除它们。所以最后我有一个包含 173 个 mp3 文件的列表(在我的例子中)。文件路径是正确的,但是,上面的函数给了我错误。
输出 :
173 mp3 files found.
Traceback (most recent call last):
File "get_album.py", line 32, in <module>
main()
File "get_album.py", line 18, in main
list_without_image = checkAlbumCover( all_files )
File "get_album.py", line 10, in checkAlbumArt
if len( mp3.tag.images ) == 0: # 0 images embedded
AttributeError: 'NoneType' object has no attribute 'images'
我做错了什么?
编辑:
我在检查图像之前打印出来f
,似乎我的函数在崩溃之前已经检查了 20~ 个文件。
我修好了它:
if mp3.tag is None: # 0 images embedded
ret.append( f )
但是,我真的不明白tag
为什么None
...