extern crate cue_sheet;
use cue_sheet::errors::Error;
use cue_sheet::tracklist::Tracklist;
use std::env;
use std::fs::File;
use std::io::Read;
fn perform_conversion(source: &str) -> Result<(), Error> {
let mut tracklist = Tracklist::parse(source)?;
assert_eq!(tracklist.files.len(), 1);
let file = tracklist.files.remove(0);
for ref t in file.tracks {
let duration = match t.duration.clone() {
Some(time) => time.to_string_2(),
None => "??:??".to_string(),
};
println!(
"{:02} {} - {} {}",
t.number,
t.title.as_ref().unwrap(),
t.performer
.clone()
.ok_or_else(|| Error::from("Not all tracks have a specified performer."))?,
duration
);
}
Ok(())
}
fn main() {
if let Some(path) = env::args().nth(1) {
let mut file = File::open(path).expect("Failed reading file.");
let mut content = String::new();
file.read_to_string(&mut content).unwrap();
perform_conversion(content.as_str()).expect("Conversion failed.");
} else {
println!(
"provide a path to a .cue file to be converted into a MusicBrainz compatible tracklist."
)
}
}