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
-
libdiscid.
read
(device=None, features=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 ofFEATURE_MCN
andFEATURE_ISRC
andFEATURE_READ
. Note that prior to libdiscid version 0.5.0 features has no effect and thatFEATURE_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: - libdiscid.DiscError – reading the disc failed
- NotImplementedError – reading discs is not supported
- MemoryError – failed to allocate the internal DiscId object
Return type: DiscId
object
-
libdiscid.
put
(first, last, sectors, offsets)¶ Creates a TOC based on the given offets.
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.
default_device
()¶ 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: unicode
-
libdiscid.
sectors_to_seconds
(sectors)¶ Convert sectors to seconds rounded to the nearest second.
Parameters: sectors (integer) – number of sectors Return type: integer
-
libdiscid.
FEATURES
= [u'read', u'mcn', u'isrc']¶ List of all available features supported by libdiscid on this platform.
-
libdiscid.
FEATURES_MAPPING
= {1L: u'read', 2L: u'mcn', 4L: u'isrc'}¶ Mapping between the constants representing a feature and their string representation.
-
libdiscid.
FEATURE_READ
= 1L¶ Read the TOC of the disc to get the disc ID. This feature is always enabled.
-
libdiscid.
FEATURE_MCN
= 2L¶ Read the Media Catalogue Number of the disc.
-
libdiscid.
FEATURE_ISRC
= 4L¶ Read International Standard Recording Codes of all the tracks.
-
libdiscid.
DEFAULT_DEVICE
= u'/dev/cdrom'¶ The default device to use for
DiscId.read()
on this platform.Deprecated since version 0.2.0: Please use
default_device()
instead.
-
class
libdiscid.
DiscId
(cdiscid)¶ Disc information
Class holding all the information obtained from a disc.
-
device
¶ The device the data was read from.
If it is
None
,libdiscid.put()
was called to create the instance.
-
first_track
¶ Number of the first audio track.
-
last_track
¶ Number of the last audio track.
-
leadout_track
¶ Leadout track.
-
mcn
¶ Media Catalogue Number of the disc.
Raises: NotImplementedError – reading MCN is not supported on this platform
-
pregap
¶ Pregap of the first track (in sectors).
-
sectors
¶ Total sector count.
-
submission_url
¶ Disc ID / TOC Submission URL for MusicBrainz
With this url you can submit the current TOC as a new MusicBrainz Disc ID.
-
toc
¶ String representing the CD’s Table of Contents (TOC).
Raises: ValueError – extracting TOC string from the submission URL failed
-
track_isrcs
¶ 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
-
track_lengths
¶ Tuple of all track lengths (in sectors).
The first element corresponds to the length of the track denoted by
first_track
and so on.
-
track_offsets
¶ Tuple of all track offsets (in sectors).
The first element corresponds to the offset of the track denoted by
first_track
and so on.
-
webservice_url
¶ The web service URL for info about the CD
With this url you can retrive information about the CD in XML from the MusicBrainz web service.
-
-
exception
libdiscid.
DiscError
¶ libdiscid.read()
andlibdiscid.put()
will raise this exception when an error occurred.
Classes¶
-
class
libdiscid.
DiscId
(cdiscid) Bases:
object
Disc information
Class holding all the information obtained from a disc.
-
device
The device the data was read from.
If it is
None
,libdiscid.put()
was called to create the instance.
-
first_track
Number of the first audio track.
-
freedb_id
The FreeDB Disc ID (without category).
-
id
The MusicBrainz Disc ID.
-
last_track
Number of the last audio track.
-
leadout_track
Leadout track.
-
mcn
Media Catalogue Number of the disc.
Raises: NotImplementedError – reading MCN is not supported on this platform
-
pregap
Pregap of the first track (in sectors).
-
sectors
Total sector count.
-
submission_url
Disc ID / TOC Submission URL for MusicBrainz
With this url you can submit the current TOC as a new MusicBrainz Disc ID.
-
toc
String representing the CD’s Table of Contents (TOC).
Raises: ValueError – extracting TOC string from the submission URL failed
-
track_isrcs
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
-
track_lengths
Tuple of all track lengths (in sectors).
The first element corresponds to the length of the track denoted by
first_track
and so on.
-
track_offsets
Tuple of all track offsets (in sectors).
The first element corresponds to the offset of the track denoted by
first_track
and so on.
-
webservice_url
The web service URL for info about the CD
With this url you can retrive information about the CD in XML from the MusicBrainz web service.
-
Exceptions¶
-
exception
libdiscid.
DiscError
Bases:
exceptions.IOError
libdiscid.read()
andlibdiscid.put()
will raise this exception when an error occurred.