Don't download media files if exist

This commit is contained in:
Daniel García Moreno 2017-08-27 17:54:00 +02:00
parent 61295100ee
commit 834dd48444

View file

@ -14,6 +14,7 @@ use self::serde_json::Value as JsonValue;
use std::collections::HashMap;
use self::url::Url;
use std::io::Read;
use std::path::Path;
use std::fs::File;
use std::io::prelude::*;
@ -214,6 +215,12 @@ pub fn dw_media(base: &Url, url: &str, thumb: bool, dest: Option<&str>, w: i32,
Some(d) => String::from(d) + &media
};
let pathname = fname.clone();
let p = Path::new(&pathname);
if p.is_file() {
return Ok(fname);
}
let mut file = File::create(&fname)?;
let buffer = get_media(url.as_str())?;
file.write_all(&buffer)?;