Only download video metadata if not downloaded yet

The user can still request metadata checks.
This commit is contained in:
FliegendeWurst 2020-07-13 09:29:49 +02:00
parent b3ad9f42c9
commit 1aa28f0d00

View File

@ -259,6 +259,10 @@ fn process(ilias: Arc<ILIAS>, mut path: PathBuf, obj: Object) -> impl Future<Out
if ilias.opt.no_videos {
return Ok(());
}
if fs::metadata(&path).await.is_ok() && !(ilias.opt.force || ilias.opt.check_videos) {
log!(2, "Skipping download, file exists already");
return Ok(());
}
let url = format!("{}{}", ILIAS_URL, url.url);
let data = ilias.download(&url);
let html = data.await?.text().await?;
@ -276,6 +280,7 @@ fn process(ilias: Arc<ILIAS>, mut path: PathBuf, obj: Object) -> impl Future<Out
.map(|x| x.as_str())
.ok_or(anyhow!("video src not found"))?
.ok_or(anyhow!("video src not string"))?;
if !ilias.opt.force {
if let Ok(meta) = fs::metadata(&path).await {
if ilias.opt.check_videos {
let head = ilias.client.head(url).send().await.context("HEAD request failed")?;
@ -285,17 +290,15 @@ fn process(ilias: Arc<ILIAS>, mut path: PathBuf, obj: Object) -> impl Future<Out
}
}
}
log!(2, "Skipping download, file exists already");
if !ilias.opt.force {
return Ok(());
}
}
} else {
let resp = ilias.download(&url).await?;
let mut reader = stream_reader(resp.bytes_stream().map_err(|x| {
io::Error::new(io::ErrorKind::Other, x)
}));
log!(0, "Writing {}", relative_path.to_string_lossy());
write_file_data(&path, &mut reader).await.context("failed to save video")?;
}
},
Forum { url, .. } => {
if !ilias.opt.forum {