Update deps & format

This commit is contained in:
2018-02-24 06:01:16 +01:00
parent 352b08df6f
commit b772cc6ce3
5 changed files with 577 additions and 445 deletions

945
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,10 +4,10 @@ name = "tum_mediasite_downloader"
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
clap = "2.25.0" clap = "2.30.0"
cookie = "0.9.1" cookie = "0.10.1"
dotenv = "0.10.0" dotenv = "0.11.0"
json = "0.11.5" json = "0.11.13"
lazy_static = "0.2.2" lazy_static = "1.0.0"
reqwest = "0.7.1" reqwest = "0.8.5"
zip = "0.2.1" zip = "0.3.1"

View File

@@ -4,20 +4,22 @@ pub type Login<'a> = Option<(&'a str, &'a str)>;
#[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(rustfmt, rustfmt_skip)]
pub static ALIASES: &[(&str, CatalogDefinition)] = &[ pub static ALIASES: &[(&str, CatalogDefinition)] = &[
// WS1617
("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)),
// SS17
("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
]; ];
pub static ALIAS_ALIASES: &[(&str, &str)] = &[ pub static ALIAS_ALIASES: &[(&str, &str)] = &[
// WS1617
("DS", "DS_WS1617"), ("DS", "DS_WS1617"),
("EIDI", "EIDI_WS1617"), ("EIDI", "EIDI_WS1617"),
("ERA", "ERA_WS1617"), ("ERA", "ERA_WS1617"),
// SS17
("GAD", "GAD_SS17"), ("GAD", "GAD_SS17"),
("LA", "LA_SS17"), ("LA", "LA_SS17"),
]; ];

View File

@@ -31,7 +31,6 @@ const MAX_RETRIES: u8 = 10;
lazy_static! { lazy_static! {
static ref CLIENT: Client = ClientBuilder::new() static ref CLIENT: Client = ClientBuilder::new()
.expect("Failed to create ClientBuilder!")
// The login site redirects to itself if no redirect parameter is given // The login site redirects to itself if no redirect parameter is given
.redirect(RedirectPolicy::none()) .redirect(RedirectPolicy::none())
.build() .build()
@@ -51,9 +50,7 @@ enum DownloadError {
fn main() { fn main() {
let matches = App::new("TumMediasiteDownloader") let matches = App::new("TumMediasiteDownloader")
.author("Boris-Chengbiao Zhou <bobo1239@web.de>") .author("Boris-Chengbiao Zhou <bobo1239@web.de>")
.about( .about("Downloads \'catalogs\' from the TUM's Mediasite lecture archive.")
"Downloads \'catalogs\' from the TUM's Mediasite lecture archive.",
)
.arg( .arg(
Arg::with_name("CATALOG_NAME") Arg::with_name("CATALOG_NAME")
.help( .help(
@@ -73,18 +70,14 @@ fn main() {
.arg( .arg(
Arg::with_name("username") Arg::with_name("username")
.short("u") .short("u")
.help( .help("username for login; can be omitted if the user from .env should be used")
"username for login; can be omitted if the user from .env should be used",
)
.requires("password") .requires("password")
.takes_value(true), .takes_value(true),
) )
.arg( .arg(
Arg::with_name("password") Arg::with_name("password")
.short("p") .short("p")
.help( .help("password for login; can be omitted if the user from .env should be used")
"password for login; can be omitted if the user from .env should be used",
)
.requires("username") .requires("username")
.takes_value(true), .takes_value(true),
) )
@@ -144,18 +137,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 let mut request_builder = client.post("https://streams.tum.de/Mediasite/Login");
.post("https://streams.tum.de/Mediasite/Login") request_builder.form(&form_data);
.unwrap();
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(),
).expect( ).expect("Didn't receive a valid response trying to login! Maybe wrong login data?");
"Didn't receive a valid response trying to login! Maybe wrong login data?",
);
// FIXME: We're somehow only getting "302 Object moved" instead of the actual response // FIXME: We're somehow only getting "302 Object moved" instead of the actual response
// => We can't determine if the login was successful // => We can't determine if the login was successful
// (we still get a MediasiteAuth cookie that is useless) // (we still get a MediasiteAuth cookie that is useless)
@@ -211,7 +198,7 @@ fn get_catalog_id(name: &str) -> String {
let url = format!("https://streams.tum.de/Mediasite/Catalog/catalogs/{}", name); let url = format!("https://streams.tum.de/Mediasite/Catalog/catalogs/{}", name);
let mut res = try_to_get_response(|client| { let mut res = try_to_get_response(|client| {
let mut request_builder = client.get(&url).unwrap(); let mut request_builder = client.get(&url);
request_builder.header(construct_cookie()); request_builder.header(construct_cookie());
request_builder request_builder
}); });
@@ -250,15 +237,9 @@ fn get_json(catalog_id: &str) -> String {
data.insert("ItemsPerPage", "500"); data.insert("ItemsPerPage", "500");
let mut res = try_to_get_response(|client| { let mut res = try_to_get_response(|client| {
let mut request_builder = client let mut request_builder =
.post( client.post("https://streams.tum.de/Mediasite/Catalog/Data/GetPresentationsForFolder");
"https://streams.tum.de/Mediasite/Catalog/Data/GetPresentationsForFolder", request_builder.header(construct_cookie()).json(&data);
)
.unwrap();
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)

View File

@@ -15,7 +15,10 @@ use DownloadError;
#[derive(Debug)] #[derive(Debug)]
pub enum Presentation { pub enum Presentation {
PublishToGo { name: String, download_url: String }, PublishToGo {
name: String,
download_url: String,
},
VideoOnDemand { VideoOnDemand {
name: String, name: String,
resource_id: String, resource_id: String,
@@ -26,8 +29,8 @@ pub enum Presentation {
impl Presentation { impl Presentation {
pub(crate) fn name(&self) -> &str { pub(crate) fn name(&self) -> &str {
match *self { match *self {
Presentation::PublishToGo { ref name, .. } | Presentation::PublishToGo { ref name, .. }
Presentation::VideoOnDemand { ref name, .. } => name, | Presentation::VideoOnDemand { ref name, .. } => name,
} }
} }
@@ -61,7 +64,7 @@ impl Presentation {
} => { } => {
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);
request_builder.header(construct_cookie()); request_builder.header(construct_cookie());
request_builder request_builder
}, },
@@ -112,14 +115,13 @@ impl Presentation {
\"ResourceId\":\"{}\",\ \"ResourceId\":\"{}\",\
\"QueryString\":\"{}\"\ \"QueryString\":\"{}\"\
}}}}", }}}}",
resource_id, resource_id, query_string
query_string
); );
let url = "https://streams.tum.de/Mediasite/PlayerService/\ let url = "https://streams.tum.de/Mediasite/PlayerService/\
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);
request_builder request_builder
.header(construct_cookie()) .header(construct_cookie())
.header(ContentType::json()) .header(ContentType::json())
@@ -144,7 +146,7 @@ impl Presentation {
for (i, download_url) in videos.iter().enumerate() { for (i, download_url) in videos.iter().enumerate() {
let mut response = try_to_get_valid_response( let mut response = try_to_get_valid_response(
|client| { |client| {
let mut request_builder = client.get(download_url).unwrap(); let mut request_builder = client.get(download_url);
request_builder.header(construct_cookie()); request_builder.header(construct_cookie());
request_builder request_builder
}, },