rust-mv3u/src/main.rs
kageru 026db02c64
removed pre-allocation of outputs
it doesn’t really seem to affect the performance anyway. vec.push() is pretty good
2018-10-28 11:33:03 +01:00

35 lines
1013 B
Rust

use std::fs::File;
use std::io::{BufRead, BufReader, Result};
use std::collections::HashMap;
use std::fs;
fn main() -> Result<()> {
let file = File::open("beets_mv3u_renames")?;
let mut renames = HashMap::new();
for line in BufReader::new(file).lines() {
let line = line?;
let split: Vec<&str> = line.split("\t\t").collect();
renames.insert(split[0].to_string(), split[1].to_string());
}
let mut outputs = Vec::new();
let pls_file = File::open("playlist.m3u")?;
for entry in BufReader::new(pls_file).lines() {
let entry = entry?;
let new = renames.get(&entry).unwrap_or(&entry).to_string();
/*
if new != &entry {
println!("renamed “{}” to “{}”", entry, new);
} else {
println!("“{}” remains unchanged", entry);
}
*/
outputs.push(new);
}
let data = outputs.join("\n");
fs::write("playlist2.m3u", data).expect("unable to write");
Ok(())
}