Using python & eyeD3 to null some tag fields - Stack Overflow

I have 1,350 1970s MP3s that I want to remove the album name and track numbers from theaudio tag (met

I have 1,350 1970s MP3s that I want to remove the album name and track numbers from the audio tag (meta) data using eyeD3. From examples on the Internet, I was able to cobble the following.

When run, the error says - AttributeError: 'NoneType' object has no attribute 'album'.

Internet examples suggest to use audiofile.tag.album and audiofile.tag.track_num. The documentation is not clear how to use but has album and track as fields in the (meta) data.

Python is V3.12 running on Windows 10 using MICROSOFT VISUAL STUDIO CODE

Please help with suggestions to a successful program.

import os
import eyed3

# Assign directory
directory = r"C:\Users\bill\Temp"

print('starting   ')
print('NOW *** ')

# Iterate over files in directory
for name in os.listdir(directory):
    # Open file
    with open(os.path.join(directory, name)) as f:
        print(f"Content of '{name}'")
        
        audiofile = eyed3.load(directory + '\\' + str(name))

        if ".mp3" in str(name):
            # Modify the metadata.

            print('Version ---  ' + str(audiofile.tag.version))

            editFlag = 0
            if audiofile.tag.album: 
                print('album ----> ' + str(audiofile.tag.album))
                audiofile.tag.album = u""
                editFlag = 1
            
            if audiofile.tag.track_num:
                print('Trk_Nm ---> ' + str(audiofile.tag.track_num))
                audiofile.tag.track_num = 0
                editFlag = 1

            if audiofile.tag.disc_num:
                print('Discnumber -- ' + str(audiofile.tag.disc_num))
                audiofile.tag.disc_num = 0
                editFlag = 1
            
            #Save changes.
            
            if editFlag == 1:
                print('Edited --> ' + str(name))
                audiofile.tag.save()
           
        

         ```

This is the output I'm getting with this code:

starting   
NOW *** 
Content of 'Caleb Carruth - Darkness Falls.mp3.m3u'
Traceback (most recent call last):
  File "c:\Users\bill\Desktop\PythonPgms\SearchDirectoryWith_os_path_join.py", line 21, in <module>    print('Version ---  ' + str(audiofile.tag.version))
                                ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'tag'

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744406959a4572682.html

相关推荐

  • Using python &amp; eyeD3 to null some tag fields - Stack Overflow

    I have 1,350 1970s MP3s that I want to remove the album name and track numbers from theaudio tag (met

    6天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信