audiotools.musicbrainz — MusicBrainz Lookup Service Module

The audiotools.musicbrainz module contains classes and functions for performing lookups to the MusicBrainz service.

DiscID Objects

class audiotools.musicbrainz.DiscID(first_track_number, last_track_number, lead_out_offset, offsets)

A MusicBrainz disc ID object used to perform lookups. first_track_number is the first track number on the CD (typically 1), last_track_number is the last track number on the CD. lead_out_offset is the CD’s lead-out sector offset (including the 2 second pre-gap). offsets is a list of track offsets in CD sectors (1/75th of a second), each including the 2 second pre-gap at the start of the disc.


Returns the disc ID as a 28 character string that MusicBrainz expects when performing lookups.

classmethod DiscID.from_cddareader(cddareader)

Given a audiotools.cdio.CDDAReader object, returns the DiscID of that disc.

classmethod DiscID.from_tracks(tracks)

Given a sorted list of audiotools.AudioFile objects, returns the DiscID as if those tracks were a CD.


This assumes all the tracks from the disc are present and are laid out in a conventional fashion with no “hidden” tracks or other oddities. The disc ID may not be accurate if that’s not the case.

classmethod DiscID.from_sheet(sheet, total_pcm_frames, sample_rate)

Given a audiotools.Sheet object along with the total length of the disc in PCM frames and the disc’s sample rate (typically 44100), returns the DiscID.

Performing Lookup

audiotools.musicbrainz.perform_lookup(disc_id, musicbrainz_server, musicbrainz_port)

Given a DiscID object, MusicBrainz hostname string and MusicBrainz server port (usually 80), iterates over a list of audiotools.MetaData objects per successful match, like:

[track1, track2, ...], [track1, track2, ...], ...

May yield nothing if the server has no matches for the given disc ID.

May raise urllib2.HTTPError if an error occurs querying the server or xml.parsers.expat.ExpatError if the server returns invalid data.