How to extract “Encoded by” from mp3 metadata usin

2019-08-12 07:30发布

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'

3条回答
2楼-- · 2019-08-12 08:05

If you're willing to switch away from eyed3, the Mutagen library is worth a shot. It's actively maintained on bitbucket (https://bitbucket.org/lazka/mutagen).

Here's an example of pulling the "Encoded By" field from an id3v2 tag in Mutagen:

from mutagen.mp3 import MP3
audio = MP3("poison-and-wine.mp3")
print "Track: " + audio.get("TIT2").text[0]
print "Encoded By: " + audio.get("TENC").text[0]

Prints:

Track Poison & Wine
Encoded By JKuhn
查看更多
3楼-- · 2019-08-12 08:07

The "encoded by" tag you're looking for is TENC in ID3 2.3/2.4. Is it not popping up?

查看更多
女痞
4楼-- · 2019-08-12 08:07

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

查看更多
登录 后发表回答