I struggle to find a way to retrieve the audio fingerprint data from given songs. I tagged those songs with MusicBrainz before and now I want to read it directly from the audiofile. The only way I found with musicbrainzngs was to search (musicbrainzngs.search_artists()) for the song in the MusicBrainz library to find the fingerprint data which is rather inefficient since I have the data in my files already.
Is there a library where I can read it from any given audiofile?
The AcoustID fingerprint is stored in audiofiles, yes, if you tagged your files using MusicBrainz Picard. What tag exactly depends on the audio file:
TXXX:Acoustid Fingerprint
ACOUSTID_FINGERPRINT
----:com.apple.iTunes:Acoustid Fingerprint
See the Musicbrainz tag mapping overview.
You can read audiofile tags with the mutagen
project, which is what Picard uses too:
import mutagen
tagnames = {
'audio/mp3': 'TXXX:Acoustid Fingerprint',
'audio/vorbis': 'ACOUSTID_FINGERPRINT',
'audio/mp4': '----:com.apple.iTunes:Acoustid Fingerprint'
}
mfile = mutagen.File(musicfile_filename)
if mfile and mfile.mime[0] in tagnames:
fingerprint = mfile.get(tagnames[mfile.mime[0]])
if fingerprint is not None:
try:
# ID3v2 tag
fingerprint = fingerprint.text[0]
except AttributeError:
# Vorbis
fingerprint = fingerprint[0]