Skip to content

Commit ce45f17

Browse files
committed
fix: allow mov files too and fix crash with regex
1 parent dc1fe58 commit ce45f17

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

src/media_info.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,16 @@ use std::fs;
44
use std::process::Command;
55

66
pub fn get_media_info(input: &str) -> OutputMetadata {
7-
let re = Regex::new(r"(\d{4}(?:-|\.)\d{2}(?:-|\.)\d{2})?(?:-|\.)*(.+).(mp4)").unwrap();
8-
9-
let captures = re.captures(input).expect("expect YYYY-MM-DD-File-Name.mp4");
10-
11-
println!("captures len {}", captures.len());
12-
for cap in 0..captures.len() {
13-
println!(
14-
"{}: {}",
15-
cap,
16-
format!("{}", captures.get(cap).unwrap().as_str())
17-
);
187
if !fs::metadata(&input).is_ok() {
198
println!("{} is not found.", &input);
209
std::process::exit(1);
2110
}
2211

23-
// TODO: Make the date optional
24-
// let mut date = "";
25-
// if captures.len() < 4 {
26-
// }
12+
let re = Regex::new(r"(\d{4}(?:-|\.)\d{2}(?:-|\.)\d{2})?(?:-|\.)*(.+).(mp4|mov)").unwrap();
13+
14+
let captures = re.captures(input).expect("expect YYYY-MM-DD-File-Name.mp4");
2715

28-
let date = captures.get(1).unwrap().as_str();
16+
let date = captures.get(1).map_or("No Date", |x| x.as_str());
2917
let extracted_filename = captures.get(2).unwrap().as_str();
3018
let extension = captures.get(3).unwrap().as_str();
3119

0 commit comments

Comments
 (0)