mqa-identify 0.2.0

A minimal library, to check if a flac file has been encoded by/with MQA
Documentation
#![deny(clippy::pedantic)]

use std::path::PathBuf;

use clap::Parser;
use indicatif::ParallelProgressIterator;
use itertools::Itertools;
use mqa_identify::identify_mqa;
use rayon::prelude::*;

#[derive(Parser)]
struct Cli {
    paths: Vec<PathBuf>,
}

fn main() {
    let cli = Cli::parse();

    let mut flac_files = Vec::new();

    for path in cli.paths {
        find_flac_files(path, &mut flac_files);
    }

    let len = flac_files.len();

    let mqa_files: Vec<PathBuf> = flac_files
        .into_par_iter()
        .progress_count(len as u64)
        .filter(|path| {
            identify_mqa(path).unwrap_or_else(|_| {
                panic!(
                    "Failed to check if the file is mqa for file {}",
                    path.display()
                )
            })
        })
        .collect();

    match mqa_files.len() {
        0 => println!("No MQA files found."),
        1 => println!("Found 1 MQA file:\n{}", mqa_files[0].display()),
        n => println!(
            "Found {} MQA files:\n{}",
            n,
            mqa_files.iter().map(|p| p.display()).join("\n")
        ),
    }
}

fn find_flac_files(path: PathBuf, flac_files: &mut Vec<PathBuf>) {
    if path.is_dir() {
        for entry in path.read_dir().unwrap() {
            let entry = entry.unwrap();
            find_flac_files(entry.path(), flac_files);
        }
    } else if path.is_file()
        && path
            .extension()
            .is_some_and(|ext| ext.eq_ignore_ascii_case("flac"))
    {
        flac_files.push(path);
    }
}