Reformat code according to new RFC style
This commit is contained in:
@@ -32,10 +32,11 @@ impl Presentation {
|
||||
}
|
||||
|
||||
pub(crate) fn download(&self, out_dir: &Path) -> Result<(), DownloadError> {
|
||||
fn download_to_file_and_check<F: Fn(&Path) -> bool>(response: &mut Response,
|
||||
out_file: &Path,
|
||||
check: F)
|
||||
-> Result<(), io::Error> {
|
||||
fn download_to_file_and_check<F: Fn(&Path) -> bool>(
|
||||
response: &mut Response,
|
||||
out_file: &Path,
|
||||
check: F,
|
||||
) -> Result<(), io::Error> {
|
||||
println!("Output file: {}", out_file.display());
|
||||
if out_file.exists() {
|
||||
println!("File is present already. Checking validity...");
|
||||
@@ -56,14 +57,10 @@ impl Presentation {
|
||||
|
||||
match *self {
|
||||
Presentation::PublishToGo { ref download_url, .. } => {
|
||||
let mut response = try_to_get_valid_response(|client| {
|
||||
client
|
||||
.get(download_url)
|
||||
.header(construct_cookie())
|
||||
},
|
||||
|resp| {
|
||||
resp.headers().get::<ContentDisposition>().is_some()
|
||||
});
|
||||
let mut response = try_to_get_valid_response(
|
||||
|client| client.get(download_url).header(construct_cookie()),
|
||||
|resp| resp.headers().get::<ContentDisposition>().is_some(),
|
||||
);
|
||||
|
||||
let filename = {
|
||||
let content_disposition =
|
||||
@@ -74,8 +71,10 @@ impl Presentation {
|
||||
match *param {
|
||||
DispositionParam::Filename(ref charset, _, ref vec) => {
|
||||
assert_eq!(&Charset::Ext("UTF-8".to_string()), charset);
|
||||
name = Some(String::from_utf8(vec.to_vec())
|
||||
.expect("Suggested filename isn't valid UTF-8!",));
|
||||
name = Some(
|
||||
String::from_utf8(vec.to_vec())
|
||||
.expect("Suggested filename isn't valid UTF-8!")
|
||||
);
|
||||
}
|
||||
_ => continue,
|
||||
}
|
||||
@@ -95,22 +94,26 @@ impl Presentation {
|
||||
..
|
||||
} => {
|
||||
let videos = {
|
||||
let payload = format!("{{\"getPlayerOptionsRequest\":{{\
|
||||
let payload = format!(
|
||||
"{{\"getPlayerOptionsRequest\":{{\
|
||||
\"ResourceId\":\"{}\",\
|
||||
\"QueryString\":\"{}\"\
|
||||
}}}}",
|
||||
resource_id,
|
||||
query_string);
|
||||
resource_id,
|
||||
query_string
|
||||
);
|
||||
|
||||
let url = "https://streams.tum.de/Mediasite/PlayerService/\
|
||||
PlayerService.svc/json/GetPlayerOptions";
|
||||
let mut res = try_to_get_response(|client| {
|
||||
client
|
||||
.post(url)
|
||||
.header(construct_cookie())
|
||||
.header(ContentType::json())
|
||||
.body(&*payload)
|
||||
});
|
||||
let mut res = try_to_get_response(
|
||||
|client| {
|
||||
client
|
||||
.post(url)
|
||||
.header(construct_cookie())
|
||||
.header(ContentType::json())
|
||||
.body(&*payload)
|
||||
}
|
||||
);
|
||||
|
||||
let json_text = read_response_body(&mut res);
|
||||
if json_text.contains("You are not authorized to view the requested content") {
|
||||
@@ -127,13 +130,11 @@ impl Presentation {
|
||||
vec
|
||||
};
|
||||
for (i, download_url) in videos.iter().enumerate() {
|
||||
let mut response = try_to_get_valid_response(|client| {
|
||||
client.get(download_url).header(construct_cookie())
|
||||
},
|
||||
|resp| {
|
||||
resp.status() ==
|
||||
&StatusCode::Ok
|
||||
});
|
||||
let mut response =
|
||||
try_to_get_valid_response(
|
||||
|client| client.get(download_url).header(construct_cookie()),
|
||||
|resp| resp.status() == &StatusCode::Ok,
|
||||
);
|
||||
// TODO: Support formats besides mp4
|
||||
// extract extension from url or somewehre else...
|
||||
let filename = format!("{} - {}.mp4", fix_filename(self.name()), i + 1);
|
||||
@@ -211,9 +212,11 @@ fn download_to_file(response: &mut Response, path: &Path) -> Result<(), io::Erro
|
||||
|
||||
let now = Instant::now();
|
||||
if now - last > Duration::from_millis(update_duration_millis) {
|
||||
print!("{:.*} kB/s \r",
|
||||
2,
|
||||
done as f64 * 1000.0 / update_duration_millis as f64 / 1024.0);
|
||||
print!(
|
||||
"{:.*} kB/s \r",
|
||||
2,
|
||||
done as f64 * 1000.0 / update_duration_millis as f64 / 1024.0
|
||||
);
|
||||
::std::io::stdout()
|
||||
.flush()
|
||||
.expect("Failed flushing the terminal!");
|
||||
@@ -261,9 +264,11 @@ fn check_video(path: &Path) -> bool {
|
||||
match command {
|
||||
Ok(output) => output.stderr.is_empty(),
|
||||
Err(_) => {
|
||||
println!("Failed to check {} with ffmpeg. Perhaps ffmpeg isn't in your path. \
|
||||
println!(
|
||||
"Failed to check {} with ffmpeg. Perhaps ffmpeg isn't in your path. \
|
||||
Skipping check...",
|
||||
path.display());
|
||||
path.display()
|
||||
);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user