diff --git a/Cargo.toml b/Cargo.toml index b4ccb1d..4289720 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ getrandom = { version = "0.2", features = ["js"] } des = "0.8" cbc = "0.1" ecb = "0.1" -tokio = { version = "1.36", features = ["sync"] } +tokio = { version = "1.36", features = ["full", "sync"] } g2-unicode-jp = "0.4.1" thiserror = "1.0.57" phf = { version = "0.11.2", features = ["phf_macros", "macros"] } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..123ae3a --- /dev/null +++ b/src/main.rs @@ -0,0 +1,42 @@ +use std::{process::exit, time::Duration}; + +#[tokio::main] +async fn main() { + let Ok(player) = cross_usb::get_device(minidisc::netmd::DEVICE_IDS_CROSSUSB.to_vec()).await else { + eprintln!("Could not find a MiniDisc device"); + exit(1); + }; + + let Ok(mut player) = minidisc::netmd::NetMDContext::new(player).await else { + eprintln!("Could not open device!"); + exit(1); + }; + + let disc = player.list_content().await.expect("Could not retrieve player's contents"); + + for track in disc.tracks() { + println!( + "{:02}:\n Title: {} | {}\n Duration: {}\n Encoding: {}\n", + track.index(), + track.title(), track.full_width_title(), + pretty_time(track.duration().as_duration()), + track.encoding(), + ); + } +} + +fn pretty_time(dur: Duration) -> String { + let mut string = String::new(); + if dur >= Duration::from_secs(3600) { + string.push_str(&format!("{:02}", dur.as_secs() / 3600)); + string.push(':'); + } + if dur >= Duration::from_secs(60) { + string.push_str(&format!("{:02}", (dur.as_secs() / 60) % 3600).to_string()); + string.push(':'); + } + if dur >= Duration::from_secs(60) { + string.push_str(&format!("{:02}", dur.as_secs() % 60).to_string()); + } + string +} diff --git a/src/netmd/commands.rs b/src/netmd/commands.rs index 6465a08..6b948e5 100644 --- a/src/netmd/commands.rs +++ b/src/netmd/commands.rs @@ -32,8 +32,8 @@ pub enum OperatingStatus { ReadyForTransfer = 65319, } -/// A representation of time in the same way NetMD devices do. -#[derive(Debug, Clone)] +/// A representation of time in the way a NetMD device uses internally. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Time { pub minute: u16, pub second: u16, @@ -41,7 +41,7 @@ pub struct Time { } /// A representation of the current status of the device. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct DeviceStatus { pub disc_present: bool, pub state: Option, @@ -50,7 +50,7 @@ pub struct DeviceStatus { } /// Information about a single track -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Track { index: u16, title: String, @@ -77,6 +77,34 @@ impl Track { usize::max(encoding_name_correction, full_width_length), ) } + + pub fn index(&self) -> u16 { + self.index + } + + pub fn title(&self) -> &String { + &self.title + } + + pub fn full_width_title(&self) -> &String { + &self.full_width_title + } + + pub fn duration(&self) -> RawTime { + self.duration + } + + pub fn channels(&self) -> Channels { + self.channel + } + + pub fn encoding(&self) -> Encoding { + self.encoding + } + + pub fn protected(&self) -> TrackFlag { + self.protected + } } /// Information about a single group on the disc, containing [`Track`]s diff --git a/src/netmd/interface.rs b/src/netmd/interface.rs index 72f28f4..eef690b 100644 --- a/src/netmd/interface.rs +++ b/src/netmd/interface.rs @@ -75,7 +75,7 @@ impl WireFormat { } /// The encoding of the audio -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum Encoding { SP = 0x90, LP2 = 0x92, @@ -93,7 +93,7 @@ impl std::fmt::Display for Encoding { } /// The number of channels in the audio -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum Channels { Mono = 0x01, Stereo = 0x00, @@ -114,7 +114,7 @@ enum ChannelCount { } /// The protected flag on a track -#[derive(Debug, Clone, Copy, FromPrimitive)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive)] pub enum TrackFlag { Protected = 0x03, Unprotected = 0x00,