[−][src]Struct discid::DiscId
DiscId
holds information about a disc (TOC, MCN, ISRCs).
Use DiscId::read
, DiscId::read_features
, DiscId::put
or DiscId::parse
to initialize an instance of DiscId
.
Methods
impl DiscId
[src]
pub fn read(device: Option<&str>) -> Result<DiscId, DiscError>
[src]
Read the disc in the given CD-ROM/DVD-ROM drive extracting only the TOC.
This function reads the disc in the drive specified by the given device
identifier. If the device is None
, the default device, as returned by
DiscId::default_device
, is used.
This function will only read the TOC, hence only the disc ID itself will be
available. Use DiscId::read_features
if you want to read also MCN and ISRCs.
Examples
Read from default device
use discid::DiscId; let disc = DiscId::read(None).expect("Reading disc failed"); println!("ID: {}", disc.id());
Read from specific device
let disc = DiscId::read(Some("/dev/sr1")).expect("Reading disc failed"); println!("ID: {}", disc.id());
pub fn read_features(
device: Option<&str>,
features: Features
) -> Result<DiscId, DiscError>
[src]
device: Option<&str>,
features: Features
) -> Result<DiscId, DiscError>
Read the disc in the given CD-ROM/DVD-ROM drive with additional features.
This function is similar to DiscId::read
but allows to read information about MCN
and per-track ISRCs in addition to the normal TOC data.
The parameter features
accepts a bitwise combination of values defined in Features
.
Features::READ
is always implied, so it is not necessary to specify it.
Reading MCN and ISRCs is not available on all platforms. You can use the
has_feature
method to check if a specific feature is available. Passing unsupported
features here will just be ignored.
Note that reading MCN and ISRC data is significantly slower than just reading the TOC, so only request the features you actually need.
Examples
Read both ISRC and MCN from default device
use discid::{DiscId, Features}; let features = Features::MCN | Features::ISRC; let disc = DiscId::read_features(None, features).expect("Reading disc failed"); println!("ID : {}", disc.id()); println!("MCN: {}", disc.mcn()); for track in disc.tracks() { println!("#{} ISRC: {}", track.number, track.isrc); }
pub fn put(first: i32, offsets: &[i32]) -> Result<DiscId, DiscError>
[src]
Provides the TOC of a known CD.
This function may be used if the TOC has been read earlier and you want to calculate the disc ID afterwards, without accessing the disc drive.
first
is the track number of the first track (1-99).
The offsets
parameter points to an array which contains the track offsets for each track.
The first element, offsets[0]
, is the leadout track. It must contain the total number of
sectors on the disc. offsets
must not be longer than 100 elements (leadout + 99 tracks).
Examples:
use discid::DiscId; let first_track = 1; // The offsets contain the total number of sectors as first element, followed by // the start sectors of each track. let offsets = [ 242457, 150, 44942, 61305, 72755, 96360, 130485, 147315, 164275, 190702, 205412, 220437, ]; let disc = DiscId::put(first_track, &offsets).expect("DiscId::put() failed"); assert_eq!("lSOVc5h6IXSuzcamJS1Gp4_tRuA-", disc.id());
pub fn parse(toc: &str) -> Result<DiscId, DiscError>
[src]
Parses a TOC string and returns a DiscId
instance for it.
The TOC string provided here must have the same format as returned by toc_string
.
This function can be used if you already have a TOC string like e.g.
1 11 242457 150 44942 61305 72755 96360 130485 147315 164275 190702 205412 220437
.
Examples:
use discid::DiscId; let toc = "1 11 242457 150 44942 61305 72755 96360 130485 147315 164275 190702 205412 220437"; let disc = DiscId::parse(toc).expect("DiscId::put() failed"); assert_eq!("lSOVc5h6IXSuzcamJS1Gp4_tRuA-", disc.id()); assert_eq!(toc, disc.toc_string());
pub fn has_feature(feature: Features) -> bool
[src]
Check if a certain feature is implemented on the current platform.
This only works for single features, not bit masks with multiple features.
See the libdiscid feature matrix for a list of supported features per platform.
Examples
use discid::{DiscId, Features}; let can_read = DiscId::has_feature(Features::READ); assert!(can_read);
pub fn version_string() -> String
[src]
Return version information about libdiscid.
The returned string will be e.g. "libdiscid 0.6.2"
.
Examples
use discid::DiscId; println!("{}", DiscId::version_string());
pub fn default_device() -> String
[src]
Return the name of the default disc drive for this operating system.
The default device is system dependent, e.g. /dev/cdrom
on Linux and D:
on Windows.
Examples
use discid::DiscId; println!("{}", DiscId::default_device());
pub fn id(&self) -> String
[src]
The MusicBrainz disc ID.
pub fn freedb_id(&self) -> String
[src]
The FreeDB disc ID.
pub fn toc_string(&self) -> String
[src]
Return a string representing CD Table Of Contents (TOC).
The TOC string is a list of integers separated by a single space character. The integers represent (in order):
- First track number (normally one)
- Last track number
- Lead-out track offset
- Up to 99 frame offsets
See also DiscId::parse
and the documentation for Disc ID Calculation.
pub fn submission_url(&self) -> String
[src]
An URL for submitting the DiscID to MusicBrainz.
pub fn first_track_num(&self) -> i32
[src]
The number of the first track on this disc.
pub fn last_track_num(&self) -> i32
[src]
The number of the last track on this disc.
pub fn sectors(&self) -> i32
[src]
The length of the disc in sectors.
pub fn mcn(&self) -> String
[src]
The media catalogue number on the disc, if present.
ⓘImportant traits for TrackIterpub fn tracks(&self) -> TrackIter
[src]
Returns an iterator to access information about each track on the disc.
Returns an instance of Track
for each track.
Examples
use discid::DiscId; let offsets = [ 242457, 150, 44942, 61305, 72755, 96360, 130485, 147315, 164275, 190702, 205412, 220437, ]; let disc = DiscId::put(1, &offsets).expect("DiscId::put() failed"); for track in disc.tracks() { println!("Track #{}", track.number); println!(" ISRC : {}", track.isrc); println!(" Offset : {}", track.offset); println!(" Sectors : {}", track.sectors); }
pub fn nth_track(&self, number: i32) -> Track
[src]
Returns a Track
instance for the nth track.
Panics
Panics if number
is outside the range given by first_track_num
and last_track_num
.
Examples
use discid::DiscId; let offsets = [ 242457, 150, 44942, 61305, 72755, 96360, 130485, 147315, 164275, 190702, 205412, 220437, ]; let disc = DiscId::put(1, &offsets).expect("DiscId::put() failed"); let track = disc.nth_track(7); assert_eq!(7, track.number); assert_eq!(147315, track.offset); assert_eq!(16960, track.sectors);
Trait Implementations
Auto Trait Implementations
impl !Send for DiscId
impl !Sync for DiscId
impl Unpin for DiscId
impl UnwindSafe for DiscId
impl !RefUnwindSafe for DiscId
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,