-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
tag_stripper.rs
62 lines (46 loc) · 1.33 KB
/
tag_stripper.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![allow(missing_docs)]
use lofty::file::TaggedFileExt;
use lofty::probe::Probe;
use std::io::Write;
fn main() {
let path = std::env::args().nth(1).expect("ERROR: No path specified!");
let tagged_file = Probe::open(path.as_str())
.expect("ERROR: Bad path provided!")
.read()
.expect("ERROR: Failed to read file!");
let tags = tagged_file.tags();
if tags.is_empty() {
eprintln!("ERROR: No tags found, exiting.");
std::process::exit(0);
}
let mut available_tag_types = Vec::new();
println!("Available tags:");
for (num, tag) in tags.iter().enumerate() {
let tag_type = tag.tag_type();
println!("{num}: {tag_type:?}");
available_tag_types.push(tag_type);
}
let mut to_remove = None;
let mut input = String::new();
while to_remove.is_none() {
print!("\nNumber to remove: ");
std::io::stdout().flush().unwrap();
if std::io::stdin().read_line(&mut input).is_ok() {
if let Ok(num) = str::parse::<usize>(input.trim()) {
if num < available_tag_types.len() {
to_remove = Some(num);
println!();
break;
}
}
}
input.clear();
eprintln!("ERROR: Unexpected input")
}
let tag_remove = available_tag_types[to_remove.unwrap()];
if tag_remove.remove_from_path(path).is_ok() {
println!("INFO: Removed tag: `{tag_remove:?}`");
} else {
eprintln!("ERROR: Failed to remove the tag")
}
}