fn downloader(target: &str, title: &str) -> Result<u8> {
    // Get the download dir from the Settings.toml file
    let dl_dir = settings::get_settings(&String::from("dl-dir")).unwrap();
    let archive_dir = settings::get_settings(&String::from("ar-dir")).unwrap();

    // Check if the download/archive location exists
    if !Path::new(&dl_dir).exists() {
        std::fs::create_dir_all(Path::new(&dl_dir)).expect("Failed to create directory");
    }
    if !Path::new(&archive_dir).exists() {
        std::fs::create_dir_all(Path::new(&archive_dir)).expect("Failed to create directory");
    }

    let check = archive_check(&target, &archive_dir);
    if check == "Found" {
        println!("File Found. Skipping Download");
        Ok(0)
    } else {
        // Normal download location
        let mut response = reqwest::get(target)?;
        let mut dest = {
            let fname = response
                .url()
                .path_segments()
                .and_then(|segments| segments.last())
                .and_then(|name| if name.is_empty() { None } else { Some(name) })
                .unwrap_or("tmp.bin");

            println!("file to download: '{}'", fname);
            let fname = format!("{}/{}", dl_dir, fname);
            println!("will be located under: '{:?}'", fname);
            File::create(fname)?
        };
        copy(&mut response, &mut dest)?;

        // The archive function
        let mut response = reqwest::get(target)?;
        let mut archive = {
            let fname = response
                .url()
                .path_segments()
                .and_then(|segments| segments.last())
                .and_then(|name| if name.is_empty() { None } else { Some(name) })
                .unwrap_or("tmp.bin");

            let fname = format!("{}/{}", archive_dir, fname);
            File::create(fname)?
        };
        copy(&mut response, &mut archive)?;
        info!("Downloaded {}", title);

        Ok(1)
    }
}
/// Function that takes in a link and downloads it to the specified path.
/// Returns either an `Ok` or an `Err`.
Function that takes in a link and downloads it to the specified path.
Returns either an `Ok` or an `Err`.
Function that takes in a link and downloads it to the specified path . Returns either an ` Ok ` or an ` Err ` .
fn downloader(target: &str, title: &str) -> Result<u8> {
    // Get the download dir from the Settings.toml file
    let dl_dir = settings::get_settings(&String::from("dl-dir")).unwrap();
    let archive_dir = settings::get_settings(&String::from("ar-dir")).unwrap();
    // Check if the download/archive location exists
    if !Path::new(&dl_dir).exists() {
        std::fs::create_dir_all(Path::new(&dl_dir)).expect("Failed to create directory");
    }
    if !Path::new(&archive_dir).exists() {
        std::fs::create_dir_all(Path::new(&archive_dir)).expect("Failed to create directory");
    }
    let check = archive_check(&target, &archive_dir);
    if check == "Found" {
        println!("File Found. Skipping Download");
        Ok(0)
    } else {
        // Normal download location
        let mut response = reqwest::get(target)?;
        let mut dest = {
            let fname = response
                .url()
                .path_segments()
                .and_then(|segments| segments.last())
                .and_then(|name| if name.is_empty() { None } else { Some(name) })
                .unwrap_or("tmp.bin");
            println!("file to download: '{}'", fname);
            let fname = format!("{}/{}", dl_dir, fname);
            println!("will be located under: '{:?}'", fname);
            File::create(fname)?
        };
        copy(&mut response, &mut dest)?;
        // The archive function
        let mut response = reqwest::get(target)?;
        let mut archive = {
            let fname = response
                .url()
                .path_segments()
                .and_then(|segments| segments.last())
                .and_then(|name| if name.is_empty() { None } else { Some(name) })
                .unwrap_or("tmp.bin");
            let fname = format!("{}/{}", archive_dir, fname);
            File::create(fname)?
        };
        copy(&mut response, &mut archive)?;
        info!("Downloaded {}", title);
        Ok(1)
    }
}
fn downloader ( target : & str , title : & str ) -> Result < u8 > { // Get the download dir from the Settings.toml file let dl_dir = settings :: get_settings ( & String :: from ( " " ) ) . unwrap ( ) ; let archive_dir = settings :: get_settings ( & String :: from ( " " ) ) . unwrap ( ) ; // Check if the download/archive location exists if ! Path :: new ( & dl_dir ) . exists ( ) { std :: fs :: create_dir_all ( Path :: new ( & dl_dir ) ) . expect ( " " ) ; } if ! Path :: new ( & archive_dir ) . exists ( ) { std :: fs :: create_dir_all ( Path :: new ( & archive_dir ) ) . expect ( " " ) ; } let check = archive_check ( & target , & archive_dir ) ; if check == " " { println ! ( " " ) ; Ok ( 0 ) } else { // Normal download location let mut response = reqwest :: get ( target ) ? ; let mut dest = { let fname = response . url ( ) . path_segments ( ) . and_then ( | segments | segments . last ( ) ) . and_then ( | name | if name . is_empty ( ) { None } else { Some ( name ) } ) . unwrap_or ( " " ) ; println ! ( " " fname ) ; let fname = format ! ( " " dl_dir fname ) ; println ! ( " " fname ) ; File :: create ( fname ) ? } ; copy ( & mut response , & mut dest ) ? ; // The archive function let mut response = reqwest :: get ( target ) ? ; let mut archive = { let fname = response . url ( ) . path_segments ( ) . and_then ( | segments | segments . last ( ) ) . and_then ( | name | if name . is_empty ( ) { None } else { Some ( name ) } ) . unwrap_or ( " " ) ; let fname = format ! ( " " archive_dir fname ) ; File :: create ( fname ) ? } ; copy ( & mut response , & mut archive ) ? ; info ! ( " " title ) ; Ok ( 1 ) } }
Function that takes in a link and downloads it to the specified path.
Function that takes in a link and downloads it to the specified path .
target
&str
title
&str
target
&str
title
&str