mirror of
https://github.com/FliegendeWurst/KIT-ILIAS-downloader.git
synced 2024-08-28 04:04:18 +00:00
Fix clippy hints
* https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if (-D clippy::collapsible-else-if) * https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow (-D clippy::needless-borrow) * https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref (-D clippy::into-iter-on-ref) * https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten (-D clippy::map-flatten) * https://rust-lang.github.io/rust-clippy/master/index.html#len_zero (-D clippy::len-zero)
This commit is contained in:
parent
05abc5bdad
commit
3f326713ba
15
src/ilias.rs
15
src/ilias.rs
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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| {
|
||||
|
Loading…
Reference in New Issue
Block a user