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 { if ilias.opt.no_videos {
return Ok(()); 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 url = format!("{}{}", ILIAS_URL, url.url);
let data = ilias.download(&url); let data = ilias.download(&url);
let html = data.await?.text().await?; let html = data.await?.text().await?;
@ -276,26 +280,25 @@ fn process(ilias: Arc<ILIAS>, mut path: PathBuf, obj: Object) -> impl Future<Out
.map(|x| x.as_str()) .map(|x| x.as_str())
.ok_or(anyhow!("video src not found"))? .ok_or(anyhow!("video src not found"))?
.ok_or(anyhow!("video src not string"))?; .ok_or(anyhow!("video src not string"))?;
if let Ok(meta) = fs::metadata(&path).await { if !ilias.opt.force {
if ilias.opt.check_videos { if let Ok(meta) = fs::metadata(&path).await {
let head = ilias.client.head(url).send().await.context("HEAD request failed")?; if ilias.opt.check_videos {
if let Some(len) = head.headers().get("content-length") { let head = ilias.client.head(url).send().await.context("HEAD request failed")?;
if meta.len() != len.to_str()?.parse::<u64>()? { if let Some(len) = head.headers().get("content-length") {
log!(0, "Warning: {} was updated, consider moving the outdated file", relative_path.to_string_lossy()); if meta.len() != len.to_str()?.parse::<u64>()? {
log!(0, "Warning: {} was updated, consider moving the outdated file", relative_path.to_string_lossy());
}
} }
} }
} }
log!(2, "Skipping download, file exists already"); } else {
if !ilias.opt.force { let resp = ilias.download(&url).await?;
return Ok(()); 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")?;
} }
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, .. } => { Forum { url, .. } => {
if !ilias.opt.forum { if !ilias.opt.forum {