Advertisement
symdrome

libs.rs

Sep 6th, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.62 KB | None | 0 0
  1. use std::process::Command;
  2. use std::fs::DirEntry;
  3.  
  4. pub struct Audio {
  5.     pub name: String,
  6.     pub duration: String,
  7. }
  8.  
  9. impl Audio {
  10.     pub fn get_length (audio: DirEntry) -> Audio {
  11.         let cmd = Command::new("soxi")
  12.             .args(["-D", &audio.path().to_string_lossy()]).output()
  13.             .expect("soxi -D failed");
  14.                    
  15.         let duration = String::from_utf8_lossy(&cmd.stdout)
  16.             .to_string().split('\n')
  17.             .collect::<String>();
  18.        
  19.         Audio {
  20.             name: audio.file_name().to_string_lossy().to_string(),
  21.             duration
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement