How to extract “Encoded by” from mp3 metadata using Python?

做~自己de王妃 提交于 2019-12-11 10:56:11

问题


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:

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'

回答1:


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



回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/30386343/how-to-extract-encoded-by-from-mp3-metadata-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!