Update deps with breaking changes
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -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
|
||||
|
Reference in New Issue
Block a user