Search code examples
pythonmetadatamp3eyed3

How to extract "Encoded by" from mp3 metadata using Python?


I am trying to write a Python script to extract metadata tags from some mp3 files. Specifically, I am looking to extract "Album" and "Encoded by", which are available if I right-click on the files and look under details:

song_details

I am using currently using the eyeD3 library to parse metadata. I am using this library because I thought it would easily accomplish my task, but I am not married to it.

I am able to extract the "Album" easily enough, but not the "Encoded by" field. If I print out all the song tags, I do not see anything like the "Encoded by" field I need. Any ideas, please?

Here is my code:

import eyed3

def main():
    music_file = r'G:\Music Collection\54-40\Sweeter Things A Compilation\01 Miss You - 54-40.mp3'

    audiofile = eyed3.load(music_file)
    for attribute_name in dir(audiofile.tag):
        attribute_value = getattr(audiofile.tag, attribute_name)
        print attribute_name, attribute_value

if __name__ == "__main__":
    main()
    print 'done'

Solution

  • It turns out the "Encoded by" field is buried in a list returned by the frame_set object: audiofile.tag.frame_set['TENC'][0].text