From 718f0e27302a968058a0d234ae6fb5969cd66adf Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 8 Jan 2020 23:47:49 +0100 Subject: More stuff --- src/main.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 6760ee7..3939e17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,13 +16,26 @@ fn main() -> io::Result<()> { { let mut ap = ArgumentParser::new(); ap.set_description("ID3v2 tag editor/fixer. Incomplete/work-in-progress."); + + ap.refer(&mut options.write) + .add_option(&["-w", "--write"], StoreTrue, + "Write updated information instead of just displaying. Unmodified or unknown tags are preserved as-is."); + ap.refer(&mut options.latin1_as_utf8) .add_option(&["--assume-utf8"], StoreTrue, - "Assume that all strings specified as Latin-1 are really UTF-8."); + "Assume that all strings specified in the MP3 as Latin-1 are really UTF-8."); + + ap.refer(&mut options.set_tags.album) .add_option(&["-A", "--album"], Store, "Set/replace album"); + ap.refer(&mut options.set_tags.artist).add_option(&["-a", "--artist"], Store, "Set/replace artist"); + ap.refer(&mut options.set_tags.title) .add_option(&["-t", "--title"], Store, "Set/replace title"); + ap.refer(&mut options.set_tags.track) .add_option(&["-T", "--track"], Store, "Set/replace track number (num or num/num)"); + ap.refer(&mut options.set_tags.year) .add_option(&["-y", "--year"], Store, "Set/replace year"); + ap.refer(&mut options.file) .required() .add_argument("file", Store, "File to operate on (probably a .mp3)"); + ap.parse_args_or_exit(); } @@ -31,11 +44,24 @@ fn main() -> io::Result<()> { let mut f = File::open(options.file)?; let tag = id3v2::ID3v2::from_stream(&mut f)?; - println!("{:?}", tag); + // println!("{:?}", tag); + + // TODO: apply changes from options here for frame in tag.frames { - println!("{:?}", frame.interpret(&EncodingOptions { latin1_as_utf8: options.latin1_as_utf8 })); + match frame.interpret(&EncodingOptions { latin1_as_utf8: options.latin1_as_utf8 })? { + Some(id3v2::Frame::TALB(album)) => println!("Album : '{}'", album), + Some(id3v2::Frame::TIT2(title)) => println!("Title : '{}'", title), + Some(id3v2::Frame::TPE1(artist)) => println!("Artist: '{}'", artist), + Some(id3v2::Frame::TYER(year)) => println!("Year : '{}'", year), + Some(id3v2::Frame::TRCK(track)) => println!("Track : '{}'", track), + None => { + println!("Unknown frame: {:?}", frame); + } + } } + // TODO: if -w, then write tags to file (if it fits) + Ok(()) } -- cgit v1.2.3