fn convert_or_copy(filename: &Path, settings: &Settings, info: &MediaInfo) -> Result<Box<PathBuf>, &'static str> {
    let mut imported_filename = Path::new(&settings.path.data_path).join(filename.file_name().unwrap());

    println!(" -> Extracting cover art");
    let coverart_filename = imported_filename.with_extension("jpg");
    let _ = extract_coverart(filename, &coverart_filename);
    
    println!(" -> Converting/copying file");

    // if this is an audible aax file, remove the DRM
    if info.format == "aax" {
        // change the extension to `m4a`
        imported_filename = imported_filename.with_extension("m4a");

        // try to load activation bytes from config
        if let Some(ref audible_settings) = settings.audible {
            
            // remove the DRM
            let result = de_aax(filename, &imported_filename, &audible_settings.activation_bytes);
            if result.success() {
                Ok(Box::new(imported_filename))
            } else {
                Err("could not convert file")
            }
        } else {
            // No activation bytes in config, inform user
            Err("please configure audible = {{ activation_bytes = \"<hex>\" }}")
        }
    } else if info.format == "aa" {
        // change the extension to `mp3`
        imported_filename = imported_filename.with_extension("mp3");        

        // convert file
        let result = convert(filename, &imported_filename, "copy");
        if result.success() {
            Ok(Box::new(imported_filename))
        } else {
            Err("could not convert file")
        }
    } else {
        // try copying the file into the data directory
        if let Ok(_) = fs::copy(filename, &imported_filename) {
            Ok(Box::new(imported_filename))
        } else {
            // something went wrong, inform user
            Err("could not copy file")
        }
    }
}
/// Either converts/decodes/de-DRMs a media file or just copies it
/// into the managed data directory
Either converts/decodes/de-DRMs a media file or just copies it
into the managed data directory
Either converts / decodes / de - DRMs a media file or just copies it into the managed data directory
fn convert_or_copy(filename: &Path, settings: &Settings, info: &MediaInfo) -> Result<Box<PathBuf>, &'static str> {
    let mut imported_filename = Path::new(&settings.path.data_path).join(filename.file_name().unwrap());
    println!(" -> Extracting cover art");
    let coverart_filename = imported_filename.with_extension("jpg");
    let _ = extract_coverart(filename, &coverart_filename);
    println!(" -> Converting/copying file");
    // if this is an audible aax file, remove the DRM
    if info.format == "aax" {
        // change the extension to `m4a`
        imported_filename = imported_filename.with_extension("m4a");
        // try to load activation bytes from config
        if let Some(ref audible_settings) = settings.audible {
            // remove the DRM
            let result = de_aax(filename, &imported_filename, &audible_settings.activation_bytes);
            if result.success() {
                Ok(Box::new(imported_filename))
            } else {
                Err("could not convert file")
            }
        } else {
            // No activation bytes in config, inform user
            Err("please configure audible = {{ activation_bytes = \"<hex>\" }}")
        }
    } else if info.format == "aa" {
        // change the extension to `mp3`
        imported_filename = imported_filename.with_extension("mp3");        
        // convert file
        let result = convert(filename, &imported_filename, "copy");
        if result.success() {
            Ok(Box::new(imported_filename))
        } else {
            Err("could not convert file")
        }
    } else {
        // try copying the file into the data directory
        if let Ok(_) = fs::copy(filename, &imported_filename) {
            Ok(Box::new(imported_filename))
        } else {
            // something went wrong, inform user
            Err("could not copy file")
        }
    }
}
fn convert_or_copy ( filename : & Path , settings : & Settings , info : & MediaInfo ) -> Result < Box < PathBuf > , & ' static str > { let mut imported_filename = Path :: new ( & settings . path . data_path ) . join ( filename . file_name ( ) . unwrap ( ) ) ; println ! ( " " ) ; let coverart_filename = imported_filename . with_extension ( " " ) ; let _ = extract_coverart ( filename , & coverart_filename ) ; println ! ( " " ) ; // if this is an audible aax file, remove the DRM if info . format == " " { // change the extension to `m4a` imported_filename = imported_filename . with_extension ( " " ) ; // try to load activation bytes from config if let Some ( ref audible_settings ) = settings . audible { // remove the DRM let result = de_aax ( filename , & imported_filename , & audible_settings . activation_bytes ) ; if result . success ( ) { Ok ( Box :: new ( imported_filename ) ) } else { Err ( " " ) } } else { // No activation bytes in config, inform user Err ( " \" \" " ) } } else if info . format == " " { // change the extension to `mp3` imported_filename = imported_filename . with_extension ( " " ) ; // convert file let result = convert ( filename , & imported_filename , " " ) ; if result . success ( ) { Ok ( Box :: new ( imported_filename ) ) } else { Err ( " " ) } } else { // try copying the file into the data directory if let Ok ( _ ) = fs :: copy ( filename , & imported_filename ) { Ok ( Box :: new ( imported_filename ) ) } else { // something went wrong, inform user Err ( " " ) } } }
Either converts/decodes/de-DRMs a media file or just copies it
into the managed data directory
Either converts / decodes / de - DRMs a media file or just copies it into the managed data directory
filename
&Path
settings
&Settings
info
&MediaInfo
filename
&Path
settings
&Settings
info
&MediaInfo