autorip 0.1.1

Composes other programs to automatically rip optical media
Documentation
use std::{
    path::{Path, PathBuf},
    process::Command,
};

use anyhow::{anyhow, Result};

use super::{Rip, RipConfig};

#[non_exhaustive]
pub(crate) enum AudioMediaSource<'a> {
    CDRom(CD<'a>),
}

impl<'a> AudioMediaSource<'a> {
    pub(crate) fn new(path: &'a Path) -> Result<Self> {
        match path.to_str() {
            Some("/dev/cdrom") => Ok(Self::CDRom(CD { path })),
            _ => Err(anyhow!(
                "Unsure how to create AutoMediaSource from {}",
                path.display()
            )),
        }
    }
}

impl Rip for AudioMediaSource<'_> {
    fn rip(&self, config: &RipConfig) -> Result<PathBuf> {
        match self {
            Self::CDRom(cd) => cd.rip(config),
        }
    }
}

pub(crate) struct CD<'a> {
    pub(crate) path: &'a Path,
    // pub(crate) duration: Option<u32>,
    // pub(crate) title_hint: String,
}

// whipper cd rip --unknown --cdr
impl Rip for CD<'_> {
    fn rip(&self, _config: &RipConfig) -> Result<PathBuf> {
        let _output = Command::new("whipper")
            .args("cd rip --unknown".split_whitespace())
            .output()?;
        Ok(".".into())
    }
}