Maximilian Bosch 2023-07-09 11:48:06 +02:00
parent 05abc5bdad
commit 3f326713ba
No known key found for this signature in database
GPG Key ID: 9A6EEA275CA5BE0A
7 changed files with 48 additions and 53 deletions

View File

@ -45,12 +45,9 @@ pub struct ILIAS {
fn error_is_http2(error: &reqwest::Error) -> bool {
error
.source() // hyper::Error
.map(|x| x.source()) // h2::Error
.flatten()
.map(|x| x.downcast_ref::<h2::Error>())
.flatten()
.map(|x| x.reason())
.flatten()
.and_then(|x| x.source()) // h2::Error
.and_then(|x| x.downcast_ref::<h2::Error>())
.and_then(|x| x.reason())
.map(|x| x == h2::Reason::NO_ERROR)
.unwrap_or(false)
}
@ -349,8 +346,8 @@ impl Object {
| Presentation { name, .. }
| ExerciseHandler { name, .. }
| PluginDispatch { name, .. }
| Generic { name, .. } => &name,
Thread { url } => &url.thr_pk.as_ref().unwrap(),
| Generic { name, .. } => name,
Thread { url } => url.thr_pk.as_ref().unwrap(),
Video { url } => &url.url,
Dashboard { url } => &url.url,
}
@ -371,7 +368,7 @@ impl Object {
| ExerciseHandler { url, .. }
| PluginDispatch { url, .. }
| Video { url }
| Generic { url, .. } => &url,
| Generic { url, .. } => url,
}
}

View File

@ -28,12 +28,12 @@ pub async fn download(path: PathBuf, ilias: Arc<ILIAS>, url: &URL, name: &str) -
return Ok(()); // ignore groups we are not in
}
warning!(name, "falling back to incomplete course content extractor!", e);
let (items, main_text, _) = ilias.get_course_content(&url).await?;
let (items, main_text, _) = ilias.get_course_content(url).await?;
(items, main_text)
},
}
} else {
let (items, main_text, _) = ilias.get_course_content(&url).await?;
let (items, main_text, _) = ilias.get_course_content(url).await?;
(items, main_text)
};
if ilias.opt.save_ilias_pages {

View File

@ -17,6 +17,6 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc<ILIAS>, url:
}
let data = ilias.download(&url.url).await?;
log!(0, "Writing {}", relative_path.to_string_lossy());
write_stream_to_file(&path, data.bytes_stream()).await?;
write_stream_to_file(path, data.bytes_stream()).await?;
Ok(())
}

View File

@ -17,7 +17,7 @@ static EXPAND_LINK: Lazy<Regex> = Lazy::new(|| Regex::new("expand=\\d").unwrap()
#[async_recursion]
pub async fn download(path: &Path, ilias: Arc<ILIAS>, url: &URL) -> Result<()> {
let content = ilias.get_course_content(&url).await?;
let content = ilias.get_course_content(url).await?;
// expand all sessions
for href in content.2 {

View File

@ -34,7 +34,7 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc<ILIAS>, url:
let json = &json_capture.next().context("xoct player json not found")?[1];
log!(2, "{}", json);
let json = json.split(",\n").next().context("invalid xoct player json")?;
serde_json::from_str(&json.trim())?
serde_json::from_str(json.trim())?
};
log!(2, "{}", json);
let streams = json
@ -49,52 +49,50 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc<ILIAS>, url:
.as_str()
.context("video src not string")?;
download_to_path(&ilias, path, relative_path, url).await?;
} else if !ilias.opt.combine_videos {
fs::create_dir(path).await.context("failed to create video directory")?;
download_all(path, streams, ilias, relative_path).await?;
} else {
if !ilias.opt.combine_videos {
fs::create_dir(path).await.context("failed to create video directory")?;
download_all(path, streams, ilias, relative_path).await?;
} else {
let dir = tempdir()?;
// construct ffmpeg command to combine all files
let mut arguments = vec![];
for file in download_all(dir.path(), streams, ilias, relative_path).await? {
arguments.push("-i".to_owned());
arguments.push(file.to_str().context("invalid UTF8")?.into());
}
arguments.push("-c".into());
arguments.push("copy".into());
for i in 0..(arguments.len() / 2) - 1 {
arguments.push("-map".into());
arguments.push(format!("{}", i));
}
arguments.push(path.to_str().context("invalid UTF8 in path")?.into());
let status = Command::new("ffmpeg")
.args(&arguments)
.stderr(Stdio::null())
.stdout(Stdio::null())
.spawn()
.context("failed to start ffmpeg")?
.wait()
.await
.context("failed to wait for ffmpeg")?;
if !status.success() {
error!(format!("ffmpeg failed to merge video files into {}", path.display()));
error!(format!("check this directory: {}", dir.into_path().display()));
error!(format!("ffmpeg command: {}", arguments.join(" ")));
}
};
let dir = tempdir()?;
// construct ffmpeg command to combine all files
let mut arguments = vec![];
for file in download_all(dir.path(), streams, ilias, relative_path).await? {
arguments.push("-i".to_owned());
arguments.push(file.to_str().context("invalid UTF8")?.into());
}
arguments.push("-c".into());
arguments.push("copy".into());
for i in 0..(arguments.len() / 2) - 1 {
arguments.push("-map".into());
arguments.push(format!("{}", i));
}
arguments.push(path.to_str().context("invalid UTF8 in path")?.into());
let status = Command::new("ffmpeg")
.args(&arguments)
.stderr(Stdio::null())
.stdout(Stdio::null())
.spawn()
.context("failed to start ffmpeg")?
.wait()
.await
.context("failed to wait for ffmpeg")?;
if !status.success() {
error!(format!("ffmpeg failed to merge video files into {}", path.display()));
error!(format!("check this directory: {}", dir.into_path().display()));
error!(format!("ffmpeg command: {}", arguments.join(" ")));
}
}
Ok(())
}
async fn download_all(
path: &Path,
streams: &Vec<serde_json::Value>,
streams: &[serde_json::Value],
ilias: Arc<ILIAS>,
relative_path: &Path,
) -> Result<Vec<PathBuf>> {
let mut paths = Vec::new();
for (i, stream) in streams.into_iter().enumerate() {
for (i, stream) in streams.iter().enumerate() {
let url = stream
.pointer("/sources/mp4/0/src")
.context("video src not found")?
@ -126,9 +124,9 @@ async fn download_to_path(ilias: &ILIAS, path: &Path, relative_path: &Path, url:
}
}
} else {
let resp = ilias.download(&url).await?;
let resp = ilias.download(url).await?;
log!(0, "Writing {}", relative_path.to_string_lossy());
write_stream_to_file(&path, resp.bytes_stream()).await?;
write_stream_to_file(path, resp.bytes_stream()).await?;
}
Ok(())
}

View File

@ -27,7 +27,7 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc<ILIAS>, url:
if url.starts_with(ILIAS_URL) {
// is a link list
if fs::metadata(&path).await.is_err() {
create_dir(&path).await?;
create_dir(path).await?;
log!(0, "Writing {}", relative_path.to_string_lossy());
}

View File

@ -24,7 +24,7 @@ impl IliasIgnore {
if let Some(err) = error {
warning!(err);
}
if ignore.len() > 0 {
if !ignore.is_empty() {
ignores.push(IgnoreFile {
ignore,
prefix: prefix.iter().fold(OsString::new(), |mut acc, el| {