Reformat code
This commit is contained in:
@@ -4,10 +4,16 @@ pub type Login<'a> = Option<(&'a str, &'a str)>;
|
|||||||
|
|
||||||
pub static ALIASES: &[(&str, CatalogDefinition)] = &[
|
pub static ALIASES: &[(&str, CatalogDefinition)] = &[
|
||||||
("DS_WS1617", ("16w-diskrete-strukturen", None)),
|
("DS_WS1617", ("16w-diskrete-strukturen", None)),
|
||||||
("EIDI_WS1617", ("eidi1-2016", Some(("eidi-2016", "PGdP.16")))),
|
(
|
||||||
|
"EIDI_WS1617",
|
||||||
|
("eidi1-2016", Some(("eidi-2016", "PGdP.16"))),
|
||||||
|
),
|
||||||
("ERA_WS1617", ("era-2016", None)),
|
("ERA_WS1617", ("era-2016", None)),
|
||||||
|
|
||||||
("GAD_SS17", ("17s-grundlagen-algorithmen-und-datenstrukturen", None)),
|
(
|
||||||
|
"GAD_SS17",
|
||||||
|
("17s-grundlagen-algorithmen-und-datenstrukturen", None),
|
||||||
|
),
|
||||||
("LA_SS17", ("17s-lineare-algebra-fuer-informatik", None)),
|
("LA_SS17", ("17s-lineare-algebra-fuer-informatik", None)),
|
||||||
// EIST is on a Nextcloud
|
// EIST is on a Nextcloud
|
||||||
];
|
];
|
||||||
|
25
src/main.rs
25
src/main.rs
@@ -144,10 +144,12 @@ fn get_auth() {
|
|||||||
|
|
||||||
let res = try_to_get_valid_response(
|
let res = try_to_get_valid_response(
|
||||||
|client| {
|
|client| {
|
||||||
let mut request_builder = client.post("https://streams.tum.de/Mediasite/Login").unwrap();
|
let mut request_builder = client
|
||||||
request_builder.form(
|
.post("https://streams.tum.de/Mediasite/Login")
|
||||||
&form_data,
|
.unwrap();
|
||||||
).expect("Failed to serialize form_data!");
|
request_builder
|
||||||
|
.form(&form_data)
|
||||||
|
.expect("Failed to serialize form_data!");
|
||||||
request_builder
|
request_builder
|
||||||
},
|
},
|
||||||
|res| res.headers().get::<SetCookie>().is_some(),
|
|res| res.headers().get::<SetCookie>().is_some(),
|
||||||
@@ -251,9 +253,12 @@ fn get_json(catalog_id: &str) -> String {
|
|||||||
let mut request_builder = client
|
let mut request_builder = client
|
||||||
.post(
|
.post(
|
||||||
"https://streams.tum.de/Mediasite/Catalog/Data/GetPresentationsForFolder",
|
"https://streams.tum.de/Mediasite/Catalog/Data/GetPresentationsForFolder",
|
||||||
).unwrap();
|
)
|
||||||
request_builder.header(construct_cookie())
|
.unwrap();
|
||||||
.json(&data).expect("Failed to serialize json!");
|
request_builder
|
||||||
|
.header(construct_cookie())
|
||||||
|
.json(&data)
|
||||||
|
.expect("Failed to serialize json!");
|
||||||
request_builder
|
request_builder
|
||||||
});
|
});
|
||||||
read_response_body(&mut res)
|
read_response_body(&mut res)
|
||||||
@@ -302,8 +307,8 @@ where
|
|||||||
|
|
||||||
fn read_response_body(response: &mut Response) -> String {
|
fn read_response_body(response: &mut Response) -> String {
|
||||||
let mut string = String::new();
|
let mut string = String::new();
|
||||||
response.read_to_string(&mut string).expect(
|
response
|
||||||
"Failed to read body",
|
.read_to_string(&mut string)
|
||||||
);
|
.expect("Failed to read body");
|
||||||
string
|
string
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,9 @@ impl Presentation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Presentation::PublishToGo { ref download_url, .. } => {
|
Presentation::PublishToGo {
|
||||||
|
ref download_url, ..
|
||||||
|
} => {
|
||||||
let response_res = try_to_get_valid_response(
|
let response_res = try_to_get_valid_response(
|
||||||
|client| {
|
|client| {
|
||||||
let mut request_builder = client.get(download_url).unwrap();
|
let mut request_builder = client.get(download_url).unwrap();
|
||||||
@@ -82,9 +84,10 @@ impl Presentation {
|
|||||||
match *param {
|
match *param {
|
||||||
DispositionParam::Filename(ref charset, _, ref vec) => {
|
DispositionParam::Filename(ref charset, _, ref vec) => {
|
||||||
assert_eq!(&Charset::Ext("UTF-8".to_string()), charset);
|
assert_eq!(&Charset::Ext("UTF-8".to_string()), charset);
|
||||||
name = Some(String::from_utf8(vec.to_vec()).expect(
|
name = Some(
|
||||||
"Suggested filename isn't valid UTF-8!",
|
String::from_utf8(vec.to_vec())
|
||||||
));
|
.expect("Suggested filename isn't valid UTF-8!"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
@@ -117,7 +120,8 @@ impl Presentation {
|
|||||||
PlayerService.svc/json/GetPlayerOptions";
|
PlayerService.svc/json/GetPlayerOptions";
|
||||||
let mut res = try_to_get_response(|client| {
|
let mut res = try_to_get_response(|client| {
|
||||||
let mut request_builder = client.post(url).unwrap();
|
let mut request_builder = client.post(url).unwrap();
|
||||||
request_builder.header(construct_cookie())
|
request_builder
|
||||||
|
.header(construct_cookie())
|
||||||
.header(ContentType::json())
|
.header(ContentType::json())
|
||||||
.body(payload.to_string());
|
.body(payload.to_string());
|
||||||
request_builder
|
request_builder
|
||||||
@@ -170,9 +174,10 @@ impl<'a> From<&'a JsonValue> for Presentation {
|
|||||||
if json["DownloadUrls"].len() >= 1 {
|
if json["DownloadUrls"].len() >= 1 {
|
||||||
assert_eq!(json["DownloadUrls"].len(), 1);
|
assert_eq!(json["DownloadUrls"].len(), 1);
|
||||||
Presentation::PublishToGo {
|
Presentation::PublishToGo {
|
||||||
name: json["Name"].clone().take_string().expect(
|
name: json["Name"]
|
||||||
"json: Presentation didn't contain a \"Name\"!",
|
.clone()
|
||||||
),
|
.take_string()
|
||||||
|
.expect("json: Presentation didn't contain a \"Name\"!"),
|
||||||
download_url: json["DownloadUrls"][0]["Url"]
|
download_url: json["DownloadUrls"][0]["Url"]
|
||||||
.clone()
|
.clone()
|
||||||
.take_string()
|
.take_string()
|
||||||
@@ -187,9 +192,10 @@ impl<'a> From<&'a JsonValue> for Presentation {
|
|||||||
let index_start_resource = index - "cdf23465581b45aa92d588ebd59619d91d".len();
|
let index_start_resource = index - "cdf23465581b45aa92d588ebd59619d91d".len();
|
||||||
|
|
||||||
Presentation::VideoOnDemand {
|
Presentation::VideoOnDemand {
|
||||||
name: json["Name"].clone().take_string().expect(
|
name: json["Name"]
|
||||||
"json: Presentation didn't contain a \"Name\"!",
|
.clone()
|
||||||
),
|
.take_string()
|
||||||
|
.expect("json: Presentation didn't contain a \"Name\"!"),
|
||||||
query_string: player_url[index..index_end_query].to_string(),
|
query_string: player_url[index..index_end_query].to_string(),
|
||||||
resource_id: player_url[index_start_resource..index].to_string(),
|
resource_id: player_url[index_start_resource..index].to_string(),
|
||||||
}
|
}
|
||||||
@@ -215,9 +221,8 @@ fn download_to_file(response: &mut Response, path: &Path) -> Result<(), io::Erro
|
|||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
};
|
};
|
||||||
|
|
||||||
file.write_all(&buf[0..len]).expect(
|
file.write_all(&buf[0..len])
|
||||||
"Failed writing into the file!",
|
.expect("Failed writing into the file!");
|
||||||
);
|
|
||||||
done += len;
|
done += len;
|
||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
@@ -227,9 +232,9 @@ fn download_to_file(response: &mut Response, path: &Path) -> Result<(), io::Erro
|
|||||||
2,
|
2,
|
||||||
done as f64 * 1000.0 / update_duration_millis as f64 / 1024.0
|
done as f64 * 1000.0 / update_duration_millis as f64 / 1024.0
|
||||||
);
|
);
|
||||||
::std::io::stdout().flush().expect(
|
::std::io::stdout()
|
||||||
"Failed flushing the terminal!",
|
.flush()
|
||||||
);
|
.expect("Failed flushing the terminal!");
|
||||||
last = now;
|
last = now;
|
||||||
done = 0;
|
done = 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user