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

3

1

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'
Puton answered 22/5, 2015 at 0:0 Comment(0)
P
0

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

Puton answered 26/5, 2015 at 4:36 Comment(0)
D
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
Destruct answered 22/5, 2015 at 0:32 Comment(2)
this looks straightforward. I figured it out in eyed3, but otherwise definitely would have used this.Puton
Glad to hear it Roberto!Destruct
K
1

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

Katerine answered 22/5, 2015 at 0:32 Comment(1)
This didn't answer my question explicitly, but did give me a useful clue. It turns out the "Encoded by" field is buried in a list returned by the frame_set object: audiofile.tag.frame_set['TENC'][0].textPuton
P
0

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

Puton answered 26/5, 2015 at 4:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.