Reformat...

This commit is contained in:
2017-06-07 04:19:42 +02:00
parent 63e4fd3b07
commit 07d77ab0f6
2 changed files with 57 additions and 57 deletions

View File

@@ -51,36 +51,42 @@ enum DownloadError {
fn main() {
let matches = App::new("TumMediasiteDownloader")
.author("Boris-Chengbiao Zhou <bobo1239@web.de>")
.about("Downloads \'catalogs\' from the TUM's Mediasite lecture archive.")
.about(
"Downloads \'catalogs\' from the TUM's Mediasite lecture archive.",
)
.arg(
Arg::with_name("CATALOG_NAME")
.help(
"name of the catalog e.g. from the URL:\n\
https://streams.tum.de/Mediasite/Catalog/catalogs/era-2016 -> era-2016\n\
special cases (WS16/17; login included): DS, EIDI, ERA, ..."
special cases (WS16/17; login included): DS, EIDI, ERA, ...",
)
.required(true)
.index(1)
.index(1),
)
.arg(
Arg::with_name("OUTPUT_DIRECTORY")
.help("where to output the downloaded files")
.required(true)
.index(2)
.index(2),
)
.arg(
Arg::with_name("username")
.short("u")
.help("username for login; can be omitted if the user from .env should be used")
.help(
"username for login; can be omitted if the user from .env should be used",
)
.requires("password")
.takes_value(true)
.takes_value(true),
)
.arg(
Arg::with_name("password")
.short("p")
.help("password for login; can be omitted if the user from .env should be used")
.help(
"password for login; can be omitted if the user from .env should be used",
)
.requires("username")
.takes_value(true)
.takes_value(true),
)
.get_matches();
@@ -153,8 +159,8 @@ fn get_auth() {
// }
let set_cookie: &SetCookie = res.headers().get().unwrap();
let cookie = cookie::Cookie::parse(set_cookie.0[0].to_string())
.expect("Failed to parse SetCookie");
let cookie =
cookie::Cookie::parse(set_cookie.0[0].to_string()).expect("Failed to parse SetCookie");
assert_eq!(cookie.name(), "MediasiteAuth");
let mut auth = AUTH.lock().unwrap();
@@ -202,11 +208,10 @@ fn get_catalog_id(name: &str) -> String {
let body = read_response_body(&mut res);
let prefix = "CatalogId: '";
let idx = body.find(prefix)
.expect(
"Failed to find CatalogId on the catalog page! Perhaps you got the wrong catalog \
name or an invalid login? Maybe you need to open the page in a browser once..."
);
let idx = body.find(prefix).expect(
"Failed to find CatalogId on the catalog page! Perhaps you got the wrong catalog \
name or an invalid login? Maybe you need to open the page in a browser once...",
);
let pre_len = prefix.len();
// Assuming all catalog ids follow this pattern!
let len = "a6fca0c1-0be4-4e66-83b7-bcdc4eb5e95e".len();
@@ -234,14 +239,14 @@ fn get_json(catalog_id: &str) -> String {
data.insert("CurrentFolderId", catalog_id);
data.insert("ItemsPerPage", "500");
let mut res = try_to_get_response(
|client| {
client
.post("https://streams.tum.de/Mediasite/Catalog/Data/GetPresentationsForFolder")
.header(construct_cookie())
.json(&data)
}
);
let mut res = try_to_get_response(|client| {
client
.post(
"https://streams.tum.de/Mediasite/Catalog/Data/GetPresentationsForFolder",
)
.header(construct_cookie())
.json(&data)
});
read_response_body(&mut res)
}
@@ -277,8 +282,8 @@ where
fn read_response_body(response: &mut Response) -> String {
let mut string = String::new();
response
.read_to_string(&mut string)
.expect("Failed to read body");
response.read_to_string(&mut string).expect(
"Failed to read body",
);
string
}