Update deps with breaking changes

This commit is contained in:
2017-07-20 03:53:08 +02:00
parent bf71909c72
commit 2659093897
4 changed files with 287 additions and 74 deletions

View File

@@ -17,7 +17,7 @@ use std::path::Path;
use std::sync::Mutex;
use clap::{App, Arg};
use reqwest::{Client, Response, RedirectPolicy, RequestBuilder};
use reqwest::{Client, ClientBuilder, Response, RedirectPolicy, RequestBuilder};
use reqwest::header::{Cookie, SetCookie};
use catalog::*;
@@ -30,12 +30,12 @@ use presentation::Presentation;
const MAX_RETRIES: u8 = 10;
lazy_static! {
static ref CLIENT: Client = {
let mut client = Client::new().expect("Failed to create Client!");
static ref CLIENT: Client = ClientBuilder::new()
.expect("Failed to create ClientBuilder!")
// The login site redirects to itself if no redirect parameter is given
client.redirect(RedirectPolicy::none());
client
};
.redirect(RedirectPolicy::none())
.build()
.expect("Failed to create Client!");
static ref USERNAME: Mutex<String> = Mutex::new(String::new());
static ref PASSWORD: Mutex<String> = Mutex::new(String::new());
@@ -144,9 +144,11 @@ fn get_auth() {
let res = try_to_get_valid_response(
|client| {
client.post("https://streams.tum.de/Mediasite/Login").form(
let mut request_builder = client.post("https://streams.tum.de/Mediasite/Login").unwrap();
request_builder.form(
&form_data,
)
).expect("Failed to serialize form_data!");
request_builder
},
|res| res.headers().get::<SetCookie>().is_some(),
).expect(
@@ -206,7 +208,11 @@ fn get_catalog_id(name: &str) -> String {
println!("Fetching catalog id!");
let url = format!("https://streams.tum.de/Mediasite/Catalog/catalogs/{}", name);
let mut res = try_to_get_response(|client| client.get(&url).header(construct_cookie()));
let mut res = try_to_get_response(|client| {
let mut request_builder = client.get(&url).unwrap();
request_builder.header(construct_cookie());
request_builder
});
let body = read_response_body(&mut res);
let prefix = "CatalogId: '";
@@ -242,18 +248,21 @@ fn get_json(catalog_id: &str) -> String {
data.insert("ItemsPerPage", "500");
let mut res = try_to_get_response(|client| {
client
let mut request_builder = client
.post(
"https://streams.tum.de/Mediasite/Catalog/Data/GetPresentationsForFolder",
)
.header(construct_cookie())
.json(&data)
).unwrap();
request_builder.header(construct_cookie())
.json(&data).expect("Failed to serialize json!");
request_builder
});
read_response_body(&mut res)
}
fn construct_cookie() -> Cookie {
Cookie(vec![format!("MediasiteAuth={}", *AUTH.lock().unwrap())])
let mut cookie = Cookie::new();
cookie.append("MediasiteAuth", (*AUTH.lock().unwrap()).to_string());
cookie
}
fn try_to_get_response<F>(f: F) -> Response

View File

@@ -58,7 +58,11 @@ impl Presentation {
match *self {
Presentation::PublishToGo { ref download_url, .. } => {
let response_res = try_to_get_valid_response(
|client| client.get(download_url).header(construct_cookie()),
|client| {
let mut request_builder = client.get(download_url).unwrap();
request_builder.header(construct_cookie());
request_builder
},
|resp| resp.headers().get::<ContentDisposition>().is_some(),
);
@@ -92,7 +96,7 @@ impl Presentation {
path.push(fix_filename(&filename));
download_to_file_and_check(&mut response, &path, |path| check_zip(path))
.map_err(|e| DownloadError::IoError(e))
.map_err(DownloadError::IoError)
}
Presentation::VideoOnDemand {
ref resource_id,
@@ -112,11 +116,11 @@ impl Presentation {
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 request_builder = client.post(url).unwrap();
request_builder.header(construct_cookie())
.header(ContentType::json())
.body(payload.to_string());
request_builder
});
let json_text = read_response_body(&mut res);
@@ -135,8 +139,12 @@ impl Presentation {
};
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,
|client| {
let mut request_builder = client.get(download_url).unwrap();
request_builder.header(construct_cookie());
request_builder
},
|resp| resp.status() == StatusCode::Ok,
).unwrap();
// TODO: Support formats besides mp4
// extract extension from url or somewehre else...
@@ -149,7 +157,7 @@ impl Presentation {
path.push(fix_filename(&filename));
download_to_file_and_check(&mut response, &path, |path| check_video(path))
.map_err(|e| DownloadError::IoError(e))?;
.map_err(DownloadError::IoError)?;
}
Ok(())
}