diff options
-rw-r--r-- | src/id3v2.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 32 | ||||
-rw-r--r-- | src/options.rs | 21 |
3 files changed, 52 insertions, 7 deletions
diff --git a/src/id3v2.rs b/src/id3v2.rs index c16c573..a8dccb9 100644 --- a/src/id3v2.rs +++ b/src/id3v2.rs @@ -42,6 +42,8 @@ pub enum Frame { TIT2(String), TYER(String), TPE1(String), + TALB(String), + TRCK(String), } impl RawFrame { @@ -98,6 +100,10 @@ impl RawFrame { self.interpret_encoded_string(encopts).map(Frame::TYER).map(Some) } else if self.id == "TPE1" { self.interpret_encoded_string(encopts).map(Frame::TPE1).map(Some) + } else if self.id == "TALB" { + self.interpret_encoded_string(encopts).map(Frame::TALB).map(Some) + } else if self.id == "TRCK" { + self.interpret_encoded_string(encopts).map(Frame::TRCK).map(Some) } else { Ok(None) } 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(()) } diff --git a/src/options.rs b/src/options.rs index 3b36e52..e51004a 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,6 +1,21 @@ pub struct Options { pub latin1_as_utf8: bool, pub file: String, + pub write: bool, + pub set_tags: TagOptions, +} + +#[derive(Default)] +pub struct TagOptions { + pub album: String, + pub artist: String, + pub title: String, + pub track: String, + pub year: String, +} + +pub struct EncodingOptions { + pub latin1_as_utf8: bool, } impl Default for Options { @@ -8,10 +23,8 @@ impl Default for Options { Options { latin1_as_utf8: false, file: String::new(), + write: false, + set_tags: Default::default(), } } } - -pub struct EncodingOptions { - pub latin1_as_utf8: bool, -} |