mirror of
https://github.com/FliegendeWurst/KIT-ILIAS-downloader.git
synced 2024-08-28 04:04:18 +00:00
Fix video downloading
Load the full lecture list differently (should work for every course now) Actually download new videos
This commit is contained in:
parent
3b31b08246
commit
449d642bf5
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2,7 +2,7 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "KIT-ILIAS-downloader"
|
name = "KIT-ILIAS-downloader"
|
||||||
version = "0.2.7"
|
version = "0.2.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "KIT-ILIAS-downloader"
|
name = "KIT-ILIAS-downloader"
|
||||||
version = "0.2.7"
|
version = "0.2.8"
|
||||||
authors = ["FliegendeWurst <2012gdwu@web.de>"]
|
authors = ["FliegendeWurst <2012gdwu@web.de>"]
|
||||||
license = "GPL-2.0"
|
license = "GPL-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
35
src/main.rs
35
src/main.rs
@ -227,10 +227,34 @@ fn process(ilias: Arc<ILIAS>, mut path: PathBuf, obj: Object) -> impl Future<Out
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
create_dir(&path).await?;
|
create_dir(&path).await?;
|
||||||
let list_url = format!("{}ilias.php?ref_id={}&cmdClass=xocteventgui&cmdNode=n7:mz:14p&baseClass=ilObjPluginDispatchGUI&lang=de&limit=800&cmd=asyncGetTableGUI&cmdMode=asynch", ILIAS_URL, url.ref_id);
|
let full_url = {
|
||||||
|
// first find the link to full video list
|
||||||
|
let list_url = format!("{}ilias.php?ref_id={}&cmdClass=xocteventgui&cmdNode=n7:mz:14p&baseClass=ilObjPluginDispatchGUI&lang=de&limit=20&cmd=asyncGetTableGUI&cmdMode=asynch", ILIAS_URL, url.ref_id);
|
||||||
|
log!(1, "Loading {}", list_url);
|
||||||
let data = ilias.download(&list_url).await?;
|
let data = ilias.download(&list_url).await?;
|
||||||
let html = data.text().await?;
|
let html = data.text().await?;
|
||||||
let html = Html::parse_fragment(&html);
|
let html = Html::parse_fragment(&html);
|
||||||
|
html.select(&a)
|
||||||
|
.filter_map(|link| link.value().attr("href"))
|
||||||
|
.filter(|href| href.contains("trows=800"))
|
||||||
|
.map(|x| x.to_string()).next().ok_or(anyhow!("video list link not found"))?
|
||||||
|
};
|
||||||
|
log!(1, "Rewriting {}", full_url);
|
||||||
|
let mut full_url = Url::parse(&format!("{}{}", ILIAS_URL, full_url))?;
|
||||||
|
let mut query_parameters = full_url.query_pairs().map(|(x,y)| (x.into_owned(), y.into_owned())).collect::<Vec<_>>();
|
||||||
|
for (key, value) in &mut query_parameters {
|
||||||
|
match &**key {
|
||||||
|
"cmd" => *value = "asyncGetTableGUI".into(),
|
||||||
|
"cmdClass" => *value = "xocteventgui".into(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query_parameters.push(("cmdMode".into(), "asynch".into()));
|
||||||
|
full_url.query_pairs_mut().clear().extend_pairs(&query_parameters).finish();
|
||||||
|
log!(1, "Loading {}", full_url);
|
||||||
|
let data = ilias.download(&full_url.into_string()).await?;
|
||||||
|
let html = data.text().await?;
|
||||||
|
let html = Html::parse_fragment(&html);
|
||||||
for row in html.select(&video_tr) {
|
for row in html.select(&video_tr) {
|
||||||
let link = row.select(&a_target_blank).next();
|
let link = row.select(&a_target_blank).next();
|
||||||
if link.is_none() {
|
if link.is_none() {
|
||||||
@ -286,17 +310,14 @@ 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 !ilias.opt.force {
|
let meta = fs::metadata(&path).await;
|
||||||
if let Ok(meta) = fs::metadata(&path).await {
|
if !ilias.opt.force && meta.is_ok() && ilias.opt.check_videos {
|
||||||
if ilias.opt.check_videos {
|
|
||||||
let head = ilias.client.head(url).send().await.context("HEAD request failed")?;
|
let head = ilias.client.head(url).send().await.context("HEAD request failed")?;
|
||||||
if let Some(len) = head.headers().get("content-length") {
|
if let Some(len) = head.headers().get("content-length") {
|
||||||
if meta.len() != len.to_str()?.parse::<u64>()? {
|
if meta.unwrap().len() != len.to_str()?.parse::<u64>()? {
|
||||||
log!(0, "Warning: {} was updated, consider moving the outdated file", relative_path.to_string_lossy());
|
log!(0, "Warning: {} was updated, consider moving the outdated file", relative_path.to_string_lossy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let resp = ilias.download(&url).await?;
|
let resp = ilias.download(&url).await?;
|
||||||
let mut reader = stream_reader(resp.bytes_stream().map_err(|x| {
|
let mut reader = stream_reader(resp.bytes_stream().map_err(|x| {
|
||||||
|
Loading…
Reference in New Issue
Block a user