diff options
author | tomsmeding <tom.smeding@gmail.com> | 2020-01-12 21:08:12 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2020-01-12 21:08:12 +0100 |
commit | 771ff47545cea2b3e9a12aceb305ffcb53aa40b6 (patch) | |
tree | 008ba3a5512451be9293ac64a0250a87b99b0c53 /src/main.rs | |
parent | 5e39d6876b806604090b892369cba9892c7dac25 (diff) |
Correctly write tags
It's now able to fix fake-utf8 v2.3 tags generated with the id3v2 tool!
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index c2b4c5a..ab070ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use std::io; -use std::fs::File; +use std::io::{self, Write}; +use std::fs::{File, OpenOptions}; use argparse::{ArgumentParser, Store, StoreTrue, StoreOption}; use crate::error::IntoIOError; use crate::id3v2::{ID3v2, Frame}; @@ -9,7 +9,6 @@ mod encoding; mod error; mod id3v2; mod options; -mod util; fn parse_options_into(opt: &mut Options) { let mut ap = ArgumentParser::new(); @@ -87,7 +86,7 @@ fn modify_tag(tag: &mut ID3v2, new_frame: Frame) -> io::Result<()> { fn main() -> io::Result<()> { let options = parse_options(); - let mut tag = ID3v2::from_stream(&mut File::open(options.file)?)?; + let mut tag = ID3v2::from_stream(&mut File::open(&options.file)?)?; // println!("{:?}", tag); if options.latin1_as_utf8 { @@ -109,6 +108,11 @@ fn main() -> io::Result<()> { print_tag(&tag)?; // TODO: if -w, then write tags to file (if it fits) + if options.write { + let encoded = tag.encode()?; + let mut f = OpenOptions::new().write(true).open(&options.file)?; + f.write_all(&encoded)?; + } Ok(()) } |