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 {
|
fn error_is_http2(error: &reqwest::Error) -> bool {
|
||||||
error
|
error
|
||||||
.source() // hyper::Error
|
.source() // hyper::Error
|
||||||
.map(|x| x.source()) // h2::Error
|
.and_then(|x| x.source()) // h2::Error
|
||||||
.flatten()
|
.and_then(|x| x.downcast_ref::<h2::Error>())
|
||||||
.map(|x| x.downcast_ref::<h2::Error>())
|
.and_then(|x| x.reason())
|
||||||
.flatten()
|
|
||||||
.map(|x| x.reason())
|
|
||||||
.flatten()
|
|
||||||
.map(|x| x == h2::Reason::NO_ERROR)
|
.map(|x| x == h2::Reason::NO_ERROR)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
@ -349,8 +346,8 @@ impl Object {
|
|||||||
| Presentation { name, .. }
|
| Presentation { name, .. }
|
||||||
| ExerciseHandler { name, .. }
|
| ExerciseHandler { name, .. }
|
||||||
| PluginDispatch { name, .. }
|
| PluginDispatch { name, .. }
|
||||||
| Generic { name, .. } => &name,
|
| Generic { name, .. } => name,
|
||||||
Thread { url } => &url.thr_pk.as_ref().unwrap(),
|
Thread { url } => url.thr_pk.as_ref().unwrap(),
|
||||||
Video { url } => &url.url,
|
Video { url } => &url.url,
|
||||||
Dashboard { url } => &url.url,
|
Dashboard { url } => &url.url,
|
||||||
}
|
}
|
||||||
@ -371,7 +368,7 @@ impl Object {
|
|||||||
| ExerciseHandler { url, .. }
|
| ExerciseHandler { url, .. }
|
||||||
| PluginDispatch { url, .. }
|
| PluginDispatch { url, .. }
|
||||||
| Video { 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
|
return Ok(()); // ignore groups we are not in
|
||||||
}
|
}
|
||||||
warning!(name, "falling back to incomplete course content extractor!", e);
|
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)
|
(items, main_text)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let (items, main_text, _) = ilias.get_course_content(&url).await?;
|
let (items, main_text, _) = ilias.get_course_content(url).await?;
|
||||||
(items, main_text)
|
(items, main_text)
|
||||||
};
|
};
|
||||||
if ilias.opt.save_ilias_pages {
|
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?;
|
let data = ilias.download(&url.url).await?;
|
||||||
log!(0, "Writing {}", relative_path.to_string_lossy());
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ static EXPAND_LINK: Lazy<Regex> = Lazy::new(|| Regex::new("expand=\\d").unwrap()
|
|||||||
|
|
||||||
#[async_recursion]
|
#[async_recursion]
|
||||||
pub async fn download(path: &Path, ilias: Arc<ILIAS>, url: &URL) -> Result<()> {
|
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
|
// expand all sessions
|
||||||
for href in content.2 {
|
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];
|
let json = &json_capture.next().context("xoct player json not found")?[1];
|
||||||
log!(2, "{}", json);
|
log!(2, "{}", json);
|
||||||
let json = json.split(",\n").next().context("invalid xoct player 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);
|
log!(2, "{}", json);
|
||||||
let streams = json
|
let streams = json
|
||||||
@ -49,8 +49,7 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc<ILIAS>, url:
|
|||||||
.as_str()
|
.as_str()
|
||||||
.context("video src not string")?;
|
.context("video src not string")?;
|
||||||
download_to_path(&ilias, path, relative_path, url).await?;
|
download_to_path(&ilias, path, relative_path, url).await?;
|
||||||
} else {
|
} else if !ilias.opt.combine_videos {
|
||||||
if !ilias.opt.combine_videos {
|
|
||||||
fs::create_dir(path).await.context("failed to create video directory")?;
|
fs::create_dir(path).await.context("failed to create video directory")?;
|
||||||
download_all(path, streams, ilias, relative_path).await?;
|
download_all(path, streams, ilias, relative_path).await?;
|
||||||
} else {
|
} else {
|
||||||
@ -82,19 +81,18 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc<ILIAS>, url:
|
|||||||
error!(format!("check this directory: {}", dir.into_path().display()));
|
error!(format!("check this directory: {}", dir.into_path().display()));
|
||||||
error!(format!("ffmpeg command: {}", arguments.join(" ")));
|
error!(format!("ffmpeg command: {}", arguments.join(" ")));
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn download_all(
|
async fn download_all(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
streams: &Vec<serde_json::Value>,
|
streams: &[serde_json::Value],
|
||||||
ilias: Arc<ILIAS>,
|
ilias: Arc<ILIAS>,
|
||||||
relative_path: &Path,
|
relative_path: &Path,
|
||||||
) -> Result<Vec<PathBuf>> {
|
) -> Result<Vec<PathBuf>> {
|
||||||
let mut paths = Vec::new();
|
let mut paths = Vec::new();
|
||||||
for (i, stream) in streams.into_iter().enumerate() {
|
for (i, stream) in streams.iter().enumerate() {
|
||||||
let url = stream
|
let url = stream
|
||||||
.pointer("/sources/mp4/0/src")
|
.pointer("/sources/mp4/0/src")
|
||||||
.context("video src not found")?
|
.context("video src not found")?
|
||||||
@ -126,9 +124,9 @@ async fn download_to_path(ilias: &ILIAS, path: &Path, relative_path: &Path, url:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let resp = ilias.download(&url).await?;
|
let resp = ilias.download(url).await?;
|
||||||
log!(0, "Writing {}", relative_path.to_string_lossy());
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc<ILIAS>, url:
|
|||||||
if url.starts_with(ILIAS_URL) {
|
if url.starts_with(ILIAS_URL) {
|
||||||
// is a link list
|
// is a link list
|
||||||
if fs::metadata(&path).await.is_err() {
|
if fs::metadata(&path).await.is_err() {
|
||||||
create_dir(&path).await?;
|
create_dir(path).await?;
|
||||||
log!(0, "Writing {}", relative_path.to_string_lossy());
|
log!(0, "Writing {}", relative_path.to_string_lossy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ impl IliasIgnore {
|
|||||||
if let Some(err) = error {
|
if let Some(err) = error {
|
||||||
warning!(err);
|
warning!(err);
|
||||||
}
|
}
|
||||||
if ignore.len() > 0 {
|
if !ignore.is_empty() {
|
||||||
ignores.push(IgnoreFile {
|
ignores.push(IgnoreFile {
|
||||||
ignore,
|
ignore,
|
||||||
prefix: prefix.iter().fold(OsString::new(), |mut acc, el| {
|
prefix: prefix.iter().fold(OsString::new(), |mut acc, el| {
|
||||||
|
Loading…
Reference in New Issue
Block a user