Process multiple files at a time
This commit is contained in:
parent
5e84b5729c
commit
f96f454791
38
src/main.rs
38
src/main.rs
|
@ -5,6 +5,20 @@ use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
|
fn apply_renames(filename: &String, renames: &HashMap<String, String>) -> Result<()> {
|
||||||
|
let mut outputs = Vec::new();
|
||||||
|
|
||||||
|
let pls_file = File::open(filename)?;
|
||||||
|
for entry in BufReader::new(pls_file).lines() {
|
||||||
|
let entry = entry?;
|
||||||
|
let new = renames.get(&entry).unwrap_or(&entry).to_string();
|
||||||
|
outputs.push(new);
|
||||||
|
}
|
||||||
|
let data = outputs.join("\n");
|
||||||
|
fs::write(filename, data).expect("unable to write");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
@ -14,8 +28,6 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let rename_file = &args[1];
|
let rename_file = &args[1];
|
||||||
let playlist_file = &args[2];
|
|
||||||
println!("{:?}", rename_file);
|
|
||||||
|
|
||||||
let file = File::open(rename_file)?;
|
let file = File::open(rename_file)?;
|
||||||
let mut renames = HashMap::new();
|
let mut renames = HashMap::new();
|
||||||
|
@ -24,24 +36,16 @@ fn main() -> Result<()> {
|
||||||
let split: Vec<&str> = line.split("\t\t").collect();
|
let split: Vec<&str> = line.split("\t\t").collect();
|
||||||
renames.insert(split[0].to_string(), split[1].to_string());
|
renames.insert(split[0].to_string(), split[1].to_string());
|
||||||
}
|
}
|
||||||
|
for r in &args[2..] {
|
||||||
let mut outputs = Vec::new();
|
try!(apply_renames(&r, &renames));
|
||||||
|
|
||||||
let pls_file = File::open(playlist_file)?;
|
|
||||||
for entry in BufReader::new(pls_file).lines() {
|
|
||||||
let entry = entry?;
|
|
||||||
let new = renames.get(&entry).unwrap_or(&entry).to_string();
|
|
||||||
/*
|
/*
|
||||||
if new != &entry {
|
match apply_renames(&r, &renames) {
|
||||||
println!("renamed “{}” to “{}”", entry, new);
|
Ok(()) => println!("Successfully processed renames for {}", r)
|
||||||
} else {
|
},
|
||||||
println!("“{}” remains unchanged", entry);
|
_ => println!("Error processing {}", r);
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
outputs.push(new);
|
|
||||||
}
|
}
|
||||||
let data = outputs.join("\n");
|
|
||||||
fs::write("playlist2.m3u", data).expect("unable to write");
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user