Skip to content

Commit 8085def

Browse files
committed
fix: improve capture groups regex
1 parent 7d75026 commit 8085def

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/media_info.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ use regex::Regex;
33
use std::process::Command;
44

55
pub fn get_media_info(input: &str) -> OutputMetadata {
6-
// TODO: Fix this so it works with . and - for date
7-
let re = Regex::new(r"(\d{4}-\d{2}-\d{2})?-(.*).(mp4)").unwrap();
6+
let re = Regex::new(r"(\d{4}(?:-|\.)\d{2}(?:-|\.)\d{2})?(?:-|\.)*(.+).(mp4)").unwrap();
87

98
let captures = re.captures(input).expect("expect YYYY-MM-DD-File-Name.mp4");
109

11-
// println!("captures len {}", captures.len());
12-
// for cap in 0..captures.len() {
13-
// println!("cap: {}", cap);
14-
// println!("{}", format!("{}", captures.get(cap).unwrap().as_str()));
15-
// }
10+
println!("captures len {}", captures.len());
11+
for cap in 0..captures.len() {
12+
println!(
13+
"{}: {}",
14+
cap,
15+
format!("{}", captures.get(cap).unwrap().as_str())
16+
);
17+
}
1618

1719
// TODO: Make the date optional
1820
// let mut date = "";

0 commit comments

Comments
 (0)