Advertisement
symdrome

main.rs

Sep 6th, 2023
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.06 KB | None | 0 0
  1. use std::fs::read_dir;
  2. use csv::Writer;
  3. use chrono::Local;
  4.  
  5. mod libs;
  6. use libs::Audio;
  7.  
  8. mod cli;
  9. use cli::Cli;
  10.  
  11. fn main() {
  12.     let cli = Cli::new();
  13.  
  14.     let src = cli.src.unwrap_or_default();
  15.     let dst = cli.dst.unwrap_or_default();
  16.     let op = cli.op.unwrap();
  17.  
  18.     let dd = Local::now().format("%d%m%Y-%H%M");
  19.     let file = format!("{}/{}_{}_{}", dst, op, dd ,"audios_duration.csv");
  20.  
  21.     let mut wtr = Writer::from_path(file).unwrap();
  22.     let _ = wtr.write_record(&["Nome","Duração"]);
  23.  
  24.     for entry in read_dir(src).expect("source directory not found.") {
  25.         let entry = entry.unwrap();
  26.  
  27.         if entry.path().is_file() {
  28.             match  entry.file_name().to_string_lossy() {
  29.                 f if f.ends_with(".wav") | f.ends_with(".mp3") | f.ends_with(".mp4") => {
  30.                     let res = Audio::get_length(entry);
  31.                    
  32.                     let _ = wtr.write_record(&[res.name, res.duration]);
  33.                    
  34.                 },
  35.                 _ => continue,
  36.             }
  37.         }
  38.     }
  39.    
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement