ayan_player_cli/
lib.rs

1use std::{ffi::OsStr, fs, io::Error, path::Path};
2pub mod player;
3pub mod config;
4pub mod utils;
5
6
7pub use utils::print_help;
8pub use utils::print_files;
9pub use utils::count_slashes;
10pub use config::*;
11
12// public functions
13pub fn visit_dirs(dir: &Path, files: &mut Vec<String>, config: &Configs) -> Result<(), Error> {
14    if dir.is_dir() {
15        for entry in fs::read_dir(dir)? {
16            let entry = entry?;
17            let path = entry.path();
18            if path.is_dir() {
19                visit_dirs(&path, files, config)?;
20            } else {
21                let name = path.as_path().to_string_lossy().to_string();
22                let ext = path
23                    .as_path()
24                    .extension()
25                    .unwrap_or(OsStr::new(""))
26                    .to_str()
27                    .unwrap_or("")
28                    .to_lowercase();
29                match &config.filter {
30                    Some(a) => {
31                        if a == &ext {
32                            files.push(name);
33                        }
34                    },
35                    None => {
36                        if ["mp4", "mkv", "avi", "wmv", "flv", "mov", "webm"].contains(&ext.as_str()) {
37                            files.push(name);
38                        }
39                    }
40                }
41
42
43            }
44        }
45    }
46    Ok(())
47}
48
49