libdiscid package

libdiscid module

Python bindings for libdiscid

libdiscid is a library to calculate MusicBrainz Disc IDs. This module provides Python-bindings for libdiscid.

>>> disc = libdiscid.read()
>>> disc.id is not None
True
exception libdiscid.DiscError

libdiscid.read() and libdiscid.put() will raise this exception when an error occurred.

class libdiscid.DiscId(cdiscid: DiscId)

Disc information

Class holding all the information obtained from a disc.

property device: str | None

The device the data was read from.

If it is None, libdiscid.put() was called to create the instance.

property first_track: int

Number of the first audio track.

property freedb_id: str

The FreeDB Disc ID (without category).

property id: str

The MusicBrainz Disc ID.

property last_track: int

Number of the last audio track.

property leadout_track: int

Leadout track.

property mcn: str

Media Catalogue Number of the disc.

Raises:

NotImplementedError – reading MCN is not supported on this platform

property pregap: int

Pregap of the first track (in sectors).

property sectors: int

Total sector count.

property submission_url: str

Disc ID / TOC Submission URL for MusicBrainz

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

property toc: str

String representing the CD’s Table of Contents (TOC).

Raises:

ValueError – extracting TOC string from the submission URL failed

property track_isrcs: Tuple[str]

Tuple of ISRCs of all tracks.

The first element of the list corresponds to the ISRC of the first_track and so on.

Raises:

NotImplementedError – reading ISRCs is not supported on this platform

property track_lengths: Tuple[int]

Tuple of all track lengths (in sectors).

The first element corresponds to the length of the track denoted by first_track and so on.

property track_offsets: Tuple[int]

Tuple of all track offsets (in sectors).

The first element corresponds to the offset of the track denoted by first_track and so on.

property webservice_url: str

The web service URL for info about the CD

With this url you can retrieve information about the CD in XML from the MusicBrainz web service.

libdiscid.FEATURES = ('read', 'mcn', 'isrc')

Tuple of all available features supported by libdiscid on this platform.

libdiscid.FEATURES_MAPPING = {1: 'read', 2: 'mcn', 4: 'isrc'}

Mapping between the constants representing a feature and their string representation.

libdiscid.FEATURE_ISRC = 4

Read International Standard Recording Codes (ISRC) of all the tracks.

libdiscid.FEATURE_MCN = 2

Read the Media Catalogue Number of the disc.

libdiscid.FEATURE_READ = 1

Read the TOC of the disc to get the disc ID. This feature is always enabled.

libdiscid.default_device() str

The default device on this platform.

The default device can change during the run-time of the program. This can happen with removable devices for example.

Return type:

str

libdiscid.put(first: int, last, sectors: int, offsets: List[int] | Tuple[int]) DiscId

Creates a TOC based on the given offsets.

Takes the first and last audio track, as well as the number of sectors and a list of offsets as in track_offsets.

Parameters:
  • first (integer) – number of the first audio track

  • last (integer) – number of the last audio track

  • sectors (integer) – total number of sectors on the disc

  • offsets (list or tuple of integers) – offsets of each track

Raises:
  • libdiscid.DiscError – operation failed for some reason

  • MemoryError – failed to allocated memory to store the offsets or the internal DiscId object

Return type:

DiscId object

libdiscid.read(device: str | bytes | None = None, features: int | None = None)

Reads the TOC from the device given as string.

If device is None, default_device() is used to determine the device. features can be any combination of FEATURE_MCN and FEATURE_ISRC and FEATURE_READ. Note that prior to libdiscid version 0.5.0 features has no effect and that FEATURE_READ is always assumed, even if not given.

Parameters:
  • device (unicode or None) – device to read from

  • features (integer or None) – selected features, possible values are FEATURE_READ FEATURE_MCN, FEATURE_ISRC and any of these values combined with bitwise or.

Raises:
Return type:

DiscId object

libdiscid.sectors_to_seconds(sectors: int) int

Convert sectors to seconds rounded to the nearest second.

Parameters:

sectors (integer) – number of sectors

Return type:

integer

Subpackages