Python 3.8 Mutagen wont read GEOB tag

245 views Asked by At

I'm using PyDev with Eclipse. Mutagen installed through Anaconda.

I have experience in C, but decided to give Python a shot. Not sure why this isn't working, and there's not a lot of examples for Mutagen. This is a simple mp3 that I'm trying to read a tag from. I checked the Mutagen spec and the GEOB class does exist. But I dont see what I'm missing.

Here is my python file:

import mutagen

from mutagen.id3 import ID3

audio = ID3("Test.mp3") #path: path to file

titleData = audio.get('TIT2')
print(titleData)

tagData = audio.get('GEOB')  # returns None as a default
print(tagData)
    
 
print("Done!")

Here is the output:

Stupid Song
None
Done!

I'm using a file Test.mp3 as my test case. And if I open with a hex editor, I see there is in fact a GEOB tag: Screenshot of 010 Editor

So I would expect to see an output other than 'None'. Any help is appreciated!

Update: Added the lines:

printall = audio.pprint()
print(printall)

and got the output:

GEOB=[unrepresentable data]
GEOB=[unrepresentable data]
GEOB=[unrepresentable data]
GEOB=[unrepresentable data]
GEOB=[unrepresentable data]
GEOB=[unrepresentable data]
GEOB=[unrepresentable data]
TBPM=142
TCON=Other
TIT2=Stupid Song
TKEY=E
TSSE=Lavf58.20.100
TXXX=SERATO_PLAYCOUNT=0

So am I just using the audio.get function incorrectly? I would like to be able to get all that [unrepresentable data] as binary, or hex.

2

There are 2 answers

0
krose On BEST ANSWER

Per the mutagen manual to get all the frames with a given identifier, the method call is "getall" not "get". The following method returns the song title and all GEOB frames.

def get_tags_mutagen(filepath):
    audio = ID3(filepath) #path: path to file
    
    titleData = audio.getall('TIT2')
    print("Song Title: ", titleData)

    tagData = audio.getall('GEOB')  # returns None as a default
    for i in tagData:
        print(i)

    return tagData
0
AmigoJack On

I neither know mutagen nor Python, but as per the manual any text frame (i.e. your TIT2) is based on the mutagen.id3.TextFrame class, having a .text attribute. So when you issue:

titleData = audio.get('TIT2')

...you actually do:

titleData = audio.get('TIT2').text

With that in mind now look at mutagen.id3.GEOB: it doesn't have any such attribute. It's up to you choose what you want to get - maybe .desc?

There are also other frames that also have no primary text - most prominently APIC (example), which you might also easily encounter/want to process. Text frames are the most simple type, but by far not the only ones - have a look at https://id3.org/id3v2.3.0 and https://id3.org/id3v2.4.0-frames to see how different each can be (example: ETCO).

(Everything in this answer that has a bottom line is a link - not only the blue text.)