discid API

Python binding of Libdiscid

Libdiscid is a library to calculate MusicBrainz Disc IDs. This module provides a python-like API for that functionality.

The user is expected to create a DiscId object, feed it with some type of TOC and extract the generated information.

Importing this module will open libdiscid at the same time and will raise OSError when libdiscid is not found.

At the module level there are these constants available:

discid.DEFAULT_DEVICE

The default device to use for DiscId.read() on this platform given as a unicode or str object.

discid.FEATURES

The supported features for the platform as a list of strings. The full set currently is ['read', 'MCN', 'ISRC']. Some Functions can raise NotImplementedError when a feature is not available.

DiscId object

The user is expected to create a DiscId object, feed it with some type of TOC and extract the generated information.

class discid.DiscId

The main class of this module.

The initialization will reserve some memory for internal data structures.

You should use read() or put() before getting any data from an object of this class:

read(device=None)

Reads the TOC from the device given as string.

That string can be either of: str, unicode or bytes. However, it should in no case contain non-ASCII characters.

A DiscError exception is raised when the reading fails, and NotImplementedError when libdiscid doesn’t support reading discs on the current platform.

put(first, last, offsets)

Creates a TOC based on the offsets given.

Takes the first and last audio tracks as int and offsets is supposed to be the same as track_offsets. That is: offsets[0] are the total number of sectors and the following are the offsets of each track.

When the a TOC was successfully populated, you can access the informational attributes:

id

This is the MusicBrainz Disc ID.

It is set after a the TOC was populated or None. If set, this is a unicode or str object.

submission_url

With this url you can submit the current TOC as a new MusicBrainz Disc ID.

If there is no populated TOC the url is None. Otherwise this is a unicode or str object.

first_track_num

Number of the first track

last_track_num

Number of the last track

sectors

Total sector count

track_offsets

A list of all track offsets.

The first element is the leadout track and contains the total number of sectors on the disc. The following elements are the offsets for all audio tracks. track_offsets[i] is the offset for the i-th track (as int).

After you are done with the object, you should free the memory allocated for it:

free()

This will free the internal allocated memory for the object. You can’t use this object anymore afterwards.

Please consider using the with statement for the object, which will take care of this destruction automatically.

The discid module includes a custom exception to handle specific problems:

exception discid.DiscError

Bases: exceptions.IOError

DiscId.read() will raise this exception when an error occured. An error string (unicode/str) is provided.

Table Of Contents

Previous topic

Usage

Next topic

Changelog

This Page