From 5e17706f5e3b8807e2dc8b42eaaf250d61b99d8a Mon Sep 17 00:00:00 2001 From: funnym0nk3y <41870754+funnym0nk3y@users.noreply.github.com> Date: Mon, 15 Feb 2021 18:03:22 +0100 Subject: [PATCH 001/103] Updated to work again Don't know why it works --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fedd175..6dc0b99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -270,7 +270,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future Date: Tue, 16 Feb 2021 10:06:44 +0100 Subject: [PATCH 002/103] Update dependencies --- Cargo.lock | 199 +++++++++++++++++++++++++---------------------------- 1 file changed, 92 insertions(+), 107 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13724d3..841b88f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,18 +103,18 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "bstr" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" +checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" dependencies = [ "memchr", ] [[package]] name = "bumpalo" -version = "3.4.0" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" +checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9" [[package]] name = "byteorder" @@ -134,12 +134,6 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -200,7 +194,7 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -210,7 +204,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" dependencies = [ "autocfg", - "cfg-if 1.0.0", + "cfg-if", "lazy_static", ] @@ -281,11 +275,11 @@ checksum = "3a68a4904193147e0a8dec3314640e6db742afd5f6e634f428a6af230d9b3591" [[package]] name = "encoding_rs" -version = "0.8.26" +version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "801bbab217d7f79c0062f4f7205b5d4427c6d1a7bd7aafdd1475f7c59d62b283" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -299,11 +293,11 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7411863d55df97a419aa64cb4d2f167103ea9d767e2c54a1868b7ac3f6b47129" +checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crc32fast", "libc", "miniz_oxide", @@ -454,7 +448,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi", ] @@ -553,9 +547,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.4" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" [[package]] name = "httpdate" @@ -565,9 +559,9 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] name = "hyper" -version = "0.14.2" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12219dc884514cb4a6a03737f4413c0e01c23a1b059b0156004b23f1e19dccbe" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ "bytes", "futures-channel", @@ -579,7 +573,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.4", + "pin-project 1.0.5", "socket2", "tokio", "tower-service", @@ -604,9 +598,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "de910d521f7cc3135c4de8db1cb910e0b5ed1dc6f57c381cd07e8e661ce10094" dependencies = [ "matches", "unicode-bidi", @@ -647,7 +641,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -664,9 +658,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.46" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" +checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" dependencies = [ "wasm-bindgen", ] @@ -679,9 +673,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.82" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" +checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" [[package]] name = "lock_api" @@ -694,11 +688,11 @@ dependencies = [ [[package]] name = "log" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", ] [[package]] @@ -825,11 +819,11 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "instant", "libc", "redox_syscall", @@ -908,11 +902,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b70b68509f17aa2857863b6fa00bf21fc93674c7a8893de2f469f6aa7ca2f2" +checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" dependencies = [ - "pin-project-internal 1.0.4", + "pin-project-internal 1.0.5", ] [[package]] @@ -928,9 +922,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caa25a6393f22ce819b0f50e0be89287292fda8d425be38ee0ca14c4931d9e71" +checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" dependencies = [ "proc-macro2", "quote", @@ -1021,9 +1015,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] @@ -1081,9 +1075,12 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.57" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +dependencies = [ + "bitflags", +] [[package]] name = "regex" @@ -1146,9 +1143,9 @@ dependencies = [ [[package]] name = "ring" -version = "0.16.19" +version = "0.16.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "024a1e66fea74c66c66624ee5622a7ff0e4b73a13b4f5c326ddb50c708944226" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" dependencies = [ "cc", "libc", @@ -1281,18 +1278,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.120" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab" +checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.120" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca2a8cb5805ce9e3b95435e3765b7b553cecc762d938d409434338386cb5775" +checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" dependencies = [ "proc-macro2", "quote", @@ -1301,9 +1298,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" +checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486" dependencies = [ "itoa", "ryu", @@ -1371,7 +1368,7 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "winapi", ] @@ -1390,9 +1387,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "standback" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66a8cff4fa24853fdf6b51f75c6d7f8206d7c75cab4e467bcd7f25c2b1febe0" +checksum = "a2beb4d1860a61f571530b3f855a1b538d0200f7871c63331ecd6f17b1f014f8" dependencies = [ "version_check", ] @@ -1503,9 +1500,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.58" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" +checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" dependencies = [ "proc-macro2", "quote", @@ -1540,18 +1537,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thread_local" -version = "1.1.0" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] name = "time" -version = "0.2.24" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "273d3ed44dca264b0d6b3665e8d48fb515042d42466fad93d2a45b90ec4058f7" +checksum = "1195b046942c221454c2539395f85413b33383a067449d78aab2b7b052a142f7" dependencies = [ "const_fn", "libc", @@ -1587,9 +1584,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ "tinyvec_macros", ] @@ -1602,9 +1599,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.0.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca04cec6ff2474c638057b65798f60ac183e5e79d3448bb7163d36a39cff6ec" +checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" dependencies = [ "autocfg", "bytes", @@ -1622,9 +1619,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2", "quote", @@ -1642,22 +1639,11 @@ dependencies = [ "webpki", ] -[[package]] -name = "tokio-stream" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76066865172052eb8796c686f0b441a93df8b08d40a950b062ffb9a426f00edd" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-util" -version = "0.6.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ae4751faa60b9f96dd8344d74592e5a17c0c9a220413dbc6942d14139bbfcc" +checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" dependencies = [ "bytes", "futures-core", @@ -1665,22 +1651,21 @@ dependencies = [ "log", "pin-project-lite", "tokio", - "tokio-stream", ] [[package]] name = "tower-service" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" +checksum = "f7d40a22fd029e33300d8d89a5cc8ffce18bb7c587662f54629e94c9de5487f3" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "pin-project-lite", "tracing-core", ] @@ -1721,9 +1706,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ "tinyvec", ] @@ -1811,11 +1796,11 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" +checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "serde", "serde_json", "wasm-bindgen-macro", @@ -1823,9 +1808,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" +checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" dependencies = [ "bumpalo", "lazy_static", @@ -1838,11 +1823,11 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35" +checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -1850,9 +1835,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" +checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1860,9 +1845,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" +checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" dependencies = [ "proc-macro2", "quote", @@ -1873,15 +1858,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" +checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" [[package]] name = "web-sys" -version = "0.3.46" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" +checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3" dependencies = [ "js-sys", "wasm-bindgen", From fe08f95478bd0a73ad0b8803976f00c53258adf7 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu@web.de> Date: Tue, 16 Feb 2021 10:08:10 +0100 Subject: [PATCH 003/103] Version 0.2.14 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 841b88f..555285f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ # It is not intended for manual editing. [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.13" +version = "0.2.14" dependencies = [ "anyhow", "futures", diff --git a/Cargo.toml b/Cargo.toml index e1b79d9..ca78c75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.13" +version = "0.2.14" authors = ["FliegendeWurst <2012gdwu@web.de>"] license = "GPL-2.0" edition = "2018" From ce6289954b09a5d715d80280e6f094dcb5c7d505 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 8 Apr 2021 19:10:38 +0200 Subject: [PATCH 004/103] Simplify installation instructions --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 56d4c55..38436d2 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,18 @@ Download content from ILIAS. That includes: -* files (latest version) +* files +* exercise sheets and solutions * Opencast lectures +* forum posts (beta) ## Installation Go to the [releases](../../releases) and get the executable for your operating system. Alternatively compile from source: (to get the latest updates) ``` $ git clone https://github.com/FliegendeWurst/KIT-ILIAS-downloader -... $ cd KIT-ILIAS-downloader -$ cargo build --release -... -$ cp target/release/KIT-ILIAS-downloader [directory in $PATH] +$ cargo install --path . ``` ## Usage @@ -25,7 +24,7 @@ Only content on your [personal desktop](https://ilias.studium.kit.edu/ilias.php? ``` $ KIT-ILIAS-downloader --help -KIT-ILIAS-downloader 0.2.5 +KIT-ILIAS-downloader 0.2.14 USAGE: KIT-ILIAS-downloader [FLAGS] [OPTIONS] --output From 9cba23e999170b33be4daa3eb542d36c586bbee4 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 10 Apr 2021 12:55:26 +0200 Subject: [PATCH 005/103] Download forum post attachments --- src/main.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6dc0b99..9738c2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,6 +163,7 @@ mod selectors { lazy_static!{ pub static ref a: Selector = Selector::parse("a").unwrap(); pub static ref a_target_blank: Selector = Selector::parse(r#"a[target="_blank"]"#).unwrap(); + pub static ref img: Selector = Selector::parse("img").unwrap(); pub static ref table: Selector = Selector::parse("table").unwrap(); pub static ref video_tr: Selector = Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap(); pub static ref links_in_table: Selector = Selector::parse("tbody tr td a").unwrap(); @@ -172,6 +173,7 @@ mod selectors { pub static ref post_title: Selector = Selector::parse(".ilFrmPostTitle").unwrap(); pub static ref post_container: Selector = Selector::parse(".ilFrmPostContentContainer").unwrap(); pub static ref post_content: Selector = Selector::parse(".ilFrmPostContent").unwrap(); + pub static ref post_attachments: Selector = Selector::parse(".ilFrmPostAttachmentsContainer").unwrap(); pub static ref span_small: Selector = Selector::parse("span.small").unwrap(); pub static ref forum_pages: Selector = Selector::parse("div.ilTableNav > table > tbody > tr > td > a").unwrap(); pub static ref alert_danger: Selector = Selector::parse("div.alert-danger").unwrap(); @@ -180,6 +182,7 @@ mod selectors { pub static ref form_name: Selector = Selector::parse(".il_InfoScreenProperty").unwrap(); pub static ref cmd_node_regex: Regex = Regex::new(r#"cmdNode=uf:\w\w"#).unwrap(); + pub static ref image_src_regex: Regex = Regex::new(r#"\./data/produktiv/mobs/mm_(\d+)/([^?]+).+"#).unwrap(); } } use crate::selectors::*; @@ -299,7 +302,9 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future().replace('/', "-"); @@ -436,7 +444,8 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future(), attachment.value().attr("href").map(|x| x.to_owned()))); + } + } } // pagination if let Some(pages) = html.select(&table).next() { @@ -456,12 +475,38 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future { create_dir(&path).await?; From 7ac9993a5e0a414367c481d82e1e7acb63b08dc9 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 10 Apr 2021 13:23:17 +0200 Subject: [PATCH 006/103] Update dependencies --- Cargo.lock | 340 +++++++++++++++++++++++------------------------------ Cargo.toml | 2 +- 2 files changed, 145 insertions(+), 197 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 555285f..6a905c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "KIT-ILIAS-downloader" version = "0.2.14" @@ -25,9 +27,9 @@ dependencies = [ [[package]] name = "adler" -version = "0.2.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" @@ -49,9 +51,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.38" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" +checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" [[package]] name = "async-compression" @@ -112,15 +114,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.0" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" [[package]] name = "byteorder" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" @@ -130,9 +132,9 @@ checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cc" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" [[package]] name = "cfg-if" @@ -157,15 +159,21 @@ dependencies = [ [[package]] name = "const_fn" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" +checksum = "076a6803b0dacd6a88cfe64deba628b01533ff5ef265687e6938280c1afd0a28" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "cookie" -version = "0.14.3" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784ad0fbab4f3e9cef09f20e0aea6000ae08d2cb98ac4c0abc53df18803d702f" +checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" dependencies = [ "percent-encoding", "time", @@ -199,9 +207,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" +checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" dependencies = [ "autocfg", "cfg-if", @@ -237,10 +245,11 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.11" +version = "0.99.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" +checksum = "f82b1b72f1263f214c0f823371768776c4f5841b942c9883aa8e5ec584fd0ba6" dependencies = [ + "convert_case", "proc-macro2", "quote", "syn", @@ -254,9 +263,9 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" [[package]] name = "dtoa" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e" +checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" [[package]] name = "dtoa-short" @@ -282,15 +291,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "error-chain" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "version_check", -] - [[package]] name = "flate2" version = "1.0.20" @@ -311,9 +311,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "form_urlencoded" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ "matches", "percent-encoding", @@ -331,9 +331,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9052a1a50244d8d5aa9bf55cbc2fb6f357c86cc52e46c62ed390a7180cf150" +checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253" dependencies = [ "futures-channel", "futures-core", @@ -346,9 +346,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2d31b7ec7efab6eefc7c57233bb10b847986139d88cc2f5a02a1ae6871a1846" +checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25" dependencies = [ "futures-core", "futures-sink", @@ -356,15 +356,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65" +checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815" [[package]] name = "futures-executor" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e59fdc009a4b3096bf94f740a0f2424c082521f20a9b08c5c07c48d90fd9b9" +checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d" dependencies = [ "futures-core", "futures-task", @@ -373,15 +373,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500" +checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04" [[package]] name = "futures-macro" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c287d25add322d9f9abdcdc5927ca398917996600182178774032e9f8258fedd" +checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -391,24 +391,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf5c69029bda2e743fddd0582d1083951d65cc9539aebf8812f36c3491342d6" +checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23" [[package]] name = "futures-task" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13de07eb8ea81ae445aca7b69f5f7bf15d7bf4912d8ca37d6645c77ae8a58d86" -dependencies = [ - "once_cell", -] +checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc" [[package]] name = "futures-util" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632a8cd0f2a4b3fdea1657f08bde063848c3bd00f9bbf6e256b8be78802e624b" +checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025" dependencies = [ "futures-channel", "futures-core", @@ -468,9 +465,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5" +checksum = "fc018e188373e2777d0ef2467ebff62a08e66c3f5857b23c8fbec3018210dc00" dependencies = [ "bytes", "fnv", @@ -483,7 +480,6 @@ dependencies = [ "tokio", "tokio-util", "tracing", - "tracing-futures", ] [[package]] @@ -526,9 +522,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" dependencies = [ "bytes", "fnv", @@ -537,19 +533,20 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" +checksum = "5dfb77c123b4e2f72a2069aeae0b4b4949cc7e966df277813fc16347e7549737" dependencies = [ "bytes", "http", + "pin-project-lite", ] [[package]] name = "httparse" -version = "1.3.5" +version = "1.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" +checksum = "bc35c995b9d93ec174cf9a27d425c7892722101e14993cd227fdb51d70cf9589" [[package]] name = "httpdate" @@ -559,9 +556,9 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] name = "hyper" -version = "0.14.4" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" +checksum = "8bf09f61b52cfcf4c00de50df88ae423d6c02354e385a86341133b5338630ad1" dependencies = [ "bytes", "futures-channel", @@ -573,7 +570,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.5", + "pin-project", "socket2", "tokio", "tower-service", @@ -598,9 +595,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de910d521f7cc3135c4de8db1cb910e0b5ed1dc6f57c381cd07e8e661ce10094" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" dependencies = [ "matches", "unicode-bidi", @@ -627,9 +624,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", @@ -658,9 +655,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.47" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" +checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c" dependencies = [ "wasm-bindgen", ] @@ -673,15 +670,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.86" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" [[package]] name = "lock_api" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" +checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" dependencies = [ "scopeguard", ] @@ -738,9 +735,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "miniz_oxide" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", "autocfg", @@ -748,9 +745,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.7" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" +checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" dependencies = [ "libc", "log", @@ -761,11 +758,10 @@ dependencies = [ [[package]] name = "miow" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "socket2", "winapi", ] @@ -802,9 +798,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.5.2" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "parking_lot" @@ -893,38 +889,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.27" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" +checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6" dependencies = [ - "pin-project-internal 0.4.27", -] - -[[package]] -name = "pin-project" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" -dependencies = [ - "pin-project-internal 1.0.5", + "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.27" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" +checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5" dependencies = [ "proc-macro2", "quote", @@ -933,9 +909,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -993,23 +969,20 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ "unicode-xid", ] [[package]] name = "publicsuffix" -version = "1.5.4" +version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaa49075179162b49acac1c6aa45fb4dafb5f13cf6794276d77bc7fd95757b" +checksum = "95b4ce31ff0a27d93c8de1849cf58162283752f065a90d508f1105fa6c9a213f" dependencies = [ - "error-chain", "idna", - "lazy_static", - "regex", "url", ] @@ -1084,27 +1057,26 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.3" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.22" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "reqwest" -version = "0.11.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd281b1030aa675fb90aa994d07187645bb3c8fc756ca766e7c3070b439de9de" +checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" dependencies = [ "async-compression", "base64", @@ -1278,18 +1250,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.123" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" dependencies = [ "proc-macro2", "quote", @@ -1298,9 +1270,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.62" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea1c6153794552ea7cf7cf63b1231a25de00ec90db326ba6264440fa08e31486" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -1335,20 +1307,11 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" -[[package]] -name = "signal-hook-registry" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" -dependencies = [ - "libc", -] - [[package]] name = "siphasher" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" +checksum = "cbce6d4507c7e4a3962091436e56e95290cb71fa302d0d270e32130b75fbff27" [[package]] name = "slab" @@ -1364,11 +1327,10 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "socket2" -version = "0.3.19" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" dependencies = [ - "cfg-if", "libc", "winapi", ] @@ -1387,9 +1349,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "standback" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2beb4d1860a61f571530b3f855a1b538d0200f7871c63331ecd6f17b1f014f8" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" dependencies = [ "version_check", ] @@ -1500,9 +1462,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.60" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" dependencies = [ "proc-macro2", "quote", @@ -1546,9 +1508,9 @@ dependencies = [ [[package]] name = "time" -version = "0.2.25" +version = "0.2.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1195b046942c221454c2539395f85413b33383a067449d78aab2b7b052a142f7" +checksum = "08a8cbfbf47955132d0202d1662f49b2423ae35862aee471f3ba4b133358f372" dependencies = [ "const_fn", "libc", @@ -1584,9 +1546,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" +checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" dependencies = [ "tinyvec_macros", ] @@ -1599,9 +1561,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" +checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722" dependencies = [ "autocfg", "bytes", @@ -1609,12 +1571,8 @@ dependencies = [ "memchr", "mio", "num_cpus", - "once_cell", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "tokio-macros", - "winapi", ] [[package]] @@ -1641,9 +1599,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" +checksum = "5143d049e85af7fbc36f5454d990e62c2df705b3589f123b71f441b6b59f443f" dependencies = [ "bytes", "futures-core", @@ -1661,9 +1619,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.23" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d40a22fd029e33300d8d89a5cc8ffce18bb7c587662f54629e94c9de5487f3" +checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ "cfg-if", "pin-project-lite", @@ -1679,16 +1637,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "tracing-futures" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" -dependencies = [ - "pin-project 0.4.27", - "tracing", -] - [[package]] name = "try-lock" version = "0.2.3" @@ -1697,9 +1645,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" dependencies = [ "matches", ] @@ -1739,9 +1687,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ "form_urlencoded", "idna", @@ -1763,15 +1711,15 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "walkdir" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", "winapi", @@ -1796,9 +1744,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" +checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" dependencies = [ "cfg-if", "serde", @@ -1808,9 +1756,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" +checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" dependencies = [ "bumpalo", "lazy_static", @@ -1823,9 +1771,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.20" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" +checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea" dependencies = [ "cfg-if", "js-sys", @@ -1835,9 +1783,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" +checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1845,9 +1793,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" +checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" dependencies = [ "proc-macro2", "quote", @@ -1858,15 +1806,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.70" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" +checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" [[package]] name = "web-sys" -version = "0.3.47" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3" +checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" dependencies = [ "js-sys", "wasm-bindgen", @@ -1884,9 +1832,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82015b7e0b8bad8185994674a13a93306bea76cf5a16c5a181382fd3a5ec2376" +checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" dependencies = [ "webpki", ] diff --git a/Cargo.toml b/Cargo.toml index ca78c75..ce2ec71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] reqwest = { version = "0.11.0", default-features = false, features = ["cookies", "gzip", "json", "rustls-tls", "stream"] } -tokio = { version = "1.0.2", features = ["full"] } +tokio = { version = "1.0.2", features = ["fs", "macros", "net", "rt-multi-thread"] } tokio-util = { version = "0.6.1", features = ["io"] } serde_json = "1.0.51" scraper = "0.12.0" From 652fdd91a44158632142c74f5516337477a67411 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 10 Apr 2021 13:35:13 +0200 Subject: [PATCH 007/103] Include forum post header in download --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9738c2b..50af630 100644 --- a/src/main.rs +++ b/src/main.rs @@ -172,7 +172,6 @@ mod selectors { pub static ref post_row: Selector = Selector::parse(".ilFrmPostRow").unwrap(); pub static ref post_title: Selector = Selector::parse(".ilFrmPostTitle").unwrap(); pub static ref post_container: Selector = Selector::parse(".ilFrmPostContentContainer").unwrap(); - pub static ref post_content: Selector = Selector::parse(".ilFrmPostContent").unwrap(); pub static ref post_attachments: Selector = Selector::parse(".ilFrmPostAttachmentsContainer").unwrap(); pub static ref span_small: Selector = Selector::parse("span.small").unwrap(); pub static ref forum_pages: Selector = Selector::parse("div.ilTableNav > table > tbody > tr > td > a").unwrap(); @@ -446,8 +445,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future Date: Tue, 13 Apr 2021 13:01:22 +0200 Subject: [PATCH 008/103] Added proxy support --- Cargo.lock | 13 +++++++++++++ Cargo.toml | 2 +- src/main.rs | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a905c0..c812132 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1104,6 +1104,7 @@ dependencies = [ "time", "tokio", "tokio-rustls", + "tokio-socks", "tokio-util", "url", "wasm-bindgen", @@ -1597,6 +1598,18 @@ dependencies = [ "webpki", ] +[[package]] +name = "tokio-socks" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51165dfa029d2a65969413a6cc96f354b86b464498702f174a4efa13608fd8c0" +dependencies = [ + "either", + "futures-util", + "thiserror", + "tokio", +] + [[package]] name = "tokio-util" version = "0.6.5" diff --git a/Cargo.toml b/Cargo.toml index ce2ec71..374a592 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -reqwest = { version = "0.11.0", default-features = false, features = ["cookies", "gzip", "json", "rustls-tls", "stream"] } +reqwest = { version = "0.11.0", default-features = false, features = ["cookies", "gzip", "json", "rustls-tls", "stream", "socks"] } tokio = { version = "1.0.2", features = ["fs", "macros", "net", "rt-multi-thread"] } tokio-util = { version = "0.6.1", features = ["io"] } serde_json = "1.0.51" diff --git a/src/main.rs b/src/main.rs index 50af630..09dcf8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use ignore::gitignore::Gitignore; use lazy_static::lazy_static; use parking_lot::Mutex; use regex::Regex; -use reqwest::Client; +use reqwest::{Client, Proxy}; use scraper::{ElementRef, Html, Selector}; use serde_json::json; use structopt::StructOpt; @@ -653,6 +653,10 @@ struct Opt { /// Parallel download jobs #[structopt(short, long, default_value = "1")] jobs: usize, + + /// Proxy, e.g. socks5://127.0.0.1:1080 + #[structopt(short, long, default_value = "")] + proxy: String, } struct ILIAS { @@ -668,9 +672,14 @@ impl ILIAS { async fn login, S2: Into>(opt: Opt, user: S1, pass: S2, ignore: Gitignore) -> Result { let user = user.into(); let pass = pass.into(); - let client = Client::builder() + let mut builder = Client::builder() .cookie_store(true) - .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))) + .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); + if opt.proxy != "" { + let proxy = Proxy::all(&opt.proxy)?; + builder = builder.proxy(proxy); + } + let client = builder // timeout is infinite by default .build()?; let this = ILIAS { From 4bbb31ea64f164591b42656174571d0c4325ad6f Mon Sep 17 00:00:00 2001 From: Craeckie Date: Tue, 13 Apr 2021 13:08:02 +0200 Subject: [PATCH 009/103] Adapted usage in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 38436d2..f511645 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ FLAGS: OPTIONS: -j, --jobs Parallel download jobs [default: 1] -o, --output Output directory + -p, --proxy Proxy, e.g. socks5://127.0.0.1:1080 [default: ""] ``` ### .iliasignore From 75846141f4a97c9724e1fdb9f2f1ebafbc1198ea Mon Sep 17 00:00:00 2001 From: Craeckie Date: Wed, 14 Apr 2021 12:00:44 +0200 Subject: [PATCH 010/103] socks5h ensures, that DNS requests are also proxied --- README.md | 2 +- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f511645..b6f76ac 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ FLAGS: OPTIONS: -j, --jobs Parallel download jobs [default: 1] -o, --output Output directory - -p, --proxy Proxy, e.g. socks5://127.0.0.1:1080 [default: ""] + -p, --proxy Proxy, e.g. socks5h://127.0.0.1:1080 [default: ""] ``` ### .iliasignore diff --git a/src/main.rs b/src/main.rs index 09dcf8d..571e6c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -654,7 +654,7 @@ struct Opt { #[structopt(short, long, default_value = "1")] jobs: usize, - /// Proxy, e.g. socks5://127.0.0.1:1080 + /// Proxy, e.g. socks5h://127.0.0.1:1080 #[structopt(short, long, default_value = "")] proxy: String, } From 4f053858417160aaba9333dbaa9b40cd5b546af5 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 14 Apr 2021 17:05:07 +0200 Subject: [PATCH 011/103] build script --- build.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0308c49 --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ +#!/bin/sh +rustup target add x86_64-unknown-linux-musl +cargo build --release --target x86_64-unknown-linux-musl +strip target/release/KIT-ILIAS-downloader + +rustup target add x86_64-pc-windows-gnu +# if on Debian or similar +sudo apt install mingw-w64 +cargo build --release --target x86_64-pc-windows-gnu +strip target/x86_64-pc-windows-gnu/release/KIT-ILIAS-downloader From 117730d6ab81ff920c2739b78af011be4238b4ef Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 14 Apr 2021 17:07:16 +0200 Subject: [PATCH 012/103] Version 0.2.15 --- Cargo.lock | 28 +++++++++++++++++++++++++++- Cargo.toml | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c812132..2976578 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.14" +version = "0.2.15" dependencies = [ "anyhow", "futures", @@ -282,6 +282,12 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a68a4904193147e0a8dec3314640e6db742afd5f6e634f428a6af230d9b3591" +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "encoding_rs" version = "0.8.28" @@ -1498,6 +1504,26 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" +[[package]] +name = "thiserror" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.3" diff --git a/Cargo.toml b/Cargo.toml index 374a592..e26e4af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.14" +version = "0.2.15" authors = ["FliegendeWurst <2012gdwu@web.de>"] license = "GPL-2.0" edition = "2018" From da9aab22d53e36c36e1aad52681f93e946524e75 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 14 Apr 2021 17:24:39 +0200 Subject: [PATCH 013/103] Correct statement in readme --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b6f76ac..67087c6 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ Download content from ILIAS. That includes: * files * exercise sheets and solutions * Opencast lectures -* forum posts (beta) +* forum posts ## Installation -Go to the [releases](../../releases) and get the executable for your operating system. Alternatively compile from source: (to get the latest updates) +Go to the [releases](../../releases) and get the executable for your operating system. Or compile from source: ``` $ git clone https://github.com/FliegendeWurst/KIT-ILIAS-downloader $ cd KIT-ILIAS-downloader @@ -18,7 +18,11 @@ $ cargo install --path . ## Usage -Use `-o ` to specify the download directory. Username and password have to be provided every time the program is run. +Use `-o ` to specify the download directory: + +``` +$ KIT-ILIAS-downloader -o ./ILIAS +``` Only content on your [personal desktop](https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems) will be downloaded. From af2c477a04dd7980327b6b0c506c912361216827 Mon Sep 17 00:00:00 2001 From: lukasprobst Date: Thu, 15 Apr 2021 23:37:36 +0200 Subject: [PATCH 014/103] Add the dependency 'colored' and color relevant messages --- Cargo.toml | 1 + src/main.rs | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e26e4af..e0cc546 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,4 @@ rpassword = "5.0.0" rprompt = "1.0.5" ignore = "0.4.14" anyhow = "1.0.28" +colored = "2.0.0" diff --git a/src/main.rs b/src/main.rs index 571e6c9..f777c90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use colored::Colorize; use anyhow::{Context, Result, anyhow}; use futures::future::{self, Either}; use futures_channel::mpsc::UnboundedSender; @@ -45,7 +46,7 @@ async fn main() { opt.output.push(".iliasignore"); let (ignore, error) = Gitignore::new(&opt.output); if let Some(err) = error { - println!("Warning: .iliasignore error: {}", err); + println!("Warning: {} {}", ".iliasignore error:".bright_yellow(), err.to_string().bright_yellow()); } opt.output.pop(); // loac .iliaslogin file @@ -60,7 +61,7 @@ async fn main() { let pass = pass.unwrap().trim(); (user.to_owned(), pass.to_owned()) } else { - println!("Warning: .iliaslogin incomplete"); + println!("Warning: {}", ".iliaslogin incomplete".bright_yellow()); ask_user_pass() } } else { @@ -70,15 +71,15 @@ async fn main() { let ilias = match ILIAS::login(opt, user, pass, ignore).await { Ok(ilias) => ilias, - Err(e) => { - print!("{:?}", e); + Err(e) =>{ + println!("Error: {}", format!("{:?}", e).bright_red()); std::process::exit(77); } }; if ilias.opt.content_tree { // need this to get the content tree if let Err(e) = ilias.client.get("https://ilias.studium.kit.edu/ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=tree&ref_id=1").send().await { - println!("Warning: could not enable content tree: {:?}", e); + println!("Warning: {} {}", "could not enable content tree:".bright_yellow(), format!("{:?}", e).bright_yellow()); } } let ilias = Arc::new(ilias); @@ -106,7 +107,7 @@ async fn main() { if ilias.opt.content_tree { // restore fast page loading times if let Err(e) = ilias.client.get("https://ilias.studium.kit.edu/ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=flat&ref_id=1").send().await { - println!("Warning: could not disable content tree: {:?}", e); + println!("Warning: {} {}", "could not disable content tree:".bright_yellow(), format!("{:?}", e).bright_yellow()); } } } @@ -143,14 +144,14 @@ fn process_gracefully(ilias: Arc, path: PathBuf, obj: Object) -> impl Fut } let path_text = path.to_string_lossy().into_owned(); if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { - println!("Syncing {}: {:?}", path_text, e); + println!("Syncing {}: {:?}", path_text, format!("{:?}", e).bright_red()); } *TASKS_RUNNING.lock() -= 1; }} async fn handle_gracefully(fut: impl Future>) { if let Err(e) = fut.await { - println!("Error: {:?}", e); + println!("Error: {}", format!("{:?}", e).bright_red()); } } @@ -221,7 +222,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future()? { - log!(0, "Warning: {} was updated, consider moving the outdated file", relative_path.to_string_lossy()); + log!(0, "Warning: {} {}", relative_path.to_string_lossy().bright_yellow(), "was updated, consider moving the outdated file".bright_yellow()); } } } else { @@ -397,7 +398,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future>(); if cells.len() != 6 { - log!(0, "Warning: unusual table row ({} cells) in {}", cells.len(), url); + log!(0, "Warning: {}{} {} {}", "unusual table row (".bright_yellow(), cells.len().to_string().bright_yellow(), "cells) in".bright_yellow(), url.to_string().bright_yellow()); continue; } let link = cells[1].select(&a).next().context("thread link not found")?; @@ -476,7 +477,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future Result { From 381df5326478fa30301c05261cabc542fa624f8e Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 16 Apr 2021 13:24:10 +0200 Subject: [PATCH 015/103] Code style + formatting + logging macros --- Cargo.lock | 12 + src/main.rs | 702 +++++++++++++++++++++++++++++----------------------- src/util.rs | 34 +++ 3 files changed, 433 insertions(+), 315 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2976578..9c2a5cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,7 @@ name = "KIT-ILIAS-downloader" version = "0.2.15" dependencies = [ "anyhow", + "colored", "futures", "futures-channel", "futures-util", @@ -157,6 +158,17 @@ dependencies = [ "vec_map", ] +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + [[package]] name = "const_fn" version = "0.4.6" diff --git a/src/main.rs b/src/main.rs index f777c90..64e572a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,13 @@ +#![allow(clippy::comparison_to_empty, clippy::upper_case_acronyms)] + +use anyhow::{anyhow, Context, Result}; use colored::Colorize; -use anyhow::{Context, Result, anyhow}; use futures::future::{self, Either}; use futures_channel::mpsc::UnboundedSender; -use futures_util::{StreamExt, stream::TryStreamExt}; +use futures_util::{stream::TryStreamExt, StreamExt}; use ignore::gitignore::Gitignore; use lazy_static::lazy_static; use parking_lot::Mutex; -use regex::Regex; use reqwest::{Client, Proxy}; use scraper::{ElementRef, Html, Selector}; use serde_json::json; @@ -16,23 +17,73 @@ use tokio::task::{self, JoinHandle}; use tokio_util::io::StreamReader; use url::Url; -use std::{collections::HashSet, default::Default}; use std::future::Future; use std::io; use std::panic; use std::path::PathBuf; +use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; +use std::{collections::HashSet, default::Default, sync::atomic::AtomicUsize}; mod util; use util::*; const ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; +static LOG_LEVEL: AtomicUsize = AtomicUsize::new(0); + +macro_rules! log { + ($lvl:expr, $($t:expr),+) => { + #[allow(unused_comparisons)] // 0 <= 0 + if $lvl <= LOG_LEVEL.load(Ordering::SeqCst) { + println!($($t),+); + } + } +} + +macro_rules! info { + ($t:tt) => { + println!($t); + }; +} + +macro_rules! success { + ($t:tt) => { + println!("{}", format!($t).bright_green()); + }; +} + +macro_rules! warning { + ($e:expr) => { + println!("Warning: {}", format!("{:?}", $e).bright_yellow()); + }; + ($msg:expr, $e:expr) => { + println!("Warning: {}", format!("{} {:?}", $msg, $e).bright_yellow()); + }; + ($msg1:expr, $msg2:expr, $e:expr) => { + println!("Warning: {}", format!("{} {} {:?}", $msg1, $msg2, $e).bright_yellow()); + }; + (format => $($e:expr),+) => { + println!("Warning: {}", format!($($e),+)); + }; +} + +macro_rules! error { + ($($prefix:expr),+; $e:expr) => { + println!("{}: {}", format!($($prefix),+), format!("{:?}", $e).bright_red()); + }; + ($e:expr) => { + println!("Error: {}", format!("{:?}", $e).bright_red()); + }; +} + #[tokio::main] async fn main() { let mut opt = Opt::from_args(); - opt.output = fs::canonicalize(opt.output).await.expect("failed to canonicalize directory"); // use long paths on Windows + // use UNC paths on Windows + opt.output = fs::canonicalize(opt.output).await.expect("failed to canonicalize directory"); + LOG_LEVEL.store(opt.verbose, Ordering::SeqCst); create_dir(&opt.output).await.expect("failed to create output directory"); // need this because task scheduling is WIP // (would wait forever on paniced task) @@ -46,7 +97,7 @@ async fn main() { opt.output.push(".iliasignore"); let (ignore, error) = Gitignore::new(&opt.output); if let Some(err) = error { - println!("Warning: {} {}", ".iliasignore error:".bright_yellow(), err.to_string().bright_yellow()); + warning!(err); } opt.output.pop(); // loac .iliaslogin file @@ -54,16 +105,11 @@ async fn main() { let login = std::fs::read_to_string(&opt.output); let (user, pass) = if let Ok(login) = login { let mut lines = login.split('\n'); - let user = lines.next(); - let pass = lines.next(); - if user.is_some() && pass.is_some() { - let user = user.unwrap().trim(); - let pass = pass.unwrap().trim(); - (user.to_owned(), pass.to_owned()) - } else { - println!("Warning: {}", ".iliaslogin incomplete".bright_yellow()); - ask_user_pass() - } + let user = lines.next().expect("missing user in .iliaslogin"); + let pass = lines.next().expect("missing password in .iliaslogin"); + let user = user.trim(); + let pass = pass.trim(); + (user.to_owned(), pass.to_owned()) } else { ask_user_pass() }; @@ -71,15 +117,15 @@ async fn main() { let ilias = match ILIAS::login(opt, user, pass, ignore).await { Ok(ilias) => ilias, - Err(e) =>{ - println!("Error: {}", format!("{:?}", e).bright_red()); + Err(e) => { + error!(e); std::process::exit(77); - } + }, }; if ilias.opt.content_tree { // need this to get the content tree if let Err(e) = ilias.client.get("https://ilias.studium.kit.edu/ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=tree&ref_id=1").send().await { - println!("Warning: {} {}", "could not enable content tree:".bright_yellow(), format!("{:?}", e).bright_yellow()); + warning!("could not enable content tree:", e); } } let ilias = Arc::new(ilias); @@ -95,34 +141,34 @@ async fn main() { let _ = tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))); } }, - Err(e) => println!("{:?}", e) + Err(e) => error!(e), } - loop { - match future::select(rx.next(), future::ready(())).await { - // if the channel is empty, all tasks are completed - Either::Left((task, _)) => if let Some(task) = task { let _ = task.await; } else { break }, - Either::Right(_) => break + while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await { + if let Some(task) = task { + let _ = task.await; + } else { + break; } } + // channel is empty => all tasks are completed if ilias.opt.content_tree { // restore fast page loading times if let Err(e) = ilias.client.get("https://ilias.studium.kit.edu/ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=flat&ref_id=1").send().await { - println!("Warning: {} {}", "could not disable content tree:".bright_yellow(), format!("{:?}", e).bright_yellow()); + warning!("could not disable content tree:", e); } } } -lazy_static!{ +lazy_static! { static ref TASKS: Mutex>>> = Mutex::default(); static ref TASKS_RUNNING: Mutex = Mutex::default(); - static ref PANIC_HOOK: Mutex> = Mutex::new(Box::new(|_| {})); } macro_rules! spawn { ($e:expr) => { let _ = TASKS.lock().as_ref().unwrap().unbounded_send(task::spawn($e)); - } + }; } fn ask_user_pass() -> (String, String) { @@ -131,9 +177,16 @@ fn ask_user_pass() -> (String, String) { (user, pass) } -fn process_gracefully(ilias: Arc, path: PathBuf, obj: Object) -> impl Future + Send { async move { +// https://github.com/rust-lang/rust/issues/53690#issuecomment-418911229 +#[allow(clippy::manual_async_fn)] +fn process_gracefully( + ilias: Arc, + path: PathBuf, + obj: Object, +) -> impl Future + Send { async move { loop { - { // limit scope of lock + { + // limit scope of lock let mut running = TASKS_RUNNING.lock(); if *running < ilias.opt.jobs { *running += 1; @@ -144,14 +197,14 @@ fn process_gracefully(ilias: Arc, path: PathBuf, obj: Object) -> impl Fut } let path_text = path.to_string_lossy().into_owned(); if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { - println!("Syncing {}: {:?}", path_text, format!("{:?}", e).bright_red()); + error!("Syncing {}", path_text; e); } *TASKS_RUNNING.lock() -= 1; }} async fn handle_gracefully(fut: impl Future>) { if let Err(e) = fut.await { - println!("Error: {}", format!("{:?}", e).bright_red()); + error!(e); } } @@ -161,7 +214,7 @@ mod selectors { use regex::Regex; use scraper::Selector; // construct CSS selectors once - lazy_static!{ + lazy_static! { pub static ref a: Selector = Selector::parse("a").unwrap(); pub static ref a_target_blank: Selector = Selector::parse(r#"a[target="_blank"]"#).unwrap(); pub static ref img: Selector = Selector::parse("img").unwrap(); @@ -180,26 +233,14 @@ mod selectors { pub static ref tree_highlighted: Selector = Selector::parse("span.ilHighlighted").unwrap(); pub static ref form_group: Selector = Selector::parse(".form-group").unwrap(); pub static ref form_name: Selector = Selector::parse(".il_InfoScreenProperty").unwrap(); - pub static ref cmd_node_regex: Regex = Regex::new(r#"cmdNode=uf:\w\w"#).unwrap(); pub static ref image_src_regex: Regex = Regex::new(r#"\./data/produktiv/mobs/mm_(\d+)/([^?]+).+"#).unwrap(); + pub static ref XOCT_REGEX: Regex = Regex::new(r#"(?m)"#).unwrap(); } } use crate::selectors::*; -// see https://github.com/rust-lang/rust/issues/53690#issuecomment-418911229 -//async fn process(ilias: Arc, path: PathBuf, obj: Object) { -fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future> + Send { async move { - let log_level = ilias.opt.verbose; - macro_rules! log { - ($lvl:expr, $($arg:expr),*) => { - #[allow(unused_comparisons)] // 0 >= 0 - if log_level >= $lvl { - println!($($arg),*); - } - } - } - +async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<()> { let relative_path = path.strip_prefix(&ilias.opt.output).unwrap(); if ilias.ignore.matched(relative_path, obj.is_dir()).is_ignore() { log!(1, "Ignored {}", relative_path.to_string_lossy()); @@ -222,9 +263,9 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future { if ilias.opt.no_videos { @@ -281,16 +322,16 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future>(); + let mut query_parameters = full_url.query_pairs().map(|(x, y)| (x.into_owned(), y.into_owned())).collect::>(); for (key, value) in &mut query_parameters { match key.as_ref() { "cmd" => *value = "asyncGetTableGUI".into(), "cmdClass" => *value = "xocteventgui".into(), - _ => {} + _ => {}, } } query_parameters.push(("cmdMode".into(), "asynch".into())); @@ -303,7 +344,7 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future "table row without link in {}", url.url); } continue; } @@ -319,7 +360,12 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future { - lazy_static!{ - static ref XOCT_REGEX: Regex = Regex::new(r#"(?m)"#).unwrap(); - } if ilias.opt.no_videos { return Ok(()); } @@ -347,30 +390,39 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future()? { - log!(0, "Warning: {} {}", relative_path.to_string_lossy().bright_yellow(), "was updated, consider moving the outdated file".bright_yellow()); + warning!(relative_path.to_string_lossy(), "was updated, consider moving the outdated file"); } } } else { let resp = ilias.download(&url).await?; - let mut reader = StreamReader::new(resp.bytes_stream().map_err(|x| { - io::Error::new(io::ErrorKind::Other, x) - })); + let mut reader = StreamReader::new( + resp.bytes_stream() + .map_err(|x| io::Error::new(io::ErrorKind::Other, x)), + ); log!(0, "Writing {}", relative_path.to_string_lossy()); - write_file_data(&path, &mut reader).await.context("failed to save video")?; + write_file_data(&path, &mut reader).await?; } }, Forum { url, .. } => { @@ -385,11 +437,11 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future>(); if cells.len() != 6 { - log!(0, "Warning: {}{} {} {}", "unusual table row (".bright_yellow(), cells.len().to_string().bright_yellow(), "cells) in".bright_yellow(), url.to_string().bright_yellow()); + log!( + 0, + "Warning: {}{} {} {}", + "unusual table row (".bright_yellow(), + cells.len().to_string().bright_yellow(), + "cells) in".bright_yellow(), + url.to_string().bright_yellow() + ); continue; } - let link = cells[1].select(&a).next().context("thread link not found")?; + let link = cells[1] + .select(&a) + .next() + .context("thread link not found")?; let object = Object::from_link(link, link)?; let mut path = path.clone(); - let name = format!("{}_{}", - object.url().thr_pk.as_ref().context("thr_pk not found for thread")?, + let name = format!( + "{}_{}", + object + .url() + .thr_pk + .as_ref() + .context("thr_pk not found for thread")?, link.text().collect::().trim() ); path.push(file_escape(&name)); // TODO: set modification date? let saved_posts = { - match std::fs::read_dir(&path) { // TODO: make this async + match std::fs::read_dir(&path) { + // TODO: make this async Ok(stream) => stream.count(), - Err(_) => 0 + Err(_) => 0, } }; - let available_posts = cells[3].text().next().unwrap_or_default().trim().parse::().context("parsing post count failed")?; + let available_posts = cells[3] + .text() + .next() + .unwrap_or_default() + .trim() + .parse::() + .context("parsing post count failed")?; if available_posts <= saved_posts && !ilias.opt.force { continue; } @@ -436,73 +510,111 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future().replace('/', "-"); - let author = post.select(&span_small).next().ok_or(anyhow!("post author not found"))?; - let author = author.text().collect::(); - let author = author.trim().split('|').nth(1).ok_or(anyhow!("author data in unknown format"))?.trim(); - let container = post.select(&post_container).next().ok_or(anyhow!("post container not found"))?; - let link = container.select(&a).next().ok_or(anyhow!("post link not found"))?; - let id = link.value().attr("id").ok_or(anyhow!("no id in thread link"))?.to_owned(); - let name = format!("{}_{}_{}.html", id, author, title.trim()); - let data = container.inner_html(); - let mut path = path.clone(); - path.push(file_escape(&name)); - spawn!(handle_gracefully(async move { - write_file_data(&path, &mut data.as_bytes()).await - .context("failed to write forum post") - })); - let images = container.select(&img).map(|x| x.value().attr("src").map(|x| x.to_owned())); - for image in images { - let image = image.ok_or(anyhow!("no src on image"))?; - all_images.push((id.clone(), image)); - } - if let Some(container) = container.select(&post_attachments).next() { - for attachment in container.select(&a) { - attachments.push((id.clone(), attachment.text().collect::(), attachment.value().attr("href").map(|x| x.to_owned()))); + let html = ilias.get_html(&url.url).await?; + for post in html.select(&post_row) { + let title = post + .select(&post_title) + .next() + .context("post title not found")? + .text() + .collect::(); + let author = post + .select(&span_small) + .next() + .context("post author not found")?; + let author = author.text().collect::(); + let author = author + .trim() + .split('|') + .nth(1) + .context("author data in unknown format")? + .trim(); + let container = post + .select(&post_container) + .next() + .context("post container not found")?; + let link = container.select(&a).next().context("post link not found")?; + let id = link + .value() + .attr("id") + .context("no id in thread link")? + .to_owned(); + let name = format!("{}_{}_{}.html", id, author, title.trim()); + let data = container.inner_html(); + let mut path = path.clone(); + path.push(file_escape(&name)); + spawn!(handle_gracefully(async move { + write_file_data(&path, &mut data.as_bytes()) + .await + .context("failed to write forum post") + })); + let images = container + .select(&img) + .map(|x| x.value().attr("src").map(|x| x.to_owned())); + for image in images { + let image = image.context("no src on image")?; + all_images.push((id.clone(), image)); + } + if let Some(container) = container.select(&post_attachments).next() { + for attachment in container.select(&a) { + attachments.push(( + id.clone(), + attachment.text().collect::(), + attachment.value().attr("href").map(|x| x.to_owned()), + )); + } } } - } - // pagination - if let Some(pages) = html.select(&table).next() { - if let Some(last) = pages.select(&links_in_table).last() { - let text = last.text().collect::(); - if text.trim() == ">>" { - // not last page yet - let ilias = Arc::clone(&ilias); - let next_page = Thread { - url: URL::from_href(last.value().attr("href").ok_or(anyhow!("page link not found"))?)? - }; - spawn!(process_gracefully(ilias, path.clone(), next_page)); + // pagination + if let Some(pages) = html.select(&table).next() { + if let Some(last) = pages.select(&links_in_table).last() { + let text = last.text().collect::(); + if text.trim() == ">>" { + // not last page yet + let ilias = Arc::clone(&ilias); + let next_page = Thread { + url: URL::from_href( + last.value().attr("href").context("page link not found")?, + )?, + }; + spawn!(process_gracefully(ilias, path.clone(), next_page)); + } + } else { + log!( + 0, + "Warning: {} {}", + "unable to find pagination links in".bright_yellow(), + url.url.to_string().bright_yellow() + ); } - } else { - log!(0, "Warning: {} {}", "unable to find pagination links in".bright_yellow(), url.url.to_string().bright_yellow()); } } - } for (id, image) in all_images { let src = URL::from_href(&image)?; let dl = ilias.download(&src.url).await?; - let m = image_src_regex.captures(&image).ok_or_else(|| anyhow!(format!("image src {} unexpected format", image)))?; + let m = image_src_regex + .captures(&image) + .context(format!("image src {} unexpected format", image))?; let (media_id, filename) = (m.get(1).unwrap().as_str(), m.get(2).unwrap().as_str()); let mut path = path.clone(); path.push(file_escape(&format!("{}_{}_{}", id, media_id, filename))); spawn!(handle_gracefully(async move { let bytes = dl.bytes().await?; - write_file_data(&path, &mut &*bytes).await + write_file_data(&path, &mut &*bytes) + .await .context("failed to write forum post image attachment") })); } for (id, name, url) in attachments { - let url = url.ok_or(anyhow!("attachment without href"))?; + let url = url.context("attachment without href")?; let src = URL::from_href(&url)?; let dl = ilias.download(&src.url).await?; let mut path = path.clone(); path.push(file_escape(&format!("{}_{}", id, name))); spawn!(handle_gracefully(async move { let bytes = dl.bytes().await?; - write_file_data(&path, &mut &*bytes).await + write_file_data(&path, &mut &*bytes) + .await .context("failed to write forum post file attachment") })); } @@ -524,11 +636,21 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future().trim().to_owned(); + let name = row + .select(&form_name) + .next() + .context("link without file name")? + .text() + .collect::() + .trim() + .to_owned(); let item = File { url, name }; let mut path = path.clone(); // handle files with the same name @@ -559,10 +681,8 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future { - e.url().context("HEAD request failed")?.as_str() - }, - Ok(head) => head.url().as_str() + Err(e) => e.url().context("HEAD request failed")?.as_str(), + Ok(head) => head.url().as_str(), }; if url.starts_with(ILIAS_URL) { // is a link list @@ -574,8 +694,16 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future()))) - .map(|(x, y)| URL::from_href(x).map(|z| (z, y.trim().to_owned())).context("parsing weblink")) + .filter_map(|x| { + x.value() + .attr("href") + .map(|y| (y, x.text().collect::())) + }) + .map(|(x, y)| { + URL::from_href(x) + .map(|z| (z, y.trim().to_owned())) + .context("parsing weblink") + }) .collect::>>() }?; @@ -585,8 +713,8 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future, mut path: PathBuf, obj: Object) -> impl Future { @@ -611,10 +739,10 @@ fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> impl Future { log!(1, "Ignored generic {:?}", obj) - } + }, } Ok(()) -}} +} #[derive(Debug, StructOpt)] #[structopt(name = env!("CARGO_PKG_NAME"))] @@ -643,7 +771,7 @@ struct Opt { #[structopt(long)] check_videos: bool, - /// Verbose logging (print objects downloaded) + /// Verbose logging #[structopt(short, multiple = true, parse(from_occurrences))] verbose: usize, @@ -656,8 +784,8 @@ struct Opt { jobs: usize, /// Proxy, e.g. socks5h://127.0.0.1:1080 - #[structopt(short, long, default_value = "")] - proxy: String, + #[structopt(short, long)] + proxy: Option, } struct ILIAS { @@ -666,27 +794,25 @@ struct ILIAS { // TODO: use these for re-authentication in case of session timeout/invalidation user: String, pass: String, - client: Client + client: Client, } impl ILIAS { - async fn login, S2: Into>(opt: Opt, user: S1, pass: S2, ignore: Gitignore) -> Result { + async fn login(opt: Opt, user: impl Into, pass: impl Into, ignore: Gitignore) -> Result { let user = user.into(); let pass = pass.into(); let mut builder = Client::builder() .cookie_store(true) .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); - if opt.proxy != "" { - let proxy = Proxy::all(&opt.proxy)?; + if let Some(proxy) = opt.proxy.as_ref() { + let proxy = Proxy::all(proxy)?; builder = builder.proxy(proxy); } let client = builder // timeout is infinite by default .build()?; - let this = ILIAS { - opt, client, user, pass, ignore - }; - println!("Logging into ILIAS using KIT account.."); + let this = ILIAS { opt, ignore, user, pass, client }; + info!("Logging into ILIAS using KIT account.."); let session_establishment = this.client .post("https://ilias.studium.kit.edu/Shibboleth.sso/Login") .form(&json!({ @@ -699,48 +825,41 @@ impl ILIAS { let url = session_establishment.url().clone(); let text = session_establishment.text().await?; let dom_sso = Html::parse_document(text.as_str()); - let csrf_token = dom_sso.select(&Selector::parse(r#"input[name="csrf_token"]"#).unwrap()).next().context("no csrf token")?; - println!("Logging into Shibboleth.."); + let csrf_token = dom_sso + .select(&Selector::parse(r#"input[name="csrf_token"]"#).unwrap()) + .next().context("no csrf token")?; + info!("Logging into Shibboleth.."); let login_response = this.client .post(url) .form(&json!({ "j_username": &this.user, "j_password": &this.pass, "_eventId_proceed": "", - "csrf_token": csrf_token.value().attr("value").ok_or(anyhow!("no csrf token"))?, + "csrf_token": csrf_token.value().attr("value").context("no csrf token")?, })) - .send().await?.text().await?; + .send().await? + .text().await?; let dom = Html::parse_document(&login_response); - /* TODO: OTP - login_soup = BeautifulSoup(login_response.text, 'lxml') - otp_inp = login_soup.find("input", attrs={"name": "j_tokenNumber"}) - if otp_inp: - print("OTP Detected.") - otp = input("OTP token: ") - otp_url = otp_inp.parent.parent.parent['action'] - otp_response = self.post('https://idp.scc.kit.edu'+otp_url, data={'j_tokenNumber':otp, "_eventId_proceed": ""}) - login_soup = BeautifulSoup(otp_response.text, 'lxml') - */ let saml = Selector::parse(r#"input[name="SAMLResponse"]"#).unwrap(); - let saml = dom.select(&saml).next().context("no SAML response, incorrect password?")?; + let saml = dom + .select(&saml) + .next().context("no SAML response, incorrect password?")?; let relay_state = Selector::parse(r#"input[name="RelayState"]"#).unwrap(); let relay_state = dom.select(&relay_state).next().context("no relay state")?; - println!("Logging into ILIAS.."); + info!("Logging into ILIAS.."); this.client .post("https://ilias.studium.kit.edu/Shibboleth.sso/SAML2/POST") .form(&json!({ - "SAMLResponse": saml.value().attr("value").ok_or(anyhow!("no SAML value"))?, - "RelayState": relay_state.value().attr("value").ok_or(anyhow!("no RelayState value"))? + "SAMLResponse": saml.value().attr("value").context("no SAML value")?, + "RelayState": relay_state.value().attr("value").context("no RelayState value")? })) .send().await?; - println!("{}", "Logged in!".bright_green()); - Ok(this) + success!("Logged in!"); + Ok(this) } async fn download(&self, url: &str) -> Result { - if self.opt.verbose > 1 { - println!("Downloading {}", url); - } + log!(2, "Downloading {}", url); if url.starts_with("http") || url.starts_with("ilias.studium.kit.edu") { Ok(self.client.get(url).send().await?) } else { @@ -771,13 +890,14 @@ impl ILIAS { fn get_items(html: &Html) -> Vec> { let container_items = Selector::parse("div.il_ContainerListItem").unwrap(); let container_item_title = Selector::parse("a.il_ContainerItemTitle").unwrap(); - html.select(&container_items).map(|item| { - item - .select(&container_item_title) - .next() - .map(|link| Object::from_link(item, link)) - .unwrap_or_else(|| Err(anyhow!("can't find link"))) - }).collect() + html.select(&container_items) + .map(|item| { + item.select(&container_item_title) + .next() + .map(|link| Object::from_link(item, link)) + .context("can't find link").flatten2() + }) + .collect() } async fn get_course_content(&self, url: &URL) -> Result>> { @@ -787,10 +907,11 @@ impl ILIAS { async fn personal_desktop(&self) -> Result { let html = self.get_html("https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems").await?; - let items = ILIAS::get_items(&html).into_iter().flat_map(Result::ok).collect(); - Ok(Dashboard { - items - }) + let items = ILIAS::get_items(&html) + .into_iter() + .flat_map(Result::ok) + .collect(); + Ok(Dashboard { items }) } async fn get_course_content_tree(&self, ref_id: &str, cmd_node: &str) -> Result> { @@ -803,12 +924,9 @@ impl ILIAS { let html = self.get_html_fragment(&url).await?; let mut items = Vec::new(); for link in html.select(&a) { - let href = link.value().attr("href").unwrap_or(""); - if href == "" { - // disabled course - continue; - } - items.push(Object::from_link(link, link)?); + if link.value().attr("href").is_some() { + items.push(Object::from_link(link, link)?); + } // else: disabled course } Ok(items) } @@ -816,61 +934,24 @@ impl ILIAS { #[derive(Debug)] struct Dashboard { - items: Vec + items: Vec, } #[derive(Debug)] enum Object { - Course { - name: String, - url: URL - }, - Folder { - name: String, - url: URL - }, - File { - name: String, - url: URL - }, - Forum { - name: String, - url: URL - }, - Thread { - url: URL - }, - Wiki { - name: String, - url: URL - }, - ExerciseHandler { - name: String, - url: URL - }, - Weblink { - name: String, - url: URL - }, - Survey { - name: String, - url: URL - }, - Presentation { - name: String, - url: URL - }, - PluginDispatch { - name: String, - url: URL - }, - Video { - url: URL, - }, - Generic { - name: String, - url: URL - }, + Course { name: String, url: URL }, + Folder { name: String, url: URL }, + File { name: String, url: URL }, + Forum { name: String, url: URL }, + Thread { url: URL }, + Wiki { name: String, url: URL }, + ExerciseHandler { name: String, url: URL }, + Weblink { name: String, url: URL }, + Survey { name: String, url: URL }, + Presentation { name: String, url: URL }, + PluginDispatch { name: String, url: URL }, + Video { url: URL }, + Generic { name: String, url: URL }, } use Object::*; @@ -878,17 +959,17 @@ use Object::*; impl Object { fn name(&self) -> &str { match self { - Course { name, .. } | - Folder { name, .. } | - File { name, .. } | - Forum { name, .. } | - Wiki { name, .. } | - Weblink { name, ..} | - Survey { name, .. } | - Presentation { name, .. } | - ExerciseHandler { name, .. } | - PluginDispatch { name, .. } | - Generic { name, .. } => &name, + Course { name, .. } + | Folder { name, .. } + | File { name, .. } + | Forum { name, .. } + | Wiki { name, .. } + | Weblink { name, .. } + | Survey { name, .. } + | Presentation { name, .. } + | ExerciseHandler { name, .. } + | PluginDispatch { name, .. } + | Generic { name, .. } => &name, Thread { url } => &url.thr_pk.as_ref().unwrap(), Video { url } => &url.url, } @@ -896,19 +977,19 @@ impl Object { fn url(&self) -> &URL { match self { - Course { url, .. } | - Folder { url, .. } | - File { url, .. } | - Forum { url, .. } | - Thread { url } | - Wiki { url, .. } | - Weblink { url, .. } | - Survey { url, .. } | - Presentation { url, .. } | - ExerciseHandler { url, .. } | - PluginDispatch { url, .. } | - Video { url } | - Generic { url, .. } => &url, + Course { url, .. } + | Folder { url, .. } + | File { url, .. } + | Forum { url, .. } + | Thread { url } + | Wiki { url, .. } + | Weblink { url, .. } + | Survey { url, .. } + | Presentation { url, .. } + | ExerciseHandler { url, .. } + | PluginDispatch { url, .. } + | Video { url } + | Generic { url, .. } => &url, } } @@ -932,97 +1013,88 @@ impl Object { fn is_dir(&self) -> bool { match self { - Course { .. } | - Folder { .. } | - Forum { .. } | - Thread { .. } | - Wiki { .. } | - ExerciseHandler { .. } | - Presentation { .. } | - PluginDispatch { .. } => true, - File { .. } | - Video { .. } | - Weblink { .. } | - Survey { .. } | - Generic { .. } => false + Course { .. } + | Folder { .. } + | Forum { .. } + | Thread { .. } + | Wiki { .. } + | ExerciseHandler { .. } + | Presentation { .. } + | PluginDispatch { .. } => true, + File { .. } | Video { .. } | Weblink { .. } | Survey { .. } | Generic { .. } => false, } } fn from_link(item: ElementRef, link: ElementRef) -> Result { - let mut name = link.text().collect::().replace('/', "-").trim().to_owned(); + let mut name = link + .text() + .collect::() + .replace('/', "-") + .trim() + .to_owned(); let mut url = URL::from_href(link.value().attr("href").context("link missing href")?)?; if url.thr_pk.is_some() { - return Ok(Thread { - url - }); + return Ok(Thread { url }); } - if url.url.starts_with("https://ilias.studium.kit.edu/goto.php") { + if url + .url + .starts_with("https://ilias.studium.kit.edu/goto.php") + { let target = url.target.as_deref().unwrap_or("NONE"); if target.starts_with("wiki_") { return Ok(Wiki { name, - url // TODO: insert ref_id here + url, // TODO: insert ref_id here }); } if target.starts_with("root_") { // magazine link - return Ok(Generic { - name, - url - }); + return Ok(Generic { name, url }); } if target.starts_with("crs_") { let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); url.ref_id = ref_id.to_owned(); - return Ok(Course { - name, - url - }); + return Ok(Course { name, url }); } if target.starts_with("frm_") { // TODO: extract post link? (this codepath should only be hit when parsing the content tree) let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); url.ref_id = ref_id.to_owned(); - return Ok(Forum { - name, - url - }); + return Ok(Forum { name, url }); } if target.starts_with("lm_") { // fancy interactive task - return Ok(Presentation { - name, - url - }); + return Ok(Presentation { name, url }); } if target.starts_with("fold_") { let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); url.ref_id = ref_id.to_owned(); - return Ok(Folder { - name, - url - }); + return Ok(Folder { name, url }); } if target.starts_with("file_") { if !target.ends_with("download") { // download page containing metadata - return Ok(Generic { - name, - url - }); + return Ok(Generic { name, url }); } else { let item_prop = Selector::parse("span.il_ItemProperty").unwrap(); let mut item_props = item.select(&item_prop); - let ext = item_props.next().ok_or(anyhow!("cannot find file extension"))?; - let version = item_props.nth(1).ok_or(anyhow!("cannot find 3rd file metadata"))?.text().collect::(); + let ext = item_props.next().context("cannot find file extension")?; + let version = item_props + .nth(1) + .context("cannot find 3rd file metadata")? + .text() + .collect::(); let version = version.trim(); - if version.starts_with("Version: ") { - name.push_str("_v"); - name.push_str(&version[9..]); + if let Some(v) = version.strip_prefix("Version: ") { + name += "_v"; + name += v; } - return Ok(File { name: format!("{}.{}", name, ext.text().collect::().trim()), url }); + return Ok(File { + name: format!("{}.{}", name, ext.text().collect::().trim()), + url, + }); } } return Ok(Generic { name, url }); @@ -1045,7 +1117,7 @@ impl Object { None => Course { name, url }, }, "ilobjplugindispatchgui" => PluginDispatch { name, url }, - _ => Generic { name, url } + _ => Generic { name, url }, }) } } @@ -1112,7 +1184,7 @@ impl URL { "ref_id" => ref_id = v.into_owned(), "target" => target = Some(v.into_owned()), "file" => file = Some(v.into_owned()), - _ => {} + _ => {}, } } Ok(URL { @@ -1132,9 +1204,9 @@ impl URL { } #[cfg(not(target_os = "windows"))] -const INVALID: &'static [char] = &['/', '\\']; +const INVALID: &[char] = &['/', '\\']; #[cfg(target_os = "windows")] -const INVALID: &'static [char] = &['/', '\\', ':', '<', '>', '"', '|', '?', '*']; +const INVALID: &[char] = &['/', '\\', ':', '<', '>', '"', '|', '?', '*']; fn file_escape(s: &str) -> String { s.replace(INVALID, "-") diff --git a/src/util.rs b/src/util.rs index c9c5a00..5cf3bba 100644 --- a/src/util.rs +++ b/src/util.rs @@ -23,3 +23,37 @@ pub async fn create_dir(path: &Path) -> Result<()> { } Ok(()) } + +// remove once result_flattening is stable (https://github.com/rust-lang/rust/issues/70142) +pub trait Result2 { + type V; + type E; + type F; + + fn flatten2(self) -> Result + where + Self::F: Into; + + fn flatten_with Self::E>(self, op: O) -> Result; +} + +impl Result2 for Result, E> { + type V = V; + type E = E; + type F = F; + + fn flatten2(self) -> Result + where + Self::F: Into, + { + self.flatten_with(|e| e.into()) + } + + fn flatten_with Self::E>(self, op: O) -> Result { + match self { + Ok(Ok(v)) => Ok(v), + Ok(Err(f)) => Err(op(f)), + Err(e) => Err(e), + } + } +} From d087ea0e92584371e34a79f6a467f9cca46e6508 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 17 Apr 2021 15:38:18 +0200 Subject: [PATCH 016/103] Keyring authentication + username/password options --- Cargo.lock | 348 ++++++++++++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 6 + src/main.rs | 61 ++++++++- 3 files changed, 388 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c2a5cf..0584a59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,11 +7,13 @@ name = "KIT-ILIAS-downloader" version = "0.2.15" dependencies = [ "anyhow", + "cfg-if", "colored", "futures", "futures-channel", "futures-util", "ignore", + "keyring", "lazy_static", "parking_lot", "regex", @@ -32,6 +34,37 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aes" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" +dependencies = [ + "aes-soft", + "aesni", + "cipher", +] + +[[package]] +name = "aes-soft" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" +dependencies = [ + "cipher", + "opaque-debug", +] + +[[package]] +name = "aesni" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" +dependencies = [ + "cipher", + "opaque-debug", +] + [[package]] name = "aho-corasick" version = "0.7.15" @@ -104,6 +137,31 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-modes" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a0e8073e8baa88212fb5823574c02ebccb395136ba9a164ab89379ec6072f0" +dependencies = [ + "block-padding", + "cipher", +] + +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + [[package]] name = "bstr" version = "0.2.15" @@ -143,6 +201,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cipher" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array", +] + [[package]] name = "clap" version = "2.33.3" @@ -208,6 +275,28 @@ dependencies = [ "url", ] +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + [[package]] name = "crc32fast" version = "1.2.1" @@ -228,6 +317,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-mac" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" +dependencies = [ + "generic-array", + "subtle", +] + [[package]] name = "cssparser" version = "0.27.2" @@ -255,6 +354,15 @@ dependencies = [ "syn", ] +[[package]] +name = "dbus" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4a0c10ea61042b7555729ab0608727bbbb06ce709c11e6047cfa4e10f6d052d" +dependencies = [ + "libc", +] + [[package]] name = "derive_more" version = "0.99.13" @@ -267,6 +375,15 @@ dependencies = [ "syn", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "discard" version = "1.0.4" @@ -448,6 +565,16 @@ dependencies = [ "byteorder", ] +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getopts" version = "0.2.21" @@ -524,6 +651,26 @@ dependencies = [ "libc", ] +[[package]] +name = "hkdf" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" +dependencies = [ + "digest", + "hmac", +] + +[[package]] +name = "hmac" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" +dependencies = [ + "crypto-mac", + "digest", +] + [[package]] name = "html5ever" version = "0.25.1" @@ -562,9 +709,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.6" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc35c995b9d93ec174cf9a27d425c7892722101e14993cd227fdb51d70cf9589" +checksum = "4a1ce40d6fc9764887c2fdc7305c3dcc429ba11ff981c1509416afd5697e4437" [[package]] name = "httpdate" @@ -613,9 +760,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" dependencies = [ "matches", "unicode-bidi", @@ -680,6 +827,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "keyring" +version = "0.10.1" +source = "git+https://github.com/FliegendeWurst/keyring-rs?branch=application-name#292611fb9c64cb715d9a2e2b8f0f35edfeb7ea0a" +dependencies = [ + "byteorder", + "secret-service", + "security-framework", + "winapi", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -804,6 +962,82 @@ dependencies = [ "winapi", ] +[[package]] +name = "num" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b7a8e9be5e039e2ff869df49155f1c06bd01ade2117ec783e56ab0932b67a8f" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d0a3d5e207573f948a9e5376662aa743a2ea13f7c50a554d7af443a73fbfeba" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.13.0" @@ -820,6 +1054,12 @@ version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "parking_lot" version = "0.11.1" @@ -907,18 +1147,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6" +checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5" +checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" dependencies = [ "proc-macro2", "quote", @@ -1066,9 +1306,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" dependencies = [ "bitflags", ] @@ -1092,9 +1332,9 @@ checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "reqwest" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" +checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" dependencies = [ "async-compression", "base64", @@ -1174,9 +1414,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.19.0" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ "base64", "log", @@ -1224,14 +1464,53 @@ dependencies = [ [[package]] name = "sct" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" dependencies = [ "ring", "untrusted", ] +[[package]] +name = "secret-service" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d752040301c251d653aa740dec847e95767ce312cfc469bee85eb13cbf81d8a" +dependencies = [ + "aes", + "block-modes", + "dbus", + "hkdf", + "lazy_static", + "num", + "rand", + "sha2", +] + +[[package]] +name = "security-framework" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "selectors" version = "0.22.0" @@ -1326,6 +1605,19 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" +[[package]] +name = "sha2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" +dependencies = [ + "block-buffer", + "cfg-if", + "cpuid-bool", + "digest", + "opaque-debug", +] + [[package]] name = "siphasher" version = "0.3.5" @@ -1479,6 +1771,12 @@ dependencies = [ "syn", ] +[[package]] +name = "subtle" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" + [[package]] name = "syn" version = "1.0.69" @@ -1600,9 +1898,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722" +checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" dependencies = [ "autocfg", "bytes", @@ -1650,9 +1948,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5143d049e85af7fbc36f5454d990e62c2df705b3589f123b71f441b6b59f443f" +checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" dependencies = [ "bytes", "futures-core", @@ -1694,6 +1992,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "typenum" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" + [[package]] name = "unicode-bidi" version = "0.3.5" @@ -1750,9 +2054,9 @@ dependencies = [ [[package]] name = "utf-8" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "vec_map" diff --git a/Cargo.toml b/Cargo.toml index e0cc546..a07c75c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,9 @@ rprompt = "1.0.5" ignore = "0.4.14" anyhow = "1.0.28" colored = "2.0.0" +keyring = { git = "https://github.com/FliegendeWurst/keyring-rs", branch = "application-name", optional = true } +cfg-if = "1.0.0" + +[features] +default = [] +keyring-auth = ["keyring"] diff --git a/src/main.rs b/src/main.rs index 64e572a..788764a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,7 +111,7 @@ async fn main() { let pass = pass.trim(); (user.to_owned(), pass.to_owned()) } else { - ask_user_pass() + ask_user_pass(&opt).expect("credentials input") }; opt.output.pop(); @@ -171,10 +171,48 @@ macro_rules! spawn { }; } -fn ask_user_pass() -> (String, String) { - let user = rprompt::prompt_reply_stdout("Username: ").expect("username prompt"); - let pass = rpassword::read_password_from_tty(Some("Password: ")).expect("password prompt"); - (user, pass) +fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { + let user = if let Some(username) = opt.username.as_ref() { + username.clone() + } else { + rprompt::prompt_reply_stdout("Username: ").context("username prompt")? + }; + #[cfg(feature = "keyring-auth")] + let (pass, should_store); + #[cfg(not(feature = "keyring-auth"))] + let pass; + cfg_if::cfg_if! { // TODO: deduplicate the logic below + if #[cfg(feature = "keyring-auth")] { + if let Some(password) = opt.password.as_ref() { + pass = password.clone(); + should_store = true; + } else if opt.keyring { + let keyring = keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user); + if let Ok(password) = keyring.get_password() { + pass = password; + should_store = false; + } else { + pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; + should_store = true; + } + } else { + pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; + should_store = true; + } + } else { + if let Some(password) = opt.password.as_ref() { + pass = password.clone(); + } else { + pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; + } + } + }; + #[cfg(feature = "keyring-auth")] + if should_store && opt.keyring { + let keyring = keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user); + keyring.set_password(&pass).map_err(|x| anyhow!(x.to_string()))?; + } + Ok((user, pass)) } // https://github.com/rust-lang/rust/issues/53690#issuecomment-418911229 @@ -786,6 +824,19 @@ struct Opt { /// Proxy, e.g. socks5h://127.0.0.1:1080 #[structopt(short, long)] proxy: Option, + + /// Use the system keyring + #[structopt(long)] + #[cfg(feature = "keyring-auth")] + keyring: bool, + + /// KIT account username + #[structopt(short = "U", long)] + username: Option, + + /// KIT account password + #[structopt(short = "P", long)] + password: Option, } struct ILIAS { From 450b0d92843152cc6ff00a945d8867c3c1b34796 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 17 Apr 2021 15:40:08 +0200 Subject: [PATCH 017/103] CI: test keyring feature --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20334cb..c693da6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] + features: ["", "--features keyring-auth"] steps: - uses: actions/checkout@v2 @@ -38,11 +39,14 @@ jobs: with: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - name: Install dbus + run: sudo apt-get install -y libdbus-1-dev + if: runner.os == 'Linux' - name: Build - run: cargo build --release --verbose + run: cargo build --release ${{ matrix.features }} --verbose # there are currently no automated tests - name: Run tests - run: cargo test --release --verbose + run: cargo test --release ${{ matrix.features }} --verbose - name: Archive artifacts uses: actions/upload-artifact@v2 with: From a05ea16d833076939414c3e4fda061d2501fe0a7 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 19 Apr 2021 10:33:46 +0200 Subject: [PATCH 018/103] --sync-url option --- src/main.rs | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 788764a..b51f4d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,19 +129,29 @@ async fn main() { } } let ilias = Arc::new(ilias); - let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop"); let (tx, mut rx) = futures_channel::mpsc::unbounded::>(); *TASKS.lock() = Some(tx.clone()); - match desktop { - Ok(desktop) => { - for item in desktop.items { - let mut path = ilias.opt.output.clone(); - path.push(file_escape(item.name())); - let ilias = Arc::clone(&ilias); - let _ = tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))); - } - }, - Err(e) => error!(e), + if let Some(url) = ilias.opt.sync_url.as_ref() { + for item in ilias.get_course_content(&URL::from_href(url).expect("invalid URL")).await.expect("invalid response") { + let item = item.expect("invalid item"); + let ilias = Arc::clone(&ilias); + let mut path = ilias.opt.output.clone(); + path.push(file_escape(item.name())); + tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))).unwrap(); + } + } else { + let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop"); + match desktop { + Ok(desktop) => { + for item in desktop.items { + let mut path = ilias.opt.output.clone(); + path.push(file_escape(item.name())); + let ilias = Arc::clone(&ilias); + let _ = tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))); + } + }, + Err(e) => error!(e), + } } while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await { if let Some(task) = task { @@ -837,6 +847,10 @@ struct Opt { /// KIT account password #[structopt(short = "P", long)] password: Option, + + /// ILIAS page to download + #[structopt(long)] + sync_url: Option, } struct ILIAS { From e397ecf73b5f39274c2564fb6430eb75e76325f5 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 19 Apr 2021 10:54:26 +0200 Subject: [PATCH 019/103] Document more functionality --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 39 +++++++++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0584a59..b325969 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.15" +version = "0.2.16" dependencies = [ "anyhow", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index a07c75c..63e0bac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.15" +version = "0.2.16" authors = ["FliegendeWurst <2012gdwu@web.de>"] license = "GPL-2.0" edition = "2018" diff --git a/README.md b/README.md index 67087c6..68a86da 100644 --- a/README.md +++ b/README.md @@ -9,44 +9,59 @@ Download content from ILIAS. That includes: ## Installation -Go to the [releases](../../releases) and get the executable for your operating system. Or compile from source: +Go to the [releases](../../releases) and get the executable for your operating system (Windows/Linux only). +Or compile from source (mandatory if you use a Mac): ``` $ git clone https://github.com/FliegendeWurst/KIT-ILIAS-downloader $ cd KIT-ILIAS-downloader -$ cargo install --path . +$ cargo install --all-features --path . ``` ## Usage +First, open a terminal (use Powershell on Windows). + Use `-o ` to specify the download directory: ``` $ KIT-ILIAS-downloader -o ./ILIAS ``` -Only content on your [personal desktop](https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems) will be downloaded. +By default, only content on your [personal desktop](https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems) will be downloaded. +Use the `--sync-url` option to download a specific page and its sub-pages: (the URL should be copied from an ILIAS link, not the browser URL bar) + +``` +$ KIT-ILIAS-downloader -o ./ILIAS/WS2021-HM1 --sync-url 'https://ilias.studium.kit.edu/ilias.php?ref_id=1276968&cmdClass=ilrepositorygui&cmdNode=uk&baseClass=ilRepositoryGUI' +``` + +### Options ``` $ KIT-ILIAS-downloader --help -KIT-ILIAS-downloader 0.2.14 +KIT-ILIAS-downloader 0.2.16 USAGE: KIT-ILIAS-downloader [FLAGS] [OPTIONS] --output FLAGS: + --check-videos Re-check OpenCast lectures (slow) --content-tree Use content tree (slow but thorough) -f Re-download already present files -t, --forum Download forum content -h, --help Prints help information + --keyring Use the system keyring -n, --no-videos Do not download Opencast videos -s, --skip-files Do not download files -V, --version Prints version information - -v Verbose logging (print objects downloaded) + -v Verbose logging OPTIONS: - -j, --jobs Parallel download jobs [default: 1] - -o, --output Output directory - -p, --proxy Proxy, e.g. socks5h://127.0.0.1:1080 [default: ""] + -j, --jobs Parallel download jobs [default: 1] + -o, --output Output directory + -P, --password KIT account password + -p, --proxy Proxy, e.g. socks5h://127.0.0.1:1080 + --sync-url ILIAS page to download + -U, --username KIT account username ``` ### .iliasignore @@ -61,10 +76,14 @@ OPTIONS: !/Course/Tutorien/Tut* 3/ ``` -### .iliaslogin +### Credentials -If you don't want to enter your credentials every time you run the program, you can instead save your username and password in a file (`.iliaslogin`): +You can use the `--user` and `--keyring` options to get/store the password using the system password store: +``` +$ KIT-ILIAS-downloader -U uabcd --keyring [...] +``` +You can also save your username and password in a `.iliaslogin` file: ``` username password From dd37cc9d91662d51fa05769e6ca6d9ebd3ed0541 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 19 Apr 2021 11:15:55 +0200 Subject: [PATCH 020/103] Fix colors on windows --- README.md | 5 +++-- build.sh | 2 +- src/main.rs | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 68a86da..cc7b1d0 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ $ cargo install --all-features --path . ## Usage -First, open a terminal (use Powershell on Windows). +First, open a terminal. Navigate to the directory that contains the downloaded binary. Use `-o ` to specify the download directory: @@ -78,7 +78,8 @@ OPTIONS: ### Credentials -You can use the `--user` and `--keyring` options to get/store the password using the system password store: +You can use the `--user` and `--keyring` options to get/store the password using the system password store. +If you use Linux, you'll have to compile from source to be able to use this option. ``` $ KIT-ILIAS-downloader -U uabcd --keyring [...] ``` diff --git a/build.sh b/build.sh index 0308c49..bf6e62b 100755 --- a/build.sh +++ b/build.sh @@ -6,5 +6,5 @@ strip target/release/KIT-ILIAS-downloader rustup target add x86_64-pc-windows-gnu # if on Debian or similar sudo apt install mingw-w64 -cargo build --release --target x86_64-pc-windows-gnu +cargo build --release --all-features --target x86_64-pc-windows-gnu strip target/x86_64-pc-windows-gnu/release/KIT-ILIAS-downloader diff --git a/src/main.rs b/src/main.rs index b51f4d1..9d103ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,6 +81,8 @@ macro_rules! error { #[tokio::main] async fn main() { let mut opt = Opt::from_args(); + #[cfg(windows)] + colored::control::set_virtual_terminal(true); // use UNC paths on Windows opt.output = fs::canonicalize(opt.output).await.expect("failed to canonicalize directory"); LOG_LEVEL.store(opt.verbose, Ordering::SeqCst); From bcc16f1ec51e994130e36b9b294bd68ca6196d9f Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 19 Apr 2021 12:32:35 +0200 Subject: [PATCH 021/103] Use async semaphore to limit parallel jobs --- src/main.rs | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9d103ee..6e2dbd7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,18 +12,16 @@ use reqwest::{Client, Proxy}; use scraper::{ElementRef, Html, Selector}; use serde_json::json; use structopt::StructOpt; -use tokio::fs; +use tokio::{fs, sync::Semaphore}; use tokio::task::{self, JoinHandle}; use tokio_util::io::StreamReader; use url::Url; use std::future::Future; use std::io; -use std::panic; use std::path::PathBuf; use std::sync::atomic::Ordering; use std::sync::Arc; -use std::time::Duration; use std::{collections::HashSet, default::Default, sync::atomic::AtomicUsize}; mod util; @@ -82,18 +80,11 @@ macro_rules! error { async fn main() { let mut opt = Opt::from_args(); #[cfg(windows)] - colored::control::set_virtual_terminal(true); + let _ = colored::control::set_virtual_terminal(true); // use UNC paths on Windows opt.output = fs::canonicalize(opt.output).await.expect("failed to canonicalize directory"); LOG_LEVEL.store(opt.verbose, Ordering::SeqCst); create_dir(&opt.output).await.expect("failed to create output directory"); - // need this because task scheduling is WIP - // (would wait forever on paniced task) - *PANIC_HOOK.lock() = panic::take_hook(); - panic::set_hook(Box::new(|info| { - *TASKS_RUNNING.lock() -= 1; - PANIC_HOOK.lock()(info); - })); // load .iliasignore file opt.output.push(".iliasignore"); @@ -133,6 +124,7 @@ async fn main() { let ilias = Arc::new(ilias); let (tx, mut rx) = futures_channel::mpsc::unbounded::>(); *TASKS.lock() = Some(tx.clone()); + TASKS_RUNNING.add_permits(ilias.opt.jobs); if let Some(url) = ilias.opt.sync_url.as_ref() { for item in ilias.get_course_content(&URL::from_href(url).expect("invalid URL")).await.expect("invalid response") { let item = item.expect("invalid item"); @@ -173,13 +165,12 @@ async fn main() { lazy_static! { static ref TASKS: Mutex>>> = Mutex::default(); - static ref TASKS_RUNNING: Mutex = Mutex::default(); - static ref PANIC_HOOK: Mutex> = Mutex::new(Box::new(|_| {})); + static ref TASKS_RUNNING: Semaphore = Semaphore::new(0); } macro_rules! spawn { ($e:expr) => { - let _ = TASKS.lock().as_ref().unwrap().unbounded_send(task::spawn($e)); + TASKS.lock().as_ref().unwrap().unbounded_send(task::spawn($e)).unwrap(); }; } @@ -234,22 +225,12 @@ fn process_gracefully( path: PathBuf, obj: Object, ) -> impl Future + Send { async move { - loop { - { - // limit scope of lock - let mut running = TASKS_RUNNING.lock(); - if *running < ilias.opt.jobs { - *running += 1; - break; - } - } - tokio::time::sleep(Duration::from_millis(50)).await; - } + let permit = TASKS_RUNNING.acquire().await.unwrap(); let path_text = path.to_string_lossy().into_owned(); if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { error!("Syncing {}", path_text; e); } - *TASKS_RUNNING.lock() -= 1; + drop(permit); }} async fn handle_gracefully(fut: impl Future>) { From 5ef486244e23029af340f1b31af1077defb575eb Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 19 Apr 2021 18:27:59 +0200 Subject: [PATCH 022/103] Fix warning when downloading forum 'unusual table row (2 cells)' was caused by the thread count above the main table 'unusual table row (0 cells)' was caused by the table header --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6e2dbd7..cb741cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,6 +252,7 @@ mod selectors { pub static ref table: Selector = Selector::parse("table").unwrap(); pub static ref video_tr: Selector = Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap(); pub static ref links_in_table: Selector = Selector::parse("tbody tr td a").unwrap(); + pub static ref th: Selector = Selector::parse("th").unwrap(); pub static ref td: Selector = Selector::parse("td").unwrap(); pub static ref tr: Selector = Selector::parse("tr").unwrap(); pub static ref post_row: Selector = Selector::parse(".ilFrmPostRow").unwrap(); @@ -479,6 +480,12 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() Html::parse_document(&html) }; for row in html.select(&tr) { + if row.value().attr("class") == Some("hidden-print") { + continue; // thread count + } + if row.select(&th).next().is_some() { + continue; // table header + } let cells = row.select(&td).collect::>(); if cells.len() != 6 { log!( From 3ece654b52d9ea2062fca14e145eb1dc347c78dc Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 19 Apr 2021 18:46:51 +0200 Subject: [PATCH 023/103] Fix empty forum warning --- src/main.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index cb741cd..b161df7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -272,6 +272,8 @@ mod selectors { } use crate::selectors::*; +const NO_ENTRIES: &str = "Keine Einträge"; + async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<()> { let relative_path = path.strip_prefix(&ilias.opt.output).unwrap(); if ilias.ignore.matched(relative_path, obj.is_dir()).is_ignore() { @@ -375,7 +377,7 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() for row in html.select(&video_tr) { let link = row.select(&a_target_blank).next(); if link.is_none() { - if !row.text().any(|x| x == "Keine Einträge") { + if !row.text().any(|x| x == NO_ENTRIES) { warning!(format => "table row without link in {}", url.url); } continue; @@ -469,9 +471,17 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() let url = { let html = Html::parse_document(&html_text); //https://ilias.studium.kit.edu/ilias.php?ref_id=122&cmdClass=ilobjforumgui&frm_tt_e39_122_trows=800&cmd=showThreads&cmdNode=uf:lg&baseClass=ilrepositorygui - html.select(&a) + let thread_count_selector = html.select(&a) .flat_map(|x| x.value().attr("href")) - .find(|x| x.contains("trows=800")) + .find(|x| x.contains("trows=800")); + if thread_count_selector.is_none() { + if let Some(cell) = html.select(&td).next() { + if cell.text().any(|x| x == NO_ENTRIES) { + return Ok(()); // empty forum + } + } + } + thread_count_selector .context("can't find forum thread count selector (empty forum?)")? .to_owned() }; From f291bcbb4b3ff7fd7320a44891756c5c419902ec Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 19 Apr 2021 18:47:19 +0200 Subject: [PATCH 024/103] Handle external images in forum posts --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index b161df7..7fa469e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -640,12 +640,15 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() for (id, image) in all_images { let src = URL::from_href(&image)?; let dl = ilias.download(&src.url).await?; - let m = image_src_regex - .captures(&image) - .context(format!("image src {} unexpected format", image))?; - let (media_id, filename) = (m.get(1).unwrap().as_str(), m.get(2).unwrap().as_str()); let mut path = path.clone(); - path.push(file_escape(&format!("{}_{}_{}", id, media_id, filename))); + if let Some(m) = image_src_regex.captures(&image) { + // image uploaded to ILIAS + let (media_id, filename) = (m.get(1).unwrap().as_str(), m.get(2).unwrap().as_str()); + path.push(file_escape(&format!("{}_{}_{}", id, media_id, filename))); + } else { + // external image + path.push(file_escape(&format!("{}_{}", id, image))); + } spawn!(handle_gracefully(async move { let bytes = dl.bytes().await?; write_file_data(&path, &mut &*bytes) From 5c17ec0326e862c933564b699b8eab23d97f3fd5 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 21 Apr 2021 20:18:54 +0200 Subject: [PATCH 025/103] Display a progress bar if possible (experimental) --- Cargo.lock | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 5 ++++- src/main.rs | 31 ++++++++++++++++++++++++++-- 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b325969..e51e275 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,14 +7,17 @@ name = "KIT-ILIAS-downloader" version = "0.2.16" dependencies = [ "anyhow", + "atty", "cfg-if", "colored", "futures", "futures-channel", "futures-util", "ignore", + "indicatif", "keyring", "lazy_static", + "once_cell", "parking_lot", "regex", "reqwest", @@ -237,10 +240,25 @@ dependencies = [ ] [[package]] -name = "const_fn" -version = "0.4.6" +name = "console" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076a6803b0dacd6a88cfe64deba628b01533ff5ef265687e6938280c1afd0a28" +checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "regex", + "terminal_size", + "unicode-width", + "winapi", +] + +[[package]] +name = "const_fn" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402da840495de3f976eaefc3485b7f5eb5b0bf9761f9a47be27fe975b3b8c2ec" [[package]] name = "convert_case" @@ -417,6 +435,12 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.28" @@ -797,6 +821,18 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indicatif" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7baab56125e25686df467fe470785512329883aab42696d661247aca2a2896e4" +dependencies = [ + "console", + "lazy_static", + "number_prefix", + "regex", +] + [[package]] name = "instant" version = "0.1.9" @@ -1048,6 +1084,12 @@ dependencies = [ "libc", ] +[[package]] +name = "number_prefix" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" + [[package]] name = "once_cell" version = "1.7.2" @@ -1799,6 +1841,16 @@ dependencies = [ "utf-8", ] +[[package]] +name = "terminal_size" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 63e0bac..e1df44a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "KIT-ILIAS-downloader" version = "0.2.16" -authors = ["FliegendeWurst <2012gdwu@web.de>"] +authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-2.0" edition = "2018" @@ -28,6 +28,9 @@ anyhow = "1.0.28" colored = "2.0.0" keyring = { git = "https://github.com/FliegendeWurst/keyring-rs", branch = "application-name", optional = true } cfg-if = "1.0.0" +indicatif = "0.15.0" +once_cell = "1.7.2" +atty = "0.2.14" [features] default = [] diff --git a/src/main.rs b/src/main.rs index 7fa469e..e205b03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,9 @@ use futures::future::{self, Either}; use futures_channel::mpsc::UnboundedSender; use futures_util::{stream::TryStreamExt, StreamExt}; use ignore::gitignore::Gitignore; +use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; use lazy_static::lazy_static; +use once_cell::sync::Lazy; use parking_lot::Mutex; use reqwest::{Client, Proxy}; use scraper::{ElementRef, Html, Selector}; @@ -17,7 +19,7 @@ use tokio::task::{self, JoinHandle}; use tokio_util::io::StreamReader; use url::Url; -use std::future::Future; +use std::{future::Future, sync::atomic::AtomicBool}; use std::io; use std::path::PathBuf; use std::sync::atomic::Ordering; @@ -30,12 +32,18 @@ use util::*; const ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; static LOG_LEVEL: AtomicUsize = AtomicUsize::new(0); +static PROGRESS_BAR_ENABLED: AtomicBool = AtomicBool::new(false); +static PROGRESS_BAR: Lazy = Lazy::new(|| ProgressBar::new(0)); macro_rules! log { ($lvl:expr, $($t:expr),+) => { #[allow(unused_comparisons)] // 0 <= 0 if $lvl <= LOG_LEVEL.load(Ordering::SeqCst) { - println!($($t),+); + if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { + PROGRESS_BAR.println(format!($($t),+)); + } else { + println!($($t),+); + } } } } @@ -125,6 +133,13 @@ async fn main() { let (tx, mut rx) = futures_channel::mpsc::unbounded::>(); *TASKS.lock() = Some(tx.clone()); TASKS_RUNNING.add_permits(ilias.opt.jobs); + PROGRESS_BAR_ENABLED.store(atty::is(atty::Stream::Stdout), Ordering::SeqCst); + if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { + PROGRESS_BAR.set_draw_target(ProgressDrawTarget::stderr_nohz()); + PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}+] {msg}")); + PROGRESS_BAR.inc_length(1); + PROGRESS_BAR.set_message("initializing.."); + } if let Some(url) = ilias.opt.sync_url.as_ref() { for item in ilias.get_course_content(&URL::from_href(url).expect("invalid URL")).await.expect("invalid response") { let item = item.expect("invalid item"); @@ -161,6 +176,11 @@ async fn main() { warning!("could not disable content tree:", e); } } + if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { + PROGRESS_BAR.inc(1); + PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}] {msg}")); + PROGRESS_BAR.finish_with_message("done"); + } } lazy_static! { @@ -225,6 +245,9 @@ fn process_gracefully( path: PathBuf, obj: Object, ) -> impl Future + Send { async move { + if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { + PROGRESS_BAR.inc_length(1); + } let permit = TASKS_RUNNING.acquire().await.unwrap(); let path_text = path.to_string_lossy().into_owned(); if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { @@ -276,6 +299,10 @@ const NO_ENTRIES: &str = "Keine Einträge"; async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<()> { let relative_path = path.strip_prefix(&ilias.opt.output).unwrap(); + if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { + PROGRESS_BAR.inc(1); + PROGRESS_BAR.set_message(&relative_path.display().to_string()); + } if ilias.ignore.matched(relative_path, obj.is_dir()).is_ignore() { log!(1, "Ignored {}", relative_path.to_string_lossy()); return Ok(()); From e94ce978963ed9d03af2b648dcd5f6fd655c1967 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 21 Apr 2021 21:04:45 +0200 Subject: [PATCH 026/103] Handle disabled links + save main course page + misc. cleanups --- Cargo.lock | 1 - Cargo.toml | 1 - src/main.rs | 125 ++++++++++++++++++++++++++-------------------------- 3 files changed, 62 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e51e275..6948942 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,6 @@ dependencies = [ "ignore", "indicatif", "keyring", - "lazy_static", "once_cell", "parking_lot", "regex", diff --git a/Cargo.toml b/Cargo.toml index e1df44a..100f484 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ futures = "0.3.8" futures-util = "0.3.8" futures-channel = "0.3.8" regex = "1.3.7" -lazy_static = "1.4.0" parking_lot = "0.11.0" structopt = "0.3.13" rpassword = "5.0.0" diff --git a/src/main.rs b/src/main.rs index e205b03..b598ea5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ use futures_channel::mpsc::UnboundedSender; use futures_util::{stream::TryStreamExt, StreamExt}; use ignore::gitignore::Gitignore; use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; -use lazy_static::lazy_static; use once_cell::sync::Lazy; use parking_lot::Mutex; use reqwest::{Client, Proxy}; @@ -35,6 +34,10 @@ static LOG_LEVEL: AtomicUsize = AtomicUsize::new(0); static PROGRESS_BAR_ENABLED: AtomicBool = AtomicBool::new(false); static PROGRESS_BAR: Lazy = Lazy::new(|| ProgressBar::new(0)); +/// Global job queue +static TASKS: Lazy>>>> = Lazy::new(Mutex::default); +static TASKS_RUNNING: Lazy = Lazy::new(|| Semaphore::new(0)); + macro_rules! log { ($lvl:expr, $($t:expr),+) => { #[allow(unused_comparisons)] // 0 <= 0 @@ -141,12 +144,18 @@ async fn main() { PROGRESS_BAR.set_message("initializing.."); } if let Some(url) = ilias.opt.sync_url.as_ref() { - for item in ilias.get_course_content(&URL::from_href(url).expect("invalid URL")).await.expect("invalid response") { - let item = item.expect("invalid item"); - let ilias = Arc::clone(&ilias); - let mut path = ilias.opt.output.clone(); - path.push(file_escape(item.name())); - tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))).unwrap(); + // TODO: this should be unified with the download logic below + let course = ilias.get_course_content(&URL::from_href(url).expect("invalid URL")).await.expect("invalid response"); + if let Some(s) = course.1.as_ref() { + let path = ilias.opt.output.join("course.html"); + write_file_data(&path, &mut s.as_bytes()).await.expect("failed to write course page html"); + } + for item in course.0 { + if let Ok(item) = item { + let ilias = Arc::clone(&ilias); + let path = ilias.opt.output.join(file_escape(item.name())); + tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))).unwrap(); + } } } else { let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop"); @@ -183,11 +192,6 @@ async fn main() { } } -lazy_static! { - static ref TASKS: Mutex>>> = Mutex::default(); - static ref TASKS_RUNNING: Semaphore = Semaphore::new(0); -} - macro_rules! spawn { ($e:expr) => { TASKS.lock().as_ref().unwrap().unbounded_send(task::spawn($e)).unwrap(); @@ -264,34 +268,32 @@ async fn handle_gracefully(fut: impl Future>) { #[allow(non_upper_case_globals)] mod selectors { - use lazy_static::lazy_static; + use once_cell::sync::Lazy; use regex::Regex; use scraper::Selector; // construct CSS selectors once - lazy_static! { - pub static ref a: Selector = Selector::parse("a").unwrap(); - pub static ref a_target_blank: Selector = Selector::parse(r#"a[target="_blank"]"#).unwrap(); - pub static ref img: Selector = Selector::parse("img").unwrap(); - pub static ref table: Selector = Selector::parse("table").unwrap(); - pub static ref video_tr: Selector = Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap(); - pub static ref links_in_table: Selector = Selector::parse("tbody tr td a").unwrap(); - pub static ref th: Selector = Selector::parse("th").unwrap(); - pub static ref td: Selector = Selector::parse("td").unwrap(); - pub static ref tr: Selector = Selector::parse("tr").unwrap(); - pub static ref post_row: Selector = Selector::parse(".ilFrmPostRow").unwrap(); - pub static ref post_title: Selector = Selector::parse(".ilFrmPostTitle").unwrap(); - pub static ref post_container: Selector = Selector::parse(".ilFrmPostContentContainer").unwrap(); - pub static ref post_attachments: Selector = Selector::parse(".ilFrmPostAttachmentsContainer").unwrap(); - pub static ref span_small: Selector = Selector::parse("span.small").unwrap(); - pub static ref forum_pages: Selector = Selector::parse("div.ilTableNav > table > tbody > tr > td > a").unwrap(); - pub static ref alert_danger: Selector = Selector::parse("div.alert-danger").unwrap(); - pub static ref tree_highlighted: Selector = Selector::parse("span.ilHighlighted").unwrap(); - pub static ref form_group: Selector = Selector::parse(".form-group").unwrap(); - pub static ref form_name: Selector = Selector::parse(".il_InfoScreenProperty").unwrap(); - pub static ref cmd_node_regex: Regex = Regex::new(r#"cmdNode=uf:\w\w"#).unwrap(); - pub static ref image_src_regex: Regex = Regex::new(r#"\./data/produktiv/mobs/mm_(\d+)/([^?]+).+"#).unwrap(); - pub static ref XOCT_REGEX: Regex = Regex::new(r#"(?m)"#).unwrap(); - } + pub static a: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); + pub static a_target_blank: Lazy = Lazy::new(|| Selector::parse(r#"a[target="_blank"]"#).unwrap()); + pub static img: Lazy = Lazy::new(|| Selector::parse("img").unwrap()); + pub static table: Lazy = Lazy::new(|| Selector::parse("table").unwrap()); + pub static video_tr: Lazy = Lazy::new(|| Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap()); + pub static links_in_table: Lazy = Lazy::new(|| Selector::parse("tbody tr td a").unwrap()); + pub static th: Lazy = Lazy::new(|| Selector::parse("th").unwrap()); + pub static td: Lazy = Lazy::new(|| Selector::parse("td").unwrap()); + pub static tr: Lazy = Lazy::new(|| Selector::parse("tr").unwrap()); + pub static post_row: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostRow").unwrap()); + pub static post_title: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostTitle").unwrap()); + pub static post_container: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostContentContainer").unwrap()); + pub static post_attachments: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostAttachmentsContainer").unwrap()); + pub static span_small: Lazy = Lazy::new(|| Selector::parse("span.small").unwrap()); + pub static forum_pages: Lazy = Lazy::new(|| Selector::parse("div.ilTableNav > table > tbody > tr > td > a").unwrap()); + pub static alert_danger: Lazy = Lazy::new(|| Selector::parse("div.alert-danger").unwrap()); + pub static form_group: Lazy = Lazy::new(|| Selector::parse(".form-group").unwrap()); + pub static form_name: Lazy = Lazy::new(|| Selector::parse(".il_InfoScreenProperty").unwrap()); + pub static cmd_node_regex: Lazy = Lazy::new(|| Regex::new(r#"cmdNode=uf:\w\w"#).unwrap()); + pub static image_src_regex: Lazy = Lazy::new(|| Regex::new(r#"\./data/produktiv/mobs/mm_(\d+)/([^?]+).+"#).unwrap()); + pub static XOCT_REGEX: Lazy = Lazy::new(|| Regex::new(r#"(?m)"#).unwrap()); + pub static il_content_container: Lazy = Lazy::new(|| Selector::parse("#ilContentContainer").unwrap()); } use crate::selectors::*; @@ -309,15 +311,17 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() } log!(1, "Syncing {} {}", obj.kind(), relative_path.to_string_lossy()); log!(2, " URL: {}", obj.url().url); + if obj.is_dir() { + create_dir(&path).await?; + } match &obj { Course { url, name } => { - create_dir(&path).await?; let content = if ilias.opt.content_tree { let html = ilias.download(&url.url).await?.text().await?; let cmd_node = cmd_node_regex.find(&html).context("can't find cmdNode")?.as_str()[8..].to_owned(); let content_tree = ilias.get_course_content_tree(&url.ref_id, &cmd_node).await; match content_tree { - Ok(tree) => tree, + Ok(tree) => (tree.into_iter().map(Result::Ok).collect(), None), Err(e) => { // some folders are hidden on the course page and can only be found via the RSS feed / recent activity / content tree sidebar // TODO: this is probably never the case for folders? @@ -325,30 +329,28 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() return Ok(()); // ignore groups we are not in } warning!(name, "falling back to incomplete course content extractor!", e); - ilias.get_course_content(&url).await?.into_iter().flat_map(Result::ok).collect() // TODO: perhaps don't download almost the same content 3x + ilias.get_course_content(&url).await? // TODO: perhaps don't download almost the same content 3x }, } } else { - ilias.get_course_content(&url).await?.into_iter().flat_map(Result::ok).collect() + ilias.get_course_content(&url).await? }; - for item in content { - let mut path = path.clone(); - path.push(file_escape(item.name())); + if let Some(s) = content.1.as_ref() { + let path = ilias.opt.output.join("course.html"); + write_file_data(&path, &mut s.as_bytes()).await.expect("failed to write course page html"); + } + for item in content.0 { + let item = item?; + let path = path.join(file_escape(item.name())); let ilias = Arc::clone(&ilias); spawn!(process_gracefully(ilias, path, item)); } }, Folder { url, .. } => { - create_dir(&path).await?; let content = ilias.get_course_content(&url).await?; - for item in content { - if item.is_err() { - log!(1, "Ignoring: {:?}", item.err().unwrap()); - continue; - } - let item = item.unwrap(); - let mut path = path.clone(); - path.push(file_escape(item.name())); + for item in content.0 { + let item = item?; + let path = path.join(file_escape(item.name())); let ilias = Arc::clone(&ilias); spawn!(process_gracefully(ilias, path, item)); } @@ -372,7 +374,6 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() if ilias.opt.no_videos { return Ok(()); } - create_dir(&path).await?; let full_url = { // first find the link to full video list let list_url = format!("{}ilias.php?ref_id={}&cmdClass=xocteventgui&cmdNode=nc:n4:14u&baseClass=ilObjPluginDispatchGUI&lang=de&limit=20&cmd=asyncGetTableGUI&cmdMode=asynch", ILIAS_URL, url.ref_id); @@ -490,7 +491,6 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() if !ilias.opt.forum { return Ok(()); } - create_dir(&path).await?; let url = &url.url; let html = { let data = ilias.download(url); @@ -581,7 +581,6 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() if !ilias.opt.forum { return Ok(()); } - create_dir(&path).await?; let mut all_images = Vec::new(); let mut attachments = Vec::new(); { @@ -698,7 +697,6 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() } }, ExerciseHandler { url, .. } => { - create_dir(&path).await?; let html = ilias.get_html(&url.url).await?; let mut filenames = HashSet::new(); for row in html.select(&form_group) { @@ -986,18 +984,20 @@ impl ILIAS { let container_items = Selector::parse("div.il_ContainerListItem").unwrap(); let container_item_title = Selector::parse("a.il_ContainerItemTitle").unwrap(); html.select(&container_items) - .map(|item| { + .flat_map(|item| { item.select(&container_item_title) .next() .map(|link| Object::from_link(item, link)) - .context("can't find link").flatten2() + // items without links are ignored }) .collect() } - async fn get_course_content(&self, url: &URL) -> Result>> { + /// Returns subfolders and the main text on the course page. + async fn get_course_content(&self, url: &URL) -> Result<(Vec>, Option)> { let html = self.get_html(&url.url).await?; - Ok(ILIAS::get_items(&html)) + let main_text = html.select(&il_content_container).next().map(|x| x.inner_html()); + Ok((ILIAS::get_items(&html), main_text)) } async fn personal_desktop(&self) -> Result { @@ -1114,9 +1114,8 @@ impl Object { | Thread { .. } | Wiki { .. } | ExerciseHandler { .. } - | Presentation { .. } | PluginDispatch { .. } => true, - File { .. } | Video { .. } | Weblink { .. } | Survey { .. } | Generic { .. } => false, + _ => false, } } From 338c97821b0ec4f77e9f359c3bf2b17d22e5f923 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 21 Apr 2021 21:38:08 +0200 Subject: [PATCH 027/103] Various cleanups --- Cargo.lock | 59 -------------------------- Cargo.toml | 1 - src/main.rs | 120 +++++++++++++++++++++------------------------------- src/util.rs | 43 ++++--------------- 4 files changed, 58 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6948942..ad30cba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,7 +17,6 @@ dependencies = [ "indicatif", "keyring", "once_cell", - "parking_lot", "regex", "reqwest", "rpassword", @@ -832,15 +831,6 @@ dependencies = [ "regex", ] -[[package]] -name = "instant" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" -dependencies = [ - "cfg-if", -] - [[package]] name = "ipnet" version = "2.3.0" @@ -885,15 +875,6 @@ version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" -[[package]] -name = "lock_api" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.14" @@ -1101,31 +1082,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "parking_lot" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] - [[package]] name = "percent-encoding" version = "2.1.0" @@ -1345,15 +1301,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "redox_syscall" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" -dependencies = [ - "bitflags", -] - [[package]] name = "regex" version = "1.4.5" @@ -1481,12 +1428,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "scraper" version = "0.12.0" diff --git a/Cargo.toml b/Cargo.toml index 100f484..2205bc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ futures = "0.3.8" futures-util = "0.3.8" futures-channel = "0.3.8" regex = "1.3.7" -parking_lot = "0.11.0" structopt = "0.3.13" rpassword = "5.0.0" rprompt = "1.0.5" diff --git a/src/main.rs b/src/main.rs index b598ea5..ba6aa85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,8 +7,7 @@ use futures_channel::mpsc::UnboundedSender; use futures_util::{stream::TryStreamExt, StreamExt}; use ignore::gitignore::Gitignore; use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; -use once_cell::sync::Lazy; -use parking_lot::Mutex; +use once_cell::sync::{Lazy, OnceCell}; use reqwest::{Client, Proxy}; use scraper::{ElementRef, Html, Selector}; use serde_json::json; @@ -18,12 +17,12 @@ use tokio::task::{self, JoinHandle}; use tokio_util::io::StreamReader; use url::Url; -use std::{future::Future, sync::atomic::AtomicBool}; +use std::future::Future; use std::io; use std::path::PathBuf; -use std::sync::atomic::Ordering; +use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::Arc; -use std::{collections::HashSet, default::Default, sync::atomic::AtomicUsize}; +use std::collections::HashSet; mod util; use util::*; @@ -35,9 +34,15 @@ static PROGRESS_BAR_ENABLED: AtomicBool = AtomicBool::new(false); static PROGRESS_BAR: Lazy = Lazy::new(|| ProgressBar::new(0)); /// Global job queue -static TASKS: Lazy>>>> = Lazy::new(Mutex::default); +static TASKS: OnceCell>> = OnceCell::new(); static TASKS_RUNNING: Lazy = Lazy::new(|| Semaphore::new(0)); +macro_rules! spawn { + ($e:expr) => { + TASKS.get().unwrap().unbounded_send(task::spawn($e)).unwrap(); + }; +} + macro_rules! log { ($lvl:expr, $($t:expr),+) => { #[allow(unused_comparisons)] // 0 <= 0 @@ -74,7 +79,7 @@ macro_rules! warning { println!("Warning: {}", format!("{} {} {:?}", $msg1, $msg2, $e).bright_yellow()); }; (format => $($e:expr),+) => { - println!("Warning: {}", format!($($e),+)); + println!("Warning: {}", format!($($e),+).bright_yellow()); }; } @@ -89,13 +94,20 @@ macro_rules! error { #[tokio::main] async fn main() { - let mut opt = Opt::from_args(); + let opt = Opt::from_args(); + if let Err(e) = real_main(opt).await { + error!(e); + } +} + +async fn real_main(mut opt: Opt) -> Result<()> { + LOG_LEVEL.store(opt.verbose, Ordering::SeqCst); #[cfg(windows)] let _ = colored::control::set_virtual_terminal(true); + // use UNC paths on Windows - opt.output = fs::canonicalize(opt.output).await.expect("failed to canonicalize directory"); - LOG_LEVEL.store(opt.verbose, Ordering::SeqCst); - create_dir(&opt.output).await.expect("failed to create output directory"); + opt.output = fs::canonicalize(opt.output).await.context("failed to canonicalize output directory")?; + create_dir(&opt.output).await.context("failed to create output directory")?; // load .iliasignore file opt.output.push(".iliasignore"); @@ -104,18 +116,19 @@ async fn main() { warning!(err); } opt.output.pop(); + // loac .iliaslogin file opt.output.push(".iliaslogin"); let login = std::fs::read_to_string(&opt.output); let (user, pass) = if let Ok(login) = login { let mut lines = login.split('\n'); - let user = lines.next().expect("missing user in .iliaslogin"); - let pass = lines.next().expect("missing password in .iliaslogin"); + let user = lines.next().context("missing user in .iliaslogin")?; + let pass = lines.next().context("missing password in .iliaslogin")?; let user = user.trim(); let pass = pass.trim(); (user.to_owned(), pass.to_owned()) } else { - ask_user_pass(&opt).expect("credentials input") + ask_user_pass(&opt).context("credentials input failed")? }; opt.output.pop(); @@ -134,7 +147,7 @@ async fn main() { } let ilias = Arc::new(ilias); let (tx, mut rx) = futures_channel::mpsc::unbounded::>(); - *TASKS.lock() = Some(tx.clone()); + TASKS.get_or_init(|| tx.clone()); TASKS_RUNNING.add_permits(ilias.opt.jobs); PROGRESS_BAR_ENABLED.store(atty::is(atty::Stream::Stdout), Ordering::SeqCst); if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { @@ -145,30 +158,13 @@ async fn main() { } if let Some(url) = ilias.opt.sync_url.as_ref() { // TODO: this should be unified with the download logic below - let course = ilias.get_course_content(&URL::from_href(url).expect("invalid URL")).await.expect("invalid response"); - if let Some(s) = course.1.as_ref() { - let path = ilias.opt.output.join("course.html"); - write_file_data(&path, &mut s.as_bytes()).await.expect("failed to write course page html"); - } - for item in course.0 { - if let Ok(item) = item { - let ilias = Arc::clone(&ilias); - let path = ilias.opt.output.join(file_escape(item.name())); - tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))).unwrap(); - } - } + let obj = Object::from_url(URL::from_href(url).expect("invalid URL"), "".to_owned(), None).expect("invalid object"); // name can be empty for first element + spawn!(process_gracefully(ilias.clone(), ilias.opt.output.clone(), obj)); } else { - let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop"); - match desktop { - Ok(desktop) => { - for item in desktop.items { - let mut path = ilias.opt.output.clone(); - path.push(file_escape(item.name())); - let ilias = Arc::clone(&ilias); - let _ = tx.unbounded_send(task::spawn(process_gracefully(ilias, path, item))); - } - }, - Err(e) => error!(e), + let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop")?; + for item in desktop.items { + let path = ilias.opt.output.join(file_escape(item.name())); + tx.unbounded_send(task::spawn(process_gracefully(ilias.clone(), path, item))).unwrap(); } } while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await { @@ -190,12 +186,7 @@ async fn main() { PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}] {msg}")); PROGRESS_BAR.finish_with_message("done"); } -} - -macro_rules! spawn { - ($e:expr) => { - TASKS.lock().as_ref().unwrap().unbounded_send(task::spawn($e)).unwrap(); - }; + Ok(()) } fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { @@ -299,7 +290,7 @@ use crate::selectors::*; const NO_ENTRIES: &str = "Keine Einträge"; -async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<()> { +async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let relative_path = path.strip_prefix(&ilias.opt.output).unwrap(); if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { PROGRESS_BAR.inc(1); @@ -461,8 +452,8 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() log!(2, "{}", json); let url = json .pointer("/streams/0/sources/mp4/0/src") - .map(|x| x.as_str()) .context("video src not found")? + .as_str() .context("video src not string")?; let meta = fs::metadata(&path).await; if !ilias.opt.force && meta.is_ok() && ilias.opt.check_videos { @@ -497,7 +488,6 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() let html_text = data.await?.text().await?; let url = { let html = Html::parse_document(&html_text); - //https://ilias.studium.kit.edu/ilias.php?ref_id=122&cmdClass=ilobjforumgui&frm_tt_e39_122_trows=800&cmd=showThreads&cmdNode=uf:lg&baseClass=ilrepositorygui let thread_count_selector = html.select(&a) .flat_map(|x| x.value().attr("href")) .find(|x| x.contains("trows=800")); @@ -525,13 +515,9 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() } let cells = row.select(&td).collect::>(); if cells.len() != 6 { - log!( - 0, + warning!(format => "Warning: {}{} {} {}", - "unusual table row (".bright_yellow(), - cells.len().to_string().bright_yellow(), - "cells) in".bright_yellow(), - url.to_string().bright_yellow() + "unusual table row (", cells.len(), "cells) in", url.to_string() ); continue; } @@ -569,7 +555,6 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() if available_posts <= saved_posts && !ilias.opt.force { continue; } - log!(0, "New posts in {:?}..", path); let ilias = Arc::clone(&ilias); spawn!(process_gracefully(ilias, path, object)); } @@ -615,9 +600,10 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() .to_owned(); let name = format!("{}_{}_{}.html", id, author, title.trim()); let data = container.inner_html(); - let mut path = path.clone(); - path.push(file_escape(&name)); + let path = path.join(file_escape(&name)); + let relative_path = relative_path.join(file_escape(&name)); spawn!(handle_gracefully(async move { + log!(0, "Writing {}", relative_path.display()); write_file_data(&path, &mut data.as_bytes()) .await .context("failed to write forum post") @@ -795,9 +781,7 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() } let head = head.unwrap(); let url = head.url().as_str(); - path.push(file_escape(&name)); - write_file_data(&path, &mut url.as_bytes()).await?; - path.pop(); + write_file_data(path.join(file_escape(&name)), &mut url.as_bytes()).await?; } } else { log!(0, "Writing {}", relative_path.to_string_lossy()); @@ -1120,14 +1104,17 @@ impl Object { } fn from_link(item: ElementRef, link: ElementRef) -> Result { - let mut name = link + let name = link .text() .collect::() .replace('/', "-") .trim() .to_owned(); - let mut url = URL::from_href(link.value().attr("href").context("link missing href")?)?; + let url = URL::from_href(link.value().attr("href").context("link missing href")?)?; + Object::from_url(url, name, Some(item)) + } + fn from_url(mut url: URL, mut name: String, item: Option) -> Result { if url.thr_pk.is_some() { return Ok(Thread { url }); } @@ -1173,7 +1160,7 @@ impl Object { return Ok(Generic { name, url }); } else { let item_prop = Selector::parse("span.il_ItemProperty").unwrap(); - let mut item_props = item.select(&item_prop); + let mut item_props = item.context("can't construct file object without HTML object")?.select(&item_prop); let ext = item_props.next().context("cannot find file extension")?; let version = item_props .nth(1) @@ -1296,12 +1283,3 @@ impl URL { }) } } - -#[cfg(not(target_os = "windows"))] -const INVALID: &[char] = &['/', '\\']; -#[cfg(target_os = "windows")] -const INVALID: &[char] = &['/', '\\', ':', '<', '>', '"', '|', '?', '*']; - -fn file_escape(s: &str) -> String { - s.replace(INVALID, "-") -} diff --git a/src/util.rs b/src/util.rs index 5cf3bba..3d6e57c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,11 +4,11 @@ use tokio::io::{AsyncRead, BufWriter}; use std::path::Path; -use super::Result; +use crate::Result; -pub async fn write_file_data(path: &Path, data: &mut R) -> Result<()> +pub async fn write_file_data(path: impl AsRef, data: &mut R) -> Result<()> where R: AsyncRead + Unpin { - let file = AsyncFile::create(&path).await.context("failed to create file")?; + let file = AsyncFile::create(path.as_ref()).await.context("failed to create file")?; let mut file = BufWriter::new(file); tokio::io::copy(data, &mut file).await.context("failed to write to file")?; Ok(()) @@ -24,36 +24,11 @@ pub async fn create_dir(path: &Path) -> Result<()> { Ok(()) } -// remove once result_flattening is stable (https://github.com/rust-lang/rust/issues/70142) -pub trait Result2 { - type V; - type E; - type F; +#[cfg(not(target_os = "windows"))] +const INVALID: &[char] = &['/', '\\']; +#[cfg(target_os = "windows")] +const INVALID: &[char] = &['/', '\\', ':', '<', '>', '"', '|', '?', '*']; - fn flatten2(self) -> Result - where - Self::F: Into; - - fn flatten_with Self::E>(self, op: O) -> Result; -} - -impl Result2 for Result, E> { - type V = V; - type E = E; - type F = F; - - fn flatten2(self) -> Result - where - Self::F: Into, - { - self.flatten_with(|e| e.into()) - } - - fn flatten_with Self::E>(self, op: O) -> Result { - match self { - Ok(Ok(v)) => Ok(v), - Ok(Err(f)) => Err(op(f)), - Err(e) => Err(e), - } - } +pub fn file_escape(s: &str) -> String { + s.replace(INVALID, "-") } From 3887d6781f7bcae13bebb9e08a009d83c45e89db Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 22 Apr 2021 12:17:45 +0200 Subject: [PATCH 028/103] Various bugfixes course.html: no longer includes right column course.html/folder.html: only downloaded if useful correct handling of pseudonymous forums --- src/main.rs | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index ba6aa85..72e4d7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -158,7 +158,7 @@ async fn real_main(mut opt: Opt) -> Result<()> { } if let Some(url) = ilias.opt.sync_url.as_ref() { // TODO: this should be unified with the download logic below - let obj = Object::from_url(URL::from_href(url).expect("invalid URL"), "".to_owned(), None).expect("invalid object"); // name can be empty for first element + let obj = Object::from_url(URL::from_href(url).context("invalid sync URL")?, "Sync URL".to_owned(), None).context("invalid sync object")?; // name can be empty for first element spawn!(process_gracefully(ilias.clone(), ilias.opt.output.clone(), obj)); } else { let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop")?; @@ -284,7 +284,10 @@ mod selectors { pub static cmd_node_regex: Lazy = Lazy::new(|| Regex::new(r#"cmdNode=uf:\w\w"#).unwrap()); pub static image_src_regex: Lazy = Lazy::new(|| Regex::new(r#"\./data/produktiv/mobs/mm_(\d+)/([^?]+).+"#).unwrap()); pub static XOCT_REGEX: Lazy = Lazy::new(|| Regex::new(r#"(?m)"#).unwrap()); - pub static il_content_container: Lazy = Lazy::new(|| Selector::parse("#ilContentContainer").unwrap()); + pub static il_content_container: Lazy = Lazy::new(|| Selector::parse("#il_center_col").unwrap()); + pub static item_prop: Lazy = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap()); + pub static container_items: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem").unwrap()); + pub static container_item_title: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle").unwrap()); } use crate::selectors::*; @@ -327,8 +330,8 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { ilias.get_course_content(&url).await? }; if let Some(s) = content.1.as_ref() { - let path = ilias.opt.output.join("course.html"); - write_file_data(&path, &mut s.as_bytes()).await.expect("failed to write course page html"); + let path = path.join("course.html"); + write_file_data(&path, &mut s.as_bytes()).await.context("failed to write course page html")?; } for item in content.0 { let item = item?; @@ -339,6 +342,10 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { }, Folder { url, .. } => { let content = ilias.get_course_content(&url).await?; + if let Some(s) = content.1.as_ref() { + let path = path.join("folder.html"); + write_file_data(&path, &mut s.as_bytes()).await.context("failed to write folder page html")?; + } for item in content.0 { let item = item?; let path = path.join(file_escape(item.name())); @@ -464,7 +471,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { .await .context("HEAD request failed")?; if let Some(len) = head.headers().get("content-length") { - if meta.unwrap().len() != len.to_str()?.parse::()? { + if meta?.len() != len.to_str()?.parse::()? { warning!(relative_path.to_string_lossy(), "was updated, consider moving the outdated file"); } } @@ -585,9 +592,18 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let author = author .trim() .split('|') - .nth(1) - .context("author data in unknown format")? - .trim(); + .collect::>(); + let author = if author.len() == 2 { + author[0] // pseudonymous forum + } else if author.len() == 3 { + if author[1] != "Pseudonym" { + author[1] + } else { + author[0] + } + } else { + return Err(anyhow!("author data in unknown format")); + }.trim(); let container = post .select(&post_container) .next() @@ -965,8 +981,6 @@ impl ILIAS { } fn get_items(html: &Html) -> Vec> { - let container_items = Selector::parse("div.il_ContainerListItem").unwrap(); - let container_item_title = Selector::parse("a.il_ContainerItemTitle").unwrap(); html.select(&container_items) .flat_map(|item| { item.select(&container_item_title) @@ -980,7 +994,17 @@ impl ILIAS { /// Returns subfolders and the main text on the course page. async fn get_course_content(&self, url: &URL) -> Result<(Vec>, Option)> { let html = self.get_html(&url.url).await?; - let main_text = html.select(&il_content_container).next().map(|x| x.inner_html()); + let main_text = if let Some(el) = html.select(&il_content_container).next() { + if !el.children().flat_map(|x| x.value().as_element()).next().map(|x| + x.attr("class").unwrap_or_default().contains("ilContainerBlock")).unwrap_or(false) { + Some(el.inner_html()) + } else { + // first element is the content overview => no custom text (?) + None + } + } else { + None + }; Ok((ILIAS::get_items(&html), main_text)) } @@ -1159,7 +1183,6 @@ impl Object { // download page containing metadata return Ok(Generic { name, url }); } else { - let item_prop = Selector::parse("span.il_ItemProperty").unwrap(); let mut item_props = item.context("can't construct file object without HTML object")?.select(&item_prop); let ext = item_props.next().context("cannot find file extension")?; let version = item_props From f32b94ab69602b956479856e2f490a2f8aa1f8a4 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 1 May 2021 12:02:48 +0200 Subject: [PATCH 029/103] Link to other tool --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cc7b1d0..f784b83 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,4 @@ password - https://github.com/brantsch/kit-ilias-fuse/ - https://github.com/Garmelon/PFERD/ +- https://github.com/DeOldSax/iliasDownloaderTool From 965a116f3490a93f60cae73af260e8533aef2129 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sat, 1 May 2021 12:03:31 +0200 Subject: [PATCH 030/103] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f784b83..1f50208 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ If you use Linux, you'll have to compile from source to be able to use this opti $ KIT-ILIAS-downloader -U uabcd --keyring [...] ``` -You can also save your username and password in a `.iliaslogin` file: +You can also save your username and password in a `.iliaslogin` file: (located in the output folder) ``` username password From 81543b1d393de9143935526aaa5c753f1b3309ad Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 4 May 2021 10:47:23 +0200 Subject: [PATCH 031/103] Version 0.2.17 --- Cargo.lock | 73 +++++++++++++++++++++++++---------------------------- Cargo.toml | 2 +- src/main.rs | 4 ++- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad30cba..c2ffcdd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.16" +version = "0.2.17" dependencies = [ "anyhow", "atty", @@ -68,9 +68,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.15" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] @@ -92,9 +92,9 @@ checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" [[package]] name = "async-compression" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b72c1f1154e234325b50864a349b9c8e56939e266a4c307c0f159812df2f9537" +checksum = "5443ccbb270374a2b1055fc72da40e1f237809cd6bb0e97e66d264cd138473a6" dependencies = [ "flate2", "futures-core", @@ -165,9 +165,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "bstr" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" +checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279" dependencies = [ "memchr", ] @@ -324,9 +324,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" +checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" dependencies = [ "autocfg", "cfg-if", @@ -632,9 +632,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc018e188373e2777d0ef2467ebff62a08e66c3f5857b23c8fbec3018210dc00" +checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" dependencies = [ "bytes", "fnv", @@ -737,15 +737,15 @@ checksum = "4a1ce40d6fc9764887c2fdc7305c3dcc429ba11ff981c1509416afd5697e4437" [[package]] name = "httpdate" -version = "0.3.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" +checksum = "05842d0d43232b23ccb7060ecb0f0626922c21f30012e97b767b30afd4a5d4b9" [[package]] name = "hyper" -version = "0.14.5" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf09f61b52cfcf4c00de50df88ae423d6c02354e385a86341133b5338630ad1" +checksum = "1e5f105c494081baa3bf9e200b279e27ec1623895cd504c7dbef8d0b080fcf54" dependencies = [ "bytes", "futures-channel", @@ -871,9 +871,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "log" @@ -892,16 +892,13 @@ checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" [[package]] name = "markup5ever" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae38d669396ca9b707bfc3db254bc382ddb94f57cc5c235f34623a669a01dab" +checksum = "a24f40fb03852d1cdd84330cddcaf98e9ec08a7b7768e952fad3b4cf048ec8fd" dependencies = [ "log", "phf", "phf_codegen", - "serde", - "serde_derive", - "serde_json", "string_cache", "string_cache_codegen", "tendril", @@ -915,9 +912,9 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "mime" @@ -1303,9 +1300,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.5" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" +checksum = "ce5f1ceb7f74abbce32601642fcf8e8508a8a8991e0621c7d750295b9095702b" dependencies = [ "aho-corasick", "memchr", @@ -1314,9 +1311,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.23" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "reqwest" @@ -1608,9 +1605,9 @@ checksum = "cbce6d4507c7e4a3962091436e56e95290cb71fa302d0d270e32130b75fbff27" [[package]] name = "slab" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" [[package]] name = "smallvec" @@ -1761,9 +1758,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.69" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ "proc-macro2", "quote", @@ -1960,9 +1957,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if", "pin-project-lite", @@ -1971,9 +1968,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" dependencies = [ "lazy_static", ] @@ -2022,9 +2019,9 @@ checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "untrusted" diff --git a/Cargo.toml b/Cargo.toml index 2205bc8..400b6ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.16" +version = "0.2.17" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-2.0" edition = "2018" diff --git a/src/main.rs b/src/main.rs index 72e4d7a..c948e6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -996,7 +996,9 @@ impl ILIAS { let html = self.get_html(&url.url).await?; let main_text = if let Some(el) = html.select(&il_content_container).next() { if !el.children().flat_map(|x| x.value().as_element()).next().map(|x| - x.attr("class").unwrap_or_default().contains("ilContainerBlock")).unwrap_or(false) { + x.attr("class").unwrap_or_default().contains("ilContainerBlock")).unwrap_or(false) + && el.inner_html().len() > 40 { + // ^ minimum length of useful content? Some(el.inner_html()) } else { // first element is the content overview => no custom text (?) From dc02ec7a460bf96c4569839819f856205edd1274 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 May 2021 09:15:24 +0200 Subject: [PATCH 032/103] Request rate limiting --- src/main.rs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index c948e6b..6fc3bdd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,11 +8,11 @@ use futures_util::{stream::TryStreamExt, StreamExt}; use ignore::gitignore::Gitignore; use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; use once_cell::sync::{Lazy, OnceCell}; -use reqwest::{Client, Proxy}; +use reqwest::{Client, IntoUrl, Proxy}; use scraper::{ElementRef, Html, Selector}; use serde_json::json; use structopt::StructOpt; -use tokio::{fs, sync::Semaphore}; +use tokio::{fs, sync::Semaphore, time}; use tokio::task::{self, JoinHandle}; use tokio_util::io::StreamReader; use url::Url; @@ -36,6 +36,11 @@ static PROGRESS_BAR: Lazy = Lazy::new(|| ProgressBar::new(0)); /// Global job queue static TASKS: OnceCell>> = OnceCell::new(); static TASKS_RUNNING: Lazy = Lazy::new(|| Semaphore::new(0)); +static REQUEST_TICKETS: Lazy = Lazy::new(|| Semaphore::new(0)); + +async fn get_request_ticket() { + REQUEST_TICKETS.acquire().await.unwrap().forget(); +} macro_rules! spawn { ($e:expr) => { @@ -95,6 +100,14 @@ macro_rules! error { #[tokio::main] async fn main() { let opt = Opt::from_args(); + let rate = opt.rate; + task::spawn(async move { + let mut interval = time::interval(time::Duration::from_secs_f64(60.0 / rate as f64)); + loop { + interval.tick().await; + REQUEST_TICKETS.add_permits(1); + } + }); if let Err(e) = real_main(opt).await { error!(e); } @@ -465,9 +478,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let meta = fs::metadata(&path).await; if !ilias.opt.force && meta.is_ok() && ilias.opt.check_videos { let head = ilias - .client .head(url) - .send() .await .context("HEAD request failed")?; if let Some(len) = head.headers().get("content-length") { @@ -757,7 +768,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { log!(2, "Skipping download, link exists already"); return Ok(()); } - let head_req_result = ilias.client.head(&url.url).send().await; + let head_req_result = ilias.head(&url.url).await; let url = match &head_req_result { Err(e) => e.url().context("HEAD request failed")?.as_str(), Ok(head) => head.url().as_str(), @@ -790,7 +801,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { continue; } - let head = ilias.client.head(url.url.as_str()).send().await.context("HEAD request to web link failed"); + let head = ilias.head(url.url.as_str()).await.context("HEAD request to web link failed"); if let Some(err) = head.as_ref().err() { warning!(err); continue; @@ -839,7 +850,7 @@ struct Opt { #[structopt(short)] force: bool, - /// Use content tree (slow but thorough) + /// Use content tree (experimental) #[structopt(long)] content_tree: bool, @@ -879,6 +890,10 @@ struct Opt { /// ILIAS page to download #[structopt(long)] sync_url: Option, + + /// Requests per minute + #[structopt(long, default_value = "8")] + rate: usize } struct ILIAS { @@ -952,6 +967,7 @@ impl ILIAS { } async fn download(&self, url: &str) -> Result { + get_request_ticket().await; log!(2, "Downloading {}", url); if url.starts_with("http") || url.starts_with("ilias.studium.kit.edu") { Ok(self.client.get(url).send().await?) @@ -960,6 +976,11 @@ impl ILIAS { } } + async fn head(&self, url: U) -> Result { + get_request_ticket().await; + self.client.head(url).send().await + } + async fn get_html(&self, url: &str) -> Result { let text = self.download(url).await?.text().await?; let html = Html::parse_document(&text); From e88640c9c9545059ae0b09bc267da4e826cb3c57 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 May 2021 09:18:29 +0200 Subject: [PATCH 033/103] Version 0.2.18 --- Cargo.lock | 21 ++++++++++++--------- Cargo.toml | 4 ++-- README.md | 5 +++-- build.sh | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2ffcdd..3feff46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.17" +version = "0.2.18" dependencies = [ "anyhow", "atty", @@ -308,10 +308,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] -name = "cpuid-bool" -version = "0.1.2" +name = "cpufeatures" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" +checksum = "dec1028182c380cc45a2e2c5ec841134f2dfd0f8f5f0a5bcd68004f81b5efdf4" +dependencies = [ + "libc", +] [[package]] name = "crc32fast" @@ -1300,9 +1303,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.3" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce5f1ceb7f74abbce32601642fcf8e8508a8a8991e0621c7d750295b9095702b" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", @@ -1586,13 +1589,13 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" [[package]] name = "sha2" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" +checksum = "d8f6b75b17576b792bef0db1bcc4b8b8bcdf9506744cf34b974195487af6cff2" dependencies = [ "block-buffer", "cfg-if", - "cpuid-bool", + "cpufeatures", "digest", "opaque-debug", ] diff --git a/Cargo.toml b/Cargo.toml index 400b6ce..3a02799 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.17" +version = "0.2.18" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] -license = "GPL-2.0" +license = "GPL-2.0-or-later" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 1f50208..ba179bd 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,14 @@ $ KIT-ILIAS-downloader -o ./ILIAS/WS2021-HM1 --sync-url 'https://ilias.studium.k ``` $ KIT-ILIAS-downloader --help -KIT-ILIAS-downloader 0.2.16 +KIT-ILIAS-downloader 0.2.18 USAGE: KIT-ILIAS-downloader [FLAGS] [OPTIONS] --output FLAGS: --check-videos Re-check OpenCast lectures (slow) - --content-tree Use content tree (slow but thorough) + --content-tree Use content tree (experimental) -f Re-download already present files -t, --forum Download forum content -h, --help Prints help information @@ -60,6 +60,7 @@ OPTIONS: -o, --output Output directory -P, --password KIT account password -p, --proxy Proxy, e.g. socks5h://127.0.0.1:1080 + --rate Requests per minute [default: 8] --sync-url ILIAS page to download -U, --username KIT account username ``` diff --git a/build.sh b/build.sh index bf6e62b..c17f08b 100755 --- a/build.sh +++ b/build.sh @@ -7,4 +7,4 @@ rustup target add x86_64-pc-windows-gnu # if on Debian or similar sudo apt install mingw-w64 cargo build --release --all-features --target x86_64-pc-windows-gnu -strip target/x86_64-pc-windows-gnu/release/KIT-ILIAS-downloader +strip target/x86_64-pc-windows-gnu/release/KIT-ILIAS-downloader.exe From bc8bc9ed0dea1b649b8c3e27cff9cd29962e1091 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 May 2021 15:48:20 +0200 Subject: [PATCH 034/103] Add full license (previously only documented in Cargo.toml) --- LICENSE | 339 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 + src/util.rs | 2 + 3 files changed, 343 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/src/main.rs b/src/main.rs index 6fc3bdd..3c1eacd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + #![allow(clippy::comparison_to_empty, clippy::upper_case_acronyms)] use anyhow::{anyhow, Context, Result}; diff --git a/src/util.rs b/src/util.rs index 3d6e57c..e0ef627 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + use anyhow::Context; use tokio::fs::File as AsyncFile; use tokio::io::{AsyncRead, BufWriter}; From 1e9adafae180028638bc74fbcf026bb0eea8992a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 May 2021 15:49:34 +0200 Subject: [PATCH 035/103] Display keyring errors --- src/main.rs | 20 ++++++++++++-------- src/util.rs | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3c1eacd..960c54f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -212,6 +212,8 @@ fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { }; #[cfg(feature = "keyring-auth")] let (pass, should_store); + #[cfg(feature = "keyring-auth")] + let keyring = Lazy::new(|| keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user)); #[cfg(not(feature = "keyring-auth"))] let pass; cfg_if::cfg_if! { // TODO: deduplicate the logic below @@ -220,13 +222,16 @@ fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { pass = password.clone(); should_store = true; } else if opt.keyring { - let keyring = keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user); - if let Ok(password) = keyring.get_password() { - pass = password; - should_store = false; - } else { - pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; - should_store = true; + match keyring.get_password() { + Ok(password) => { + pass = password; + should_store = false; + }, + Err(e) => { + error!(e); + pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; + should_store = true; + } } } else { pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; @@ -242,7 +247,6 @@ fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { }; #[cfg(feature = "keyring-auth")] if should_store && opt.keyring { - let keyring = keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user); keyring.set_password(&pass).map_err(|x| anyhow!(x.to_string()))?; } Ok((user, pass)) diff --git a/src/util.rs b/src/util.rs index e0ef627..7404f13 100644 --- a/src/util.rs +++ b/src/util.rs @@ -8,6 +8,7 @@ use std::path::Path; use crate::Result; +/// Write all data to the specified path. Will overwrite previous file data. pub async fn write_file_data(path: impl AsRef, data: &mut R) -> Result<()> where R: AsyncRead + Unpin { let file = AsyncFile::create(path.as_ref()).await.context("failed to create file")?; From 3d30e4403e8eb5808c1fb44a69de394dcf068913 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 May 2021 16:15:06 +0200 Subject: [PATCH 036/103] Changelog of previous releases (previously only available via Github releases) --- CHANGELOG.md | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2e3df59 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,137 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project loosely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.2.18] - 2021-05-07 +### Added +- Request rate limiting (default 8 req. / 60 s, option `--rate`, issue [#13]) + +## [0.2.17] - 2021-05-04 +### Added +- Progress/status display: `[15/40+] ` +- Extraction of course/folder pages (in course.html / folder.html, currently not versioned) + +### Fixed +- Downloading of external images in forum posts +- Miscellaneous internal improvements + +## [0.2.16] - 2021-04-19 +### Added +- `--sync-url` option (to download only a single course/folder) +- `--user` and `--password` options (issue [#10]) +- `--keyring` option (to get/save the password using a system keyring service) +- Colored errors/warnings (PR [#11] by [@thelukasprobst]) + +## [0.2.15] - 2021-04-14 +### Added +- Downloading of attachments and embedded images in forum posts +- SOCKS5 proxy support (PR [#9] by [@Craeckie]) + +## [0.2.14] - 2021-02-16 +### Fixed +- Handling of long paths on Windows (issue [#6]) +- OpenCast downloading (issue [#7], PR [#8] by [@funnym0nk3y]) + +## [0.2.13] - 2021-01-05 +### Fixed +- Shibboleth login (issue [#5], PR [#4] by [@Ma27]) + +## [0.2.12] - 2020-12-10 +### Fixed +- Handling of invalid filenames on Windows (issue [#3]) + +## [0.2.11] - 2020-12-04 +### Fixed +- Waiting on spawned tasks (issue [#2]) + +## [0.2.10] - 2020-11-27 +### Added +- `.iliaslogin` file to provide login credentials + +### Fixed +- Handling of `/` and `\\` in lecture names + +## [0.2.9] - 2020-11-01 +### Fixed +- OpenCast downloading + +## [0.2.8] - 2020-07-16 +### Fixed +- OpenCast downloading + +## [0.2.7] - 2020-07-15 +### Added +- Automatic creation of output directory +- Optional re-check of OpenCast lectures (`--check-videos`) + +### Fixed +- OpenCast pagination (20 -> 800) + +## [0.2.6] - 2020-05-18 +### Added +- Downloading of exercise solutions and feedback + +### Fixed +- Video filenames no longer contain raw HTML + +## [0.2.5] - 2020-05-09 +(undocumented) + +## [0.2.4] - 2020-04-28 +(undocumented) + +## [0.2.3] - 2020-04-24 +(undocumented) + +## [0.2.2] - 2020-04-22 +(undocumented) + +## [0.2.1] - 2020-04-22 +(undocumented) + +## [0.2.0] - 2020-04-22 +(undocumented) + +## [0.1.0] - 2020-04-21 +(undocumented) + +[#13]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/13 +[#11]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/11 +[#10]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/10 +[#9]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/9 +[#8]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/8 +[#7]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/7 +[#6]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/6 +[#5]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/5 +[#4]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/4 +[#3]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/3 +[#2]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/2 +[@thelukasprobst]: https://github.com/thelukasprobst +[@Craeckie]: https://github.com/Craeckie +[@funnym0nk3y]: https://github.com/funnym0nk3y +[@Ma27]: https://github.com/Ma27 +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.18...HEAD +[0.2.18]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.17...v0.2.18 +[0.2.17]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.16...v0.2.17 +[0.2.16]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.15...v0.2.16 +[0.2.15]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.14...v0.2.15 +[0.2.14]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.13...v0.2.14 +[0.2.13]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.12...v0.2.13 +[0.2.12]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.11...v0.2.12 +[0.2.11]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.10...v0.2.11 +[0.2.10]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.9...v0.2.10 +[0.2.9]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.8...v0.2.9 +[0.2.8]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.7...v0.2.8 +[0.2.7]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.6...v0.2.7 +[0.2.6]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.5...v0.2.6 +[0.2.5]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.4...v0.2.5 +[0.2.4]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.3...v0.2.4 +[0.2.3]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.2...v0.2.3 +[0.2.2]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.1...v0.2.2 +[0.2.1]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.0...v0.2.1 +[0.2.0]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.1.0...v0.2.0 +[0.1.0]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/1529a678e0f4c78a24c8cc2cd236ce12ea8a78dc..v0.1.0 From b0a389157e9c4592c53f713dafa73557f927364a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 11 May 2021 09:46:23 +0200 Subject: [PATCH 037/103] indicatif: 0.15 -> 0.16 --- Cargo.lock | 52 ++++++++++++++++++++++++++-------------------------- Cargo.toml | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3feff46..dd6f736 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -723,9 +723,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfb77c123b4e2f72a2069aeae0b4b4949cc7e966df277813fc16347e7549737" +checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" dependencies = [ "bytes", "http", @@ -734,9 +734,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a1ce40d6fc9764887c2fdc7305c3dcc429ba11ff981c1509416afd5697e4437" +checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" [[package]] name = "httpdate" @@ -824,9 +824,9 @@ dependencies = [ [[package]] name = "indicatif" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7baab56125e25686df467fe470785512329883aab42696d661247aca2a2896e4" +checksum = "507cf157a0dab3c837bef6e2086466255d9de4a6b1af69e62b62c54cd52f6062" dependencies = [ "console", "lazy_static", @@ -848,9 +848,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.50" +version = "0.3.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c" +checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" dependencies = [ "wasm-bindgen", ] @@ -1066,9 +1066,9 @@ dependencies = [ [[package]] name = "number_prefix" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" @@ -2034,9 +2034,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna", @@ -2091,9 +2091,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.73" +version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" +checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" dependencies = [ "cfg-if", "serde", @@ -2103,9 +2103,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.73" +version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" +checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" dependencies = [ "bumpalo", "lazy_static", @@ -2118,9 +2118,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.23" +version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea" +checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1" dependencies = [ "cfg-if", "js-sys", @@ -2130,9 +2130,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.73" +version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" +checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2140,9 +2140,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.73" +version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" +checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" dependencies = [ "proc-macro2", "quote", @@ -2153,15 +2153,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.73" +version = "0.2.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" +checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" [[package]] name = "web-sys" -version = "0.3.50" +version = "0.3.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" +checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 3a02799..b32bffc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ anyhow = "1.0.28" colored = "2.0.0" keyring = { git = "https://github.com/FliegendeWurst/keyring-rs", branch = "application-name", optional = true } cfg-if = "1.0.0" -indicatif = "0.15.0" +indicatif = "0.16.0" once_cell = "1.7.2" atty = "0.2.14" From 91533a81ba13223532cbe7659caf5d62ba739cd6 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 11 May 2021 09:48:32 +0200 Subject: [PATCH 038/103] CI: run on push to any branch --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c693da6..5921b61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,8 @@ name: CI on: push: - branches: [ master ] + branches: + - '**' pull_request: branches: [ master ] From 4bbeb6c54b81331c5b8ea34258afdb943c8c1be1 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 11 May 2021 09:56:57 +0200 Subject: [PATCH 039/103] Adapt to indicatif 0.16 API --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 960c54f..9853fac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -316,7 +316,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let relative_path = path.strip_prefix(&ilias.opt.output).unwrap(); if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { PROGRESS_BAR.inc(1); - PROGRESS_BAR.set_message(&relative_path.display().to_string()); + PROGRESS_BAR.set_message(relative_path.display().to_string()); } if ilias.ignore.matched(relative_path, obj.is_dir()).is_ignore() { log!(1, "Ignored {}", relative_path.to_string_lossy()); From 1f9ab6a07c674b43a7072c59ab25024a8d8ff5c1 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 11 May 2021 18:41:32 +0200 Subject: [PATCH 040/103] Version 0.2.19 --- CHANGELOG.md | 8 +++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e3df59..4d6c129 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe ## [Unreleased] +## [0.2.19] - 2021-05-11 +### Fixed +- Status display on Windows (issue [#14]) + ## [0.2.18] - 2021-05-07 ### Added - Request rate limiting (default 8 req. / 60 s, option `--rate`, issue [#13]) @@ -99,6 +103,7 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe ## [0.1.0] - 2020-04-21 (undocumented) +[#14]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/14 [#13]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/13 [#11]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/11 [#10]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/10 @@ -114,7 +119,8 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe [@Craeckie]: https://github.com/Craeckie [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 -[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.18...HEAD +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.19...HEAD +[0.2.18]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.18...v0.2.19 [0.2.18]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.17...v0.2.18 [0.2.17]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.16...v0.2.17 [0.2.16]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.15...v0.2.16 diff --git a/Cargo.lock b/Cargo.lock index dd6f736..2ec5957 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.18" +version = "0.2.19" dependencies = [ "anyhow", "atty", diff --git a/Cargo.toml b/Cargo.toml index b32bffc..c31188a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.18" +version = "0.2.19" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-2.0-or-later" edition = "2018" From cea829b79e034492ce438b8d868ce87e4988ece6 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 11 May 2021 19:03:37 +0200 Subject: [PATCH 041/103] Fix deprecation warning --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9853fac..b97bf27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -416,7 +416,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { query_parameters.push(("cmdMode".into(), "asynch".into())); full_url.query_pairs_mut().clear().extend_pairs(&query_parameters).finish(); log!(1, "Loading {}", full_url); - let data = ilias.download(&full_url.into_string()).await?; + let data = ilias.download(full_url.as_str()).await?; let html = data.text().await?; let html = Html::parse_fragment(&html); for row in html.select(&video_tr) { @@ -1321,7 +1321,7 @@ impl URL { } } Ok(URL { - url: url.into_string(), + url: url.into(), baseClass, cmdClass, cmdNode, From d899fcccba5c06c306cddf0545e6a209df55a0a0 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 11 May 2021 19:07:05 +0200 Subject: [PATCH 042/103] Fix typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6c129..0967a1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,7 +120,7 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 [Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.19...HEAD -[0.2.18]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.18...v0.2.19 +[0.2.19]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.18...v0.2.19 [0.2.18]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.17...v0.2.18 [0.2.17]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.16...v0.2.17 [0.2.16]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.15...v0.2.16 From d5037f9ae765ed566f3de400b19bb9ceda4a59e1 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 13 May 2021 11:08:35 +0200 Subject: [PATCH 043/103] Retry requests on HTTP/2 NO_ERROR --- Cargo.lock | 51 +++++++++++++++++++++++++++------------------------ Cargo.toml | 1 + src/main.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 74 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ec5957..57e26c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,6 +13,7 @@ dependencies = [ "futures", "futures-channel", "futures-util", + "h2", "ignore", "indicatif", "keyring", @@ -491,9 +492,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253" +checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" dependencies = [ "futures-channel", "futures-core", @@ -506,9 +507,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25" +checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" dependencies = [ "futures-core", "futures-sink", @@ -516,15 +517,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815" +checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" [[package]] name = "futures-executor" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d" +checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" dependencies = [ "futures-core", "futures-task", @@ -533,16 +534,17 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04" +checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" [[package]] name = "futures-macro" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b" +checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" dependencies = [ + "autocfg", "proc-macro-hack", "proc-macro2", "quote", @@ -551,22 +553,23 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23" +checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" [[package]] name = "futures-task" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc" +checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" [[package]] name = "futures-util" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025" +checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" dependencies = [ + "autocfg", "futures-channel", "futures-core", "futures-io", @@ -1530,18 +1533,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.125" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.125" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ "proc-macro2", "quote", @@ -1589,9 +1592,9 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" [[package]] name = "sha2" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8f6b75b17576b792bef0db1bcc4b8b8bcdf9506744cf34b974195487af6cff2" +checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" dependencies = [ "block-buffer", "cfg-if", diff --git a/Cargo.toml b/Cargo.toml index c31188a..d8880c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ cfg-if = "1.0.0" indicatif = "0.16.0" once_cell = "1.7.2" atty = "0.2.14" +h2 = "0.3.3" [features] default = [] diff --git a/src/main.rs b/src/main.rs index b97bf27..cda1df6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ use tokio::task::{self, JoinHandle}; use tokio_util::io::StreamReader; use url::Url; +use std::error::Error as _; use std::future::Future; use std::io; use std::path::PathBuf; @@ -156,7 +157,7 @@ async fn real_main(mut opt: Opt) -> Result<()> { }; if ilias.opt.content_tree { // need this to get the content tree - if let Err(e) = ilias.client.get("https://ilias.studium.kit.edu/ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=tree&ref_id=1").send().await { + if let Err(e) = ilias.download("ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=tree&ref_id=1").await { warning!("could not enable content tree:", e); } } @@ -167,7 +168,7 @@ async fn real_main(mut opt: Opt) -> Result<()> { PROGRESS_BAR_ENABLED.store(atty::is(atty::Stream::Stdout), Ordering::SeqCst); if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { PROGRESS_BAR.set_draw_target(ProgressDrawTarget::stderr_nohz()); - PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}+] {msg}")); + PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}+] {wide_msg}")); PROGRESS_BAR.inc_length(1); PROGRESS_BAR.set_message("initializing.."); } @@ -192,7 +193,7 @@ async fn real_main(mut opt: Opt) -> Result<()> { // channel is empty => all tasks are completed if ilias.opt.content_tree { // restore fast page loading times - if let Err(e) = ilias.client.get("https://ilias.studium.kit.edu/ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=flat&ref_id=1").send().await { + if let Err(e) = ilias.download("ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=flat&ref_id=1").await { warning!("could not disable content tree:", e); } } @@ -911,6 +912,18 @@ struct ILIAS { client: Client, } +/// Returns true if the error is caused by: +/// "http2 error: protocol error: not a result of an error" +fn error_is_http2(error: &reqwest::Error) -> bool { + error.source() + .map(|x| x.downcast_ref::()) + .flatten() + .map(|x| x.reason()) + .flatten() + .map(|x| x == h2::Reason::NO_ERROR) + .unwrap_or(false) +} + impl ILIAS { async fn login(opt: Opt, user: impl Into, pass: impl Into, ignore: Gitignore) -> Result { let user = user.into(); @@ -975,16 +988,42 @@ impl ILIAS { async fn download(&self, url: &str) -> Result { get_request_ticket().await; log!(2, "Downloading {}", url); - if url.starts_with("http") || url.starts_with("ilias.studium.kit.edu") { - Ok(self.client.get(url).send().await?) + let url = if url.starts_with("http://") || url.starts_with("https://") { + url.to_owned() + } else if url.starts_with("ilias.studium.kit.edu") { + format!("https://{}", url) } else { - Ok(self.client.get(&format!("{}{}", ILIAS_URL, url)).send().await?) + format!("{}{}", ILIAS_URL, url) + }; + for attempt in 1..10 { + let result = self.client.head(url.clone()).send().await; + match result { + Ok(x) => return Ok(x), + Err(e) if attempt <= 3 && error_is_http2(&e) => { + warning!("encountered HTTP/2 NO_ERROR, retrying download.."); + continue + }, + Err(e) => return Err(e.into()) + } } + unreachable!() } async fn head(&self, url: U) -> Result { get_request_ticket().await; - self.client.head(url).send().await + let url = url.into_url()?; + for attempt in 1..10 { + let result = self.client.head(url.clone()).send().await; + match result { + Ok(x) => return Ok(x), + Err(e) if attempt <= 3 && error_is_http2(&e) => { + warning!("encountered HTTP/2 NO_ERROR, retrying download.."); + continue + }, + Err(e) => return Err(e) + } + } + unreachable!() } async fn get_html(&self, url: &str) -> Result { From 218e63f7dbc3e1fc4aad1d240b57f34956227351 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 13 May 2021 12:10:45 +0200 Subject: [PATCH 044/103] Do GET requests when downloading --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index cda1df6..2f79ee3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -996,7 +996,7 @@ impl ILIAS { format!("{}{}", ILIAS_URL, url) }; for attempt in 1..10 { - let result = self.client.head(url.clone()).send().await; + let result = self.client.get(url.clone()).send().await; match result { Ok(x) => return Ok(x), Err(e) if attempt <= 3 && error_is_http2(&e) => { From ec65c74393caadb1a9f8dcc327f612988b9af122 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 13 May 2021 12:11:52 +0200 Subject: [PATCH 045/103] CI: only upload artifacts with keyring enabled --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5921b61..f539780 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - features: ["", "--features keyring-auth"] + features: ["", "--all-features"] steps: - uses: actions/checkout@v2 @@ -50,6 +50,7 @@ jobs: run: cargo test --release ${{ matrix.features }} --verbose - name: Archive artifacts uses: actions/upload-artifact@v2 + if: matrix.features == '--all-features' with: name: Binaries path: | From 29262ea18853351135c24c7b9f75e9dc8aef5f40 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 13 May 2021 13:29:18 +0200 Subject: [PATCH 046/103] Basic shell.nix --- shell.nix | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 shell.nix diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..0ef5a9c --- /dev/null +++ b/shell.nix @@ -0,0 +1,6 @@ +with (import {}); +mkShell { + buildInputs = [ + dbus + ]; +} From 20b3b943278d12926ab83dc129b0bbc7b74d58f0 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 13 May 2021 13:30:05 +0200 Subject: [PATCH 047/103] Version 0.2.20 --- CHANGELOG.md | 9 ++++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0967a1f..f9868ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe ## [Unreleased] +## [0.2.20] - 2021-05-13 +### Fixed +- HTTP/2 [`NO_ERROR`](https://docs.rs/h2/0.3.3/h2/struct.Reason.html#associatedconstant.NO_ERROR) handling (issue [#15]) +- Status display no longer prints every path when running in a small terminal + ## [0.2.19] - 2021-05-11 ### Fixed - Status display on Windows (issue [#14]) @@ -103,6 +108,7 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe ## [0.1.0] - 2020-04-21 (undocumented) +[#15]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/15 [#14]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/14 [#13]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/13 [#11]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/11 @@ -119,7 +125,8 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe [@Craeckie]: https://github.com/Craeckie [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 -[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.19...HEAD +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.20...HEAD +[0.2.20]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.19...v0.2.20 [0.2.19]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.18...v0.2.19 [0.2.18]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.17...v0.2.18 [0.2.17]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.16...v0.2.17 diff --git a/Cargo.lock b/Cargo.lock index 57e26c6..ec166fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.19" +version = "0.2.20" dependencies = [ "anyhow", "atty", diff --git a/Cargo.toml b/Cargo.toml index d8880c2..0b5cf00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.19" +version = "0.2.20" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-2.0-or-later" edition = "2018" diff --git a/src/main.rs b/src/main.rs index 2f79ee3..9c28f86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1017,7 +1017,7 @@ impl ILIAS { match result { Ok(x) => return Ok(x), Err(e) if attempt <= 3 && error_is_http2(&e) => { - warning!("encountered HTTP/2 NO_ERROR, retrying download.."); + warning!("encountered HTTP/2 NO_ERROR, retrying HEAD request.."); continue }, Err(e) => return Err(e) From a6a40f69c8e0960c21f7b607413153c342786d48 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 14 May 2021 14:29:24 +0200 Subject: [PATCH 048/103] Fix automatic output directory creation --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9c28f86..f451a7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,8 +122,8 @@ async fn real_main(mut opt: Opt) -> Result<()> { let _ = colored::control::set_virtual_terminal(true); // use UNC paths on Windows - opt.output = fs::canonicalize(opt.output).await.context("failed to canonicalize output directory")?; create_dir(&opt.output).await.context("failed to create output directory")?; + opt.output = fs::canonicalize(opt.output).await.context("failed to canonicalize output directory")?; // load .iliasignore file opt.output.push(".iliasignore"); From 7d9c27063c5149ae43a93831158de4b8912145b6 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 14 May 2021 15:07:00 +0200 Subject: [PATCH 049/103] Improve installation instructions --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ba179bd..4280459 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,10 @@ Download content from ILIAS. That includes: ## Installation -Go to the [releases](../../releases) and get the executable for your operating system (Windows/Linux only). -Or compile from source (mandatory if you use a Mac): +**Windows/Linux users**: go to the [releases](../../releases) and download the executable for your operating system. +**macOS users**: [Install Rust](https://www.rust-lang.org/tools/install) and compile from source: ``` -$ git clone https://github.com/FliegendeWurst/KIT-ILIAS-downloader -$ cd KIT-ILIAS-downloader -$ cargo install --all-features --path . +$ cargo install --all-features --git 'https://github.com/FliegendeWurst/KIT-ILIAS-downloader' ``` ## Usage @@ -38,7 +36,7 @@ $ KIT-ILIAS-downloader -o ./ILIAS/WS2021-HM1 --sync-url 'https://ilias.studium.k ``` $ KIT-ILIAS-downloader --help -KIT-ILIAS-downloader 0.2.18 +KIT-ILIAS-downloader 0.2.20 USAGE: KIT-ILIAS-downloader [FLAGS] [OPTIONS] --output From 8a1a5f6165f040d33fc682e35c2dc3eecf59ba08 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 17 May 2021 18:05:54 +0200 Subject: [PATCH 050/103] Organize code into modules --- src/cli.rs | 175 ++++++++++++++ src/ilias.rs | 484 +++++++++++++++++++++++++++++++++++++ src/main.rs | 664 ++------------------------------------------------- 3 files changed, 674 insertions(+), 649 deletions(-) create mode 100644 src/cli.rs create mode 100644 src/ilias.rs diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..96dfc7b --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +use std::{path::PathBuf, sync::atomic::{AtomicBool, AtomicUsize}}; + +use anyhow::{anyhow, Context, Result}; +use colored::Colorize as _; +use indicatif::ProgressBar; +use once_cell::sync::Lazy; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +#[structopt(name = env!("CARGO_PKG_NAME"))] +pub struct Opt { + /// Do not download files + #[structopt(short, long)] + pub skip_files: bool, + + /// Do not download Opencast videos + #[structopt(short, long)] + pub no_videos: bool, + + /// Download forum content + #[structopt(short = "t", long)] + pub forum: bool, + + /// Re-download already present files + #[structopt(short)] + pub force: bool, + + /// Use content tree (experimental) + #[structopt(long)] + pub content_tree: bool, + + /// Re-check OpenCast lectures (slow) + #[structopt(long)] + pub check_videos: bool, + + /// Verbose logging + #[structopt(short, multiple = true, parse(from_occurrences))] + pub verbose: usize, + + /// Output directory + #[structopt(short, long, parse(from_os_str))] + pub output: PathBuf, + + /// Parallel download jobs + #[structopt(short, long, default_value = "1")] + pub jobs: usize, + + /// Proxy, e.g. socks5h://127.0.0.1:1080 + #[structopt(short, long)] + pub proxy: Option, + + /// Use the system keyring + #[structopt(long)] + #[cfg(feature = "keyring-auth")] + pub keyring: bool, + + /// KIT account username + #[structopt(short = "U", long)] + pub username: Option, + + /// KIT account password + #[structopt(short = "P", long)] + pub password: Option, + + /// ILIAS page to download + #[structopt(long)] + pub sync_url: Option, + + /// Requests per minute + #[structopt(long, default_value = "8")] + pub rate: usize +} + +pub static LOG_LEVEL: AtomicUsize = AtomicUsize::new(0); +pub static PROGRESS_BAR_ENABLED: AtomicBool = AtomicBool::new(false); +pub static PROGRESS_BAR: Lazy = Lazy::new(|| ProgressBar::new(0)); + +macro_rules! log { + ($lvl:expr, $($t:expr),+) => { + #[allow(unused_comparisons)] // 0 <= 0 + if $lvl <= crate::cli::LOG_LEVEL.load(std::sync::atomic::Ordering::SeqCst) { + if crate::cli::PROGRESS_BAR_ENABLED.load(std::sync::atomic::Ordering::SeqCst) { + crate::cli::PROGRESS_BAR.println(format!($($t),+)); + } else { + println!($($t),+); + } + } + } +} + +macro_rules! info { + ($t:tt) => { + println!($t); + }; +} + +macro_rules! success { + ($t:tt) => { + println!("{}", format!($t).bright_green()); + }; +} + +macro_rules! warning { + ($e:expr) => { + println!("Warning: {}", format!("{:?}", $e).bright_yellow()); + }; + ($msg:expr, $e:expr) => { + println!("Warning: {}", format!("{} {:?}", $msg, $e).bright_yellow()); + }; + ($msg1:expr, $msg2:expr, $e:expr) => { + println!("Warning: {}", format!("{} {} {:?}", $msg1, $msg2, $e).bright_yellow()); + }; + (format => $($e:expr),+) => { + println!("Warning: {}", format!($($e),+).bright_yellow()); + }; +} + +macro_rules! error { + ($($prefix:expr),+; $e:expr) => { + println!("{}: {}", format!($($prefix),+), format!("{:?}", $e).bright_red()); + }; + ($e:expr) => { + println!("Error: {}", format!("{:?}", $e).bright_red()); + }; +} + +pub fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { + let user = if let Some(username) = opt.username.as_ref() { + username.clone() + } else { + rprompt::prompt_reply_stdout("Username: ").context("username prompt")? + }; + #[cfg(feature = "keyring-auth")] + let (pass, should_store); + #[cfg(feature = "keyring-auth")] + let keyring = Lazy::new(|| keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user)); + #[cfg(not(feature = "keyring-auth"))] + let pass; + cfg_if::cfg_if! { // TODO: deduplicate the logic below + if #[cfg(feature = "keyring-auth")] { + if let Some(password) = opt.password.as_ref() { + pass = password.clone(); + should_store = true; + } else if opt.keyring { + match keyring.get_password() { + Ok(password) => { + pass = password; + should_store = false; + }, + Err(e) => { + error!(e); + pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; + should_store = true; + } + } + } else { + pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; + should_store = true; + } + } else { + if let Some(password) = opt.password.as_ref() { + pass = password.clone(); + } else { + pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; + } + } + }; + #[cfg(feature = "keyring-auth")] + if should_store && opt.keyring { + keyring.set_password(&pass).map_err(|x| anyhow!(x.to_string()))?; + } + Ok((user, pass)) +} diff --git a/src/ilias.rs b/src/ilias.rs new file mode 100644 index 0000000..f68ebae --- /dev/null +++ b/src/ilias.rs @@ -0,0 +1,484 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +use std::error::Error as _; + +use anyhow::{anyhow, Context, Result}; +use colored::Colorize; +use ignore::gitignore::Gitignore; +use reqwest::{Client, IntoUrl, Proxy, Url}; +use scraper::{ElementRef, Html, Selector}; +use serde_json::json; + +use crate::{ILIAS_URL, cli::Opt, get_request_ticket, selectors::*}; + +pub struct ILIAS { + pub opt: Opt, + pub ignore: Gitignore, + // TODO: use these for re-authentication in case of session timeout/invalidation + user: String, + pass: String, + client: Client, +} + +/// Returns true if the error is caused by: +/// "http2 error: protocol error: not a result of an error" +fn error_is_http2(error: &reqwest::Error) -> bool { + error.source() // hyper::Error + .map(|x| x.downcast_ref::()) + .flatten() + .map(|x| x.reason()) + .flatten() + .map(|x| x == h2::Reason::NO_ERROR) + .unwrap_or(false) +} + +impl ILIAS { + pub async fn login(opt: Opt, user: impl Into, pass: impl Into, ignore: Gitignore) -> Result { + let user = user.into(); + let pass = pass.into(); + let mut builder = Client::builder() + .cookie_store(true) + .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); + if let Some(proxy) = opt.proxy.as_ref() { + let proxy = Proxy::all(proxy)?; + builder = builder.proxy(proxy); + } + let client = builder + // timeout is infinite by default + .build()?; + let this = ILIAS { opt, ignore, user, pass, client }; + info!("Logging into ILIAS using KIT account.."); + let session_establishment = this.client + .post("https://ilias.studium.kit.edu/Shibboleth.sso/Login") + .form(&json!({ + "sendLogin": "1", + "idp_selection": "https://idp.scc.kit.edu/idp/shibboleth", + "target": "/shib_login.php?target=", + "home_organization_selection": "Mit KIT-Account anmelden" + })) + .send().await?; + let url = session_establishment.url().clone(); + let text = session_establishment.text().await?; + let dom_sso = Html::parse_document(text.as_str()); + let csrf_token = dom_sso + .select(&Selector::parse(r#"input[name="csrf_token"]"#).unwrap()) + .next().context("no csrf token")?; + info!("Logging into Shibboleth.."); + let login_response = this.client + .post(url) + .form(&json!({ + "j_username": &this.user, + "j_password": &this.pass, + "_eventId_proceed": "", + "csrf_token": csrf_token.value().attr("value").context("no csrf token")?, + })) + .send().await? + .text().await?; + let dom = Html::parse_document(&login_response); + let saml = Selector::parse(r#"input[name="SAMLResponse"]"#).unwrap(); + let saml = dom + .select(&saml) + .next().context("no SAML response, incorrect password?")?; + let relay_state = Selector::parse(r#"input[name="RelayState"]"#).unwrap(); + let relay_state = dom.select(&relay_state).next().context("no relay state")?; + info!("Logging into ILIAS.."); + this.client + .post("https://ilias.studium.kit.edu/Shibboleth.sso/SAML2/POST") + .form(&json!({ + "SAMLResponse": saml.value().attr("value").context("no SAML value")?, + "RelayState": relay_state.value().attr("value").context("no RelayState value")? + })) + .send().await?; + success!("Logged in!"); + Ok(this) + } + + pub async fn download(&self, url: &str) -> Result { + get_request_ticket().await; + log!(2, "Downloading {}", url); + let url = if url.starts_with("http://") || url.starts_with("https://") { + url.to_owned() + } else if url.starts_with("ilias.studium.kit.edu") { + format!("https://{}", url) + } else { + format!("{}{}", ILIAS_URL, url) + }; + for attempt in 1..10 { + let result = self.client.get(url.clone()).send().await; + match result { + Ok(x) => return Ok(x), + Err(e) if attempt <= 3 && error_is_http2(&e) => { + warning!("encountered HTTP/2 NO_ERROR, retrying download.."); + continue + }, + Err(e) => return Err(e.into()) + } + } + unreachable!() + } + + pub async fn head(&self, url: U) -> Result { + get_request_ticket().await; + let url = url.into_url()?; + for attempt in 1..10 { + let result = self.client.head(url.clone()).send().await; + match result { + Ok(x) => return Ok(x), + Err(e) if attempt <= 3 && error_is_http2(&e) => { + warning!("encountered HTTP/2 NO_ERROR, retrying HEAD request.."); + continue + }, + Err(e) => return Err(e) + } + } + unreachable!() + } + + pub async fn get_html(&self, url: &str) -> Result { + let text = self.download(url).await?.text().await?; + let html = Html::parse_document(&text); + if html.select(&alert_danger).next().is_some() { + Err(anyhow!("ILIAS error")) + } else { + Ok(html) + } + } + + pub async fn get_html_fragment(&self, url: &str) -> Result { + let text = self.download(url).await?.text().await?; + let html = Html::parse_fragment(&text); + if html.select(&alert_danger).next().is_some() { + Err(anyhow!("ILIAS error")) + } else { + Ok(html) + } + } + + pub fn get_items(html: &Html) -> Vec> { + html.select(&container_items) + .flat_map(|item| { + item.select(&container_item_title) + .next() + .map(|link| Object::from_link(item, link)) + // items without links are ignored + }) + .collect() + } + + /// Returns subfolders and the main text on the course page. + pub async fn get_course_content(&self, url: &URL) -> Result<(Vec>, Option)> { + let html = self.get_html(&url.url).await?; + let main_text = if let Some(el) = html.select(&il_content_container).next() { + if !el.children().flat_map(|x| x.value().as_element()).next().map(|x| + x.attr("class").unwrap_or_default().contains("ilContainerBlock")).unwrap_or(false) + && el.inner_html().len() > 40 { + // ^ minimum length of useful content? + Some(el.inner_html()) + } else { + // first element is the content overview => no custom text (?) + None + } + } else { + None + }; + Ok((ILIAS::get_items(&html), main_text)) + } + + pub async fn personal_desktop(&self) -> Result { + let html = self.get_html("https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems").await?; + let items = ILIAS::get_items(&html) + .into_iter() + .flat_map(Result::ok) + .collect(); + Ok(Dashboard { items }) + } + + pub async fn get_course_content_tree(&self, ref_id: &str, cmd_node: &str) -> Result> { + // TODO: this magically does not return sub-folders + // opening the same url in browser does show sub-folders?! + let url = format!( + "{}ilias.php?ref_id={}&cmdClass=ilobjcoursegui&cmd=showRepTree&cmdNode={}&baseClass=ilRepositoryGUI&cmdMode=asynch&exp_cmd=getNodeAsync&node_id=exp_node_rep_exp_{}&exp_cont=il_expl2_jstree_cont_rep_exp&searchterm=", + ILIAS_URL, ref_id, cmd_node, ref_id + ); + let html = self.get_html_fragment(&url).await?; + let mut items = Vec::new(); + for link in html.select(&a) { + if link.value().attr("href").is_some() { + items.push(Object::from_link(link, link)?); + } // else: disabled course + } + Ok(items) + } +} + +#[derive(Debug)] +pub struct Dashboard { + pub items: Vec, +} + +#[derive(Debug)] +pub enum Object { + Course { name: String, url: URL }, + Folder { name: String, url: URL }, + File { name: String, url: URL }, + Forum { name: String, url: URL }, + Thread { url: URL }, + Wiki { name: String, url: URL }, + ExerciseHandler { name: String, url: URL }, + Weblink { name: String, url: URL }, + Survey { name: String, url: URL }, + Presentation { name: String, url: URL }, + PluginDispatch { name: String, url: URL }, + Video { url: URL }, + Generic { name: String, url: URL }, +} + +use Object::*; + +impl Object { + pub fn name(&self) -> &str { + match self { + Course { name, .. } + | Folder { name, .. } + | File { name, .. } + | Forum { name, .. } + | Wiki { name, .. } + | Weblink { name, .. } + | Survey { name, .. } + | Presentation { name, .. } + | ExerciseHandler { name, .. } + | PluginDispatch { name, .. } + | Generic { name, .. } => &name, + Thread { url } => &url.thr_pk.as_ref().unwrap(), + Video { url } => &url.url, + } + } + + pub fn url(&self) -> &URL { + match self { + Course { url, .. } + | Folder { url, .. } + | File { url, .. } + | Forum { url, .. } + | Thread { url } + | Wiki { url, .. } + | Weblink { url, .. } + | Survey { url, .. } + | Presentation { url, .. } + | ExerciseHandler { url, .. } + | PluginDispatch { url, .. } + | Video { url } + | Generic { url, .. } => &url, + } + } + + pub fn kind(&self) -> &str { + match self { + Course { .. } => "course", + Folder { .. } => "folder", + File { .. } => "file", + Forum { .. } => "forum", + Thread { .. } => "thread", + Wiki { .. } => "wiki", + Weblink { .. } => "weblink", + Survey { .. } => "survey", + Presentation { .. } => "presentation", + ExerciseHandler { .. } => "exercise handler", + PluginDispatch { .. } => "plugin dispatch", + Video { .. } => "video", + Generic { .. } => "generic", + } + } + + pub fn is_dir(&self) -> bool { + match self { + Course { .. } + | Folder { .. } + | Forum { .. } + | Thread { .. } + | Wiki { .. } + | ExerciseHandler { .. } + | PluginDispatch { .. } => true, + _ => false, + } + } + + pub fn from_link(item: ElementRef, link: ElementRef) -> Result { + let name = link + .text() + .collect::() + .replace('/', "-") + .trim() + .to_owned(); + let url = URL::from_href(link.value().attr("href").context("link missing href")?)?; + Object::from_url(url, name, Some(item)) + } + + pub fn from_url(mut url: URL, mut name: String, item: Option) -> Result { + if url.thr_pk.is_some() { + return Ok(Thread { url }); + } + + if url + .url + .starts_with("https://ilias.studium.kit.edu/goto.php") + { + let target = url.target.as_deref().unwrap_or("NONE"); + if target.starts_with("wiki_") { + return Ok(Wiki { + name, + url, // TODO: insert ref_id here + }); + } + if target.starts_with("root_") { + // magazine link + return Ok(Generic { name, url }); + } + if target.starts_with("crs_") { + let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); + url.ref_id = ref_id.to_owned(); + return Ok(Course { name, url }); + } + if target.starts_with("frm_") { + // TODO: extract post link? (this codepath should only be hit when parsing the content tree) + let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); + url.ref_id = ref_id.to_owned(); + return Ok(Forum { name, url }); + } + if target.starts_with("lm_") { + // fancy interactive task + return Ok(Presentation { name, url }); + } + if target.starts_with("fold_") { + let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); + url.ref_id = ref_id.to_owned(); + return Ok(Folder { name, url }); + } + if target.starts_with("file_") { + if !target.ends_with("download") { + // download page containing metadata + return Ok(Generic { name, url }); + } else { + let mut item_props = item.context("can't construct file object without HTML object")?.select(&item_prop); + let ext = item_props.next().context("cannot find file extension")?; + let version = item_props + .nth(1) + .context("cannot find 3rd file metadata")? + .text() + .collect::(); + let version = version.trim(); + if let Some(v) = version.strip_prefix("Version: ") { + name += "_v"; + name += v; + } + return Ok(File { + name: format!("{}.{}", name, ext.text().collect::().trim()), + url, + }); + } + } + return Ok(Generic { name, url }); + } + + if url.cmd.as_deref() == Some("showThreads") { + return Ok(Forum { name, url }); + } + + // class name is *sometimes* in CamelCase + Ok(match &*url.baseClass.to_ascii_lowercase() { + "ilexercisehandlergui" => ExerciseHandler { name, url }, + "ililwikihandlergui" => Wiki { name, url }, + "illinkresourcehandlergui" => Weblink { name, url }, + "ilobjsurveygui" => Survey { name, url }, + "illmpresentationgui" => Presentation { name, url }, + "ilrepositorygui" => match url.cmd.as_deref() { + Some("view") | Some("render") => Folder { name, url }, + Some(_) => Generic { name, url }, + None => Course { name, url }, + }, + "ilobjplugindispatchgui" => PluginDispatch { name, url }, + _ => Generic { name, url }, + }) + } +} + +#[allow(non_snake_case)] +#[derive(Debug)] +pub struct URL { + pub url: String, + baseClass: String, + cmdClass: Option, + cmdNode: Option, + pub cmd: Option, + forwardCmd: Option, + pub thr_pk: Option, + pos_pk: Option, + pub ref_id: String, + target: Option, + file: Option, +} + +#[allow(non_snake_case)] +impl URL { + pub fn raw(url: String) -> Self { + URL { + url, + baseClass: String::new(), + cmdClass: None, + cmdNode: None, + cmd: None, + forwardCmd: None, + thr_pk: None, + pos_pk: None, + ref_id: String::new(), + target: None, + file: None, + } + } + + pub fn from_href(href: &str) -> Result { + let url = if !href.starts_with(ILIAS_URL) { + Url::parse(&format!("{}{}", ILIAS_URL, href))? + } else { + Url::parse(href)? + }; + let mut baseClass = String::new(); + let mut cmdClass = None; + let mut cmdNode = None; + let mut cmd = None; + let mut forwardCmd = None; + let mut thr_pk = None; + let mut pos_pk = None; + let mut ref_id = String::new(); + let mut target = None; + let mut file = None; + for (k, v) in url.query_pairs() { + match &*k { + "baseClass" => baseClass = v.into_owned(), + "cmdClass" => cmdClass = Some(v.into_owned()), + "cmdNode" => cmdNode = Some(v.into_owned()), + "cmd" => cmd = Some(v.into_owned()), + "forwardCmd" => forwardCmd = Some(v.into_owned()), + "thr_pk" => thr_pk = Some(v.into_owned()), + "pos_pk" => pos_pk = Some(v.into_owned()), + "ref_id" => ref_id = v.into_owned(), + "target" => target = Some(v.into_owned()), + "file" => file = Some(v.into_owned()), + _ => {}, + } + } + Ok(URL { + url: url.into(), + baseClass, + cmdClass, + cmdNode, + cmd, + forwardCmd, + thr_pk, + pos_pk, + ref_id, + target, + file, + }) + } +} diff --git a/src/main.rs b/src/main.rs index f451a7e..227b9b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,42 +6,42 @@ use anyhow::{anyhow, Context, Result}; use colored::Colorize; use futures::future::{self, Either}; use futures_channel::mpsc::UnboundedSender; -use futures_util::{stream::TryStreamExt, StreamExt}; +use futures_util::stream::TryStreamExt; +use futures_util::StreamExt; use ignore::gitignore::Gitignore; -use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle}; +use indicatif::{ProgressDrawTarget, ProgressStyle}; use once_cell::sync::{Lazy, OnceCell}; -use reqwest::{Client, IntoUrl, Proxy}; -use scraper::{ElementRef, Html, Selector}; -use serde_json::json; +use scraper::Html; use structopt::StructOpt; use tokio::{fs, sync::Semaphore, time}; use tokio::task::{self, JoinHandle}; use tokio_util::io::StreamReader; use url::Url; -use std::error::Error as _; use std::future::Future; use std::io; use std::path::PathBuf; -use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use std::sync::atomic::Ordering; use std::sync::Arc; use std::collections::HashSet; +pub const ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; + +#[macro_use] +mod cli; +use cli::*; +mod ilias; +use ilias::*; +use Object::*; mod util; use util::*; -const ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; - -static LOG_LEVEL: AtomicUsize = AtomicUsize::new(0); -static PROGRESS_BAR_ENABLED: AtomicBool = AtomicBool::new(false); -static PROGRESS_BAR: Lazy = Lazy::new(|| ProgressBar::new(0)); - /// Global job queue static TASKS: OnceCell>> = OnceCell::new(); static TASKS_RUNNING: Lazy = Lazy::new(|| Semaphore::new(0)); static REQUEST_TICKETS: Lazy = Lazy::new(|| Semaphore::new(0)); -async fn get_request_ticket() { +pub async fn get_request_ticket() { REQUEST_TICKETS.acquire().await.unwrap().forget(); } @@ -51,55 +51,6 @@ macro_rules! spawn { }; } -macro_rules! log { - ($lvl:expr, $($t:expr),+) => { - #[allow(unused_comparisons)] // 0 <= 0 - if $lvl <= LOG_LEVEL.load(Ordering::SeqCst) { - if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { - PROGRESS_BAR.println(format!($($t),+)); - } else { - println!($($t),+); - } - } - } -} - -macro_rules! info { - ($t:tt) => { - println!($t); - }; -} - -macro_rules! success { - ($t:tt) => { - println!("{}", format!($t).bright_green()); - }; -} - -macro_rules! warning { - ($e:expr) => { - println!("Warning: {}", format!("{:?}", $e).bright_yellow()); - }; - ($msg:expr, $e:expr) => { - println!("Warning: {}", format!("{} {:?}", $msg, $e).bright_yellow()); - }; - ($msg1:expr, $msg2:expr, $e:expr) => { - println!("Warning: {}", format!("{} {} {:?}", $msg1, $msg2, $e).bright_yellow()); - }; - (format => $($e:expr),+) => { - println!("Warning: {}", format!($($e),+).bright_yellow()); - }; -} - -macro_rules! error { - ($($prefix:expr),+; $e:expr) => { - println!("{}: {}", format!($($prefix),+), format!("{:?}", $e).bright_red()); - }; - ($e:expr) => { - println!("Error: {}", format!("{:?}", $e).bright_red()); - }; -} - #[tokio::main] async fn main() { let opt = Opt::from_args(); @@ -199,60 +150,12 @@ async fn real_main(mut opt: Opt) -> Result<()> { } if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { PROGRESS_BAR.inc(1); - PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}] {msg}")); + PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}] {wide_msg}")); PROGRESS_BAR.finish_with_message("done"); } Ok(()) } -fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { - let user = if let Some(username) = opt.username.as_ref() { - username.clone() - } else { - rprompt::prompt_reply_stdout("Username: ").context("username prompt")? - }; - #[cfg(feature = "keyring-auth")] - let (pass, should_store); - #[cfg(feature = "keyring-auth")] - let keyring = Lazy::new(|| keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user)); - #[cfg(not(feature = "keyring-auth"))] - let pass; - cfg_if::cfg_if! { // TODO: deduplicate the logic below - if #[cfg(feature = "keyring-auth")] { - if let Some(password) = opt.password.as_ref() { - pass = password.clone(); - should_store = true; - } else if opt.keyring { - match keyring.get_password() { - Ok(password) => { - pass = password; - should_store = false; - }, - Err(e) => { - error!(e); - pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; - should_store = true; - } - } - } else { - pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; - should_store = true; - } - } else { - if let Some(password) = opt.password.as_ref() { - pass = password.clone(); - } else { - pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; - } - } - }; - #[cfg(feature = "keyring-auth")] - if should_store && opt.keyring { - keyring.set_password(&pass).map_err(|x| anyhow!(x.to_string()))?; - } - Ok((user, pass)) -} - // https://github.com/rust-lang/rust/issues/53690#issuecomment-418911229 #[allow(clippy::manual_async_fn)] fn process_gracefully( @@ -837,540 +740,3 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { } Ok(()) } - -#[derive(Debug, StructOpt)] -#[structopt(name = env!("CARGO_PKG_NAME"))] -struct Opt { - /// Do not download files - #[structopt(short, long)] - skip_files: bool, - - /// Do not download Opencast videos - #[structopt(short, long)] - no_videos: bool, - - /// Download forum content - #[structopt(short = "t", long)] - forum: bool, - - /// Re-download already present files - #[structopt(short)] - force: bool, - - /// Use content tree (experimental) - #[structopt(long)] - content_tree: bool, - - /// Re-check OpenCast lectures (slow) - #[structopt(long)] - check_videos: bool, - - /// Verbose logging - #[structopt(short, multiple = true, parse(from_occurrences))] - verbose: usize, - - /// Output directory - #[structopt(short, long, parse(from_os_str))] - output: PathBuf, - - /// Parallel download jobs - #[structopt(short, long, default_value = "1")] - jobs: usize, - - /// Proxy, e.g. socks5h://127.0.0.1:1080 - #[structopt(short, long)] - proxy: Option, - - /// Use the system keyring - #[structopt(long)] - #[cfg(feature = "keyring-auth")] - keyring: bool, - - /// KIT account username - #[structopt(short = "U", long)] - username: Option, - - /// KIT account password - #[structopt(short = "P", long)] - password: Option, - - /// ILIAS page to download - #[structopt(long)] - sync_url: Option, - - /// Requests per minute - #[structopt(long, default_value = "8")] - rate: usize -} - -struct ILIAS { - opt: Opt, - ignore: Gitignore, - // TODO: use these for re-authentication in case of session timeout/invalidation - user: String, - pass: String, - client: Client, -} - -/// Returns true if the error is caused by: -/// "http2 error: protocol error: not a result of an error" -fn error_is_http2(error: &reqwest::Error) -> bool { - error.source() - .map(|x| x.downcast_ref::()) - .flatten() - .map(|x| x.reason()) - .flatten() - .map(|x| x == h2::Reason::NO_ERROR) - .unwrap_or(false) -} - -impl ILIAS { - async fn login(opt: Opt, user: impl Into, pass: impl Into, ignore: Gitignore) -> Result { - let user = user.into(); - let pass = pass.into(); - let mut builder = Client::builder() - .cookie_store(true) - .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); - if let Some(proxy) = opt.proxy.as_ref() { - let proxy = Proxy::all(proxy)?; - builder = builder.proxy(proxy); - } - let client = builder - // timeout is infinite by default - .build()?; - let this = ILIAS { opt, ignore, user, pass, client }; - info!("Logging into ILIAS using KIT account.."); - let session_establishment = this.client - .post("https://ilias.studium.kit.edu/Shibboleth.sso/Login") - .form(&json!({ - "sendLogin": "1", - "idp_selection": "https://idp.scc.kit.edu/idp/shibboleth", - "target": "/shib_login.php?target=", - "home_organization_selection": "Mit KIT-Account anmelden" - })) - .send().await?; - let url = session_establishment.url().clone(); - let text = session_establishment.text().await?; - let dom_sso = Html::parse_document(text.as_str()); - let csrf_token = dom_sso - .select(&Selector::parse(r#"input[name="csrf_token"]"#).unwrap()) - .next().context("no csrf token")?; - info!("Logging into Shibboleth.."); - let login_response = this.client - .post(url) - .form(&json!({ - "j_username": &this.user, - "j_password": &this.pass, - "_eventId_proceed": "", - "csrf_token": csrf_token.value().attr("value").context("no csrf token")?, - })) - .send().await? - .text().await?; - let dom = Html::parse_document(&login_response); - let saml = Selector::parse(r#"input[name="SAMLResponse"]"#).unwrap(); - let saml = dom - .select(&saml) - .next().context("no SAML response, incorrect password?")?; - let relay_state = Selector::parse(r#"input[name="RelayState"]"#).unwrap(); - let relay_state = dom.select(&relay_state).next().context("no relay state")?; - info!("Logging into ILIAS.."); - this.client - .post("https://ilias.studium.kit.edu/Shibboleth.sso/SAML2/POST") - .form(&json!({ - "SAMLResponse": saml.value().attr("value").context("no SAML value")?, - "RelayState": relay_state.value().attr("value").context("no RelayState value")? - })) - .send().await?; - success!("Logged in!"); - Ok(this) - } - - async fn download(&self, url: &str) -> Result { - get_request_ticket().await; - log!(2, "Downloading {}", url); - let url = if url.starts_with("http://") || url.starts_with("https://") { - url.to_owned() - } else if url.starts_with("ilias.studium.kit.edu") { - format!("https://{}", url) - } else { - format!("{}{}", ILIAS_URL, url) - }; - for attempt in 1..10 { - let result = self.client.get(url.clone()).send().await; - match result { - Ok(x) => return Ok(x), - Err(e) if attempt <= 3 && error_is_http2(&e) => { - warning!("encountered HTTP/2 NO_ERROR, retrying download.."); - continue - }, - Err(e) => return Err(e.into()) - } - } - unreachable!() - } - - async fn head(&self, url: U) -> Result { - get_request_ticket().await; - let url = url.into_url()?; - for attempt in 1..10 { - let result = self.client.head(url.clone()).send().await; - match result { - Ok(x) => return Ok(x), - Err(e) if attempt <= 3 && error_is_http2(&e) => { - warning!("encountered HTTP/2 NO_ERROR, retrying HEAD request.."); - continue - }, - Err(e) => return Err(e) - } - } - unreachable!() - } - - async fn get_html(&self, url: &str) -> Result { - let text = self.download(url).await?.text().await?; - let html = Html::parse_document(&text); - if html.select(&alert_danger).next().is_some() { - Err(anyhow!("ILIAS error")) - } else { - Ok(html) - } - } - - async fn get_html_fragment(&self, url: &str) -> Result { - let text = self.download(url).await?.text().await?; - let html = Html::parse_fragment(&text); - if html.select(&alert_danger).next().is_some() { - Err(anyhow!("ILIAS error")) - } else { - Ok(html) - } - } - - fn get_items(html: &Html) -> Vec> { - html.select(&container_items) - .flat_map(|item| { - item.select(&container_item_title) - .next() - .map(|link| Object::from_link(item, link)) - // items without links are ignored - }) - .collect() - } - - /// Returns subfolders and the main text on the course page. - async fn get_course_content(&self, url: &URL) -> Result<(Vec>, Option)> { - let html = self.get_html(&url.url).await?; - let main_text = if let Some(el) = html.select(&il_content_container).next() { - if !el.children().flat_map(|x| x.value().as_element()).next().map(|x| - x.attr("class").unwrap_or_default().contains("ilContainerBlock")).unwrap_or(false) - && el.inner_html().len() > 40 { - // ^ minimum length of useful content? - Some(el.inner_html()) - } else { - // first element is the content overview => no custom text (?) - None - } - } else { - None - }; - Ok((ILIAS::get_items(&html), main_text)) - } - - async fn personal_desktop(&self) -> Result { - let html = self.get_html("https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems").await?; - let items = ILIAS::get_items(&html) - .into_iter() - .flat_map(Result::ok) - .collect(); - Ok(Dashboard { items }) - } - - async fn get_course_content_tree(&self, ref_id: &str, cmd_node: &str) -> Result> { - // TODO: this magically does not return sub-folders - // opening the same url in browser does show sub-folders?! - let url = format!( - "{}ilias.php?ref_id={}&cmdClass=ilobjcoursegui&cmd=showRepTree&cmdNode={}&baseClass=ilRepositoryGUI&cmdMode=asynch&exp_cmd=getNodeAsync&node_id=exp_node_rep_exp_{}&exp_cont=il_expl2_jstree_cont_rep_exp&searchterm=", - ILIAS_URL, ref_id, cmd_node, ref_id - ); - let html = self.get_html_fragment(&url).await?; - let mut items = Vec::new(); - for link in html.select(&a) { - if link.value().attr("href").is_some() { - items.push(Object::from_link(link, link)?); - } // else: disabled course - } - Ok(items) - } -} - -#[derive(Debug)] -struct Dashboard { - items: Vec, -} - -#[derive(Debug)] -enum Object { - Course { name: String, url: URL }, - Folder { name: String, url: URL }, - File { name: String, url: URL }, - Forum { name: String, url: URL }, - Thread { url: URL }, - Wiki { name: String, url: URL }, - ExerciseHandler { name: String, url: URL }, - Weblink { name: String, url: URL }, - Survey { name: String, url: URL }, - Presentation { name: String, url: URL }, - PluginDispatch { name: String, url: URL }, - Video { url: URL }, - Generic { name: String, url: URL }, -} - -use Object::*; - -impl Object { - fn name(&self) -> &str { - match self { - Course { name, .. } - | Folder { name, .. } - | File { name, .. } - | Forum { name, .. } - | Wiki { name, .. } - | Weblink { name, .. } - | Survey { name, .. } - | Presentation { name, .. } - | ExerciseHandler { name, .. } - | PluginDispatch { name, .. } - | Generic { name, .. } => &name, - Thread { url } => &url.thr_pk.as_ref().unwrap(), - Video { url } => &url.url, - } - } - - fn url(&self) -> &URL { - match self { - Course { url, .. } - | Folder { url, .. } - | File { url, .. } - | Forum { url, .. } - | Thread { url } - | Wiki { url, .. } - | Weblink { url, .. } - | Survey { url, .. } - | Presentation { url, .. } - | ExerciseHandler { url, .. } - | PluginDispatch { url, .. } - | Video { url } - | Generic { url, .. } => &url, - } - } - - fn kind(&self) -> &str { - match self { - Course { .. } => "course", - Folder { .. } => "folder", - File { .. } => "file", - Forum { .. } => "forum", - Thread { .. } => "thread", - Wiki { .. } => "wiki", - Weblink { .. } => "weblink", - Survey { .. } => "survey", - Presentation { .. } => "presentation", - ExerciseHandler { .. } => "exercise handler", - PluginDispatch { .. } => "plugin dispatch", - Video { .. } => "video", - Generic { .. } => "generic", - } - } - - fn is_dir(&self) -> bool { - match self { - Course { .. } - | Folder { .. } - | Forum { .. } - | Thread { .. } - | Wiki { .. } - | ExerciseHandler { .. } - | PluginDispatch { .. } => true, - _ => false, - } - } - - fn from_link(item: ElementRef, link: ElementRef) -> Result { - let name = link - .text() - .collect::() - .replace('/', "-") - .trim() - .to_owned(); - let url = URL::from_href(link.value().attr("href").context("link missing href")?)?; - Object::from_url(url, name, Some(item)) - } - - fn from_url(mut url: URL, mut name: String, item: Option) -> Result { - if url.thr_pk.is_some() { - return Ok(Thread { url }); - } - - if url - .url - .starts_with("https://ilias.studium.kit.edu/goto.php") - { - let target = url.target.as_deref().unwrap_or("NONE"); - if target.starts_with("wiki_") { - return Ok(Wiki { - name, - url, // TODO: insert ref_id here - }); - } - if target.starts_with("root_") { - // magazine link - return Ok(Generic { name, url }); - } - if target.starts_with("crs_") { - let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); - url.ref_id = ref_id.to_owned(); - return Ok(Course { name, url }); - } - if target.starts_with("frm_") { - // TODO: extract post link? (this codepath should only be hit when parsing the content tree) - let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); - url.ref_id = ref_id.to_owned(); - return Ok(Forum { name, url }); - } - if target.starts_with("lm_") { - // fancy interactive task - return Ok(Presentation { name, url }); - } - if target.starts_with("fold_") { - let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); - url.ref_id = ref_id.to_owned(); - return Ok(Folder { name, url }); - } - if target.starts_with("file_") { - if !target.ends_with("download") { - // download page containing metadata - return Ok(Generic { name, url }); - } else { - let mut item_props = item.context("can't construct file object without HTML object")?.select(&item_prop); - let ext = item_props.next().context("cannot find file extension")?; - let version = item_props - .nth(1) - .context("cannot find 3rd file metadata")? - .text() - .collect::(); - let version = version.trim(); - if let Some(v) = version.strip_prefix("Version: ") { - name += "_v"; - name += v; - } - return Ok(File { - name: format!("{}.{}", name, ext.text().collect::().trim()), - url, - }); - } - } - return Ok(Generic { name, url }); - } - - if url.cmd.as_deref() == Some("showThreads") { - return Ok(Forum { name, url }); - } - - // class name is *sometimes* in CamelCase - Ok(match &*url.baseClass.to_ascii_lowercase() { - "ilexercisehandlergui" => ExerciseHandler { name, url }, - "ililwikihandlergui" => Wiki { name, url }, - "illinkresourcehandlergui" => Weblink { name, url }, - "ilobjsurveygui" => Survey { name, url }, - "illmpresentationgui" => Presentation { name, url }, - "ilrepositorygui" => match url.cmd.as_deref() { - Some("view") | Some("render") => Folder { name, url }, - Some(_) => Generic { name, url }, - None => Course { name, url }, - }, - "ilobjplugindispatchgui" => PluginDispatch { name, url }, - _ => Generic { name, url }, - }) - } -} - -#[allow(non_snake_case)] -#[derive(Debug)] -struct URL { - url: String, - baseClass: String, - cmdClass: Option, - cmdNode: Option, - cmd: Option, - forwardCmd: Option, - thr_pk: Option, - pos_pk: Option, - ref_id: String, - target: Option, - file: Option, -} - -#[allow(non_snake_case)] -impl URL { - fn raw(url: String) -> Self { - URL { - url, - baseClass: String::new(), - cmdClass: None, - cmdNode: None, - cmd: None, - forwardCmd: None, - thr_pk: None, - pos_pk: None, - ref_id: String::new(), - target: None, - file: None, - } - } - - fn from_href(href: &str) -> Result { - let url = if !href.starts_with(ILIAS_URL) { - Url::parse(&format!("{}{}", ILIAS_URL, href))? - } else { - Url::parse(href)? - }; - let mut baseClass = String::new(); - let mut cmdClass = None; - let mut cmdNode = None; - let mut cmd = None; - let mut forwardCmd = None; - let mut thr_pk = None; - let mut pos_pk = None; - let mut ref_id = String::new(); - let mut target = None; - let mut file = None; - for (k, v) in url.query_pairs() { - match &*k { - "baseClass" => baseClass = v.into_owned(), - "cmdClass" => cmdClass = Some(v.into_owned()), - "cmdNode" => cmdNode = Some(v.into_owned()), - "cmd" => cmd = Some(v.into_owned()), - "forwardCmd" => forwardCmd = Some(v.into_owned()), - "thr_pk" => thr_pk = Some(v.into_owned()), - "pos_pk" => pos_pk = Some(v.into_owned()), - "ref_id" => ref_id = v.into_owned(), - "target" => target = Some(v.into_owned()), - "file" => file = Some(v.into_owned()), - _ => {}, - } - } - Ok(URL { - url: url.into(), - baseClass, - cmdClass, - cmdNode, - cmd, - forwardCmd, - thr_pk, - pos_pk, - ref_id, - target, - file, - }) - } -} From 044caf497ce54beeba02bc4728d26d842c36367a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 17 May 2021 18:06:25 +0200 Subject: [PATCH 051/103] Actually correct handling of HTTP/2 NO_ERROR --- src/ilias.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ilias.rs b/src/ilias.rs index f68ebae..5f08f8b 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -24,6 +24,8 @@ pub struct ILIAS { /// "http2 error: protocol error: not a result of an error" fn error_is_http2(error: &reqwest::Error) -> bool { error.source() // hyper::Error + .map(|x| x.source()) // -> h2::Error + .flatten() .map(|x| x.downcast_ref::()) .flatten() .map(|x| x.reason()) From 6d4a1903fb05efc8f0eaed13650383341680a671 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 17 May 2021 18:12:11 +0200 Subject: [PATCH 052/103] Fix logging when the progress bar is enabled --- src/cli.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 96dfc7b..12fc826 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,7 +2,10 @@ use std::{path::PathBuf, sync::atomic::{AtomicBool, AtomicUsize}}; -use anyhow::{anyhow, Context, Result}; +#[cfg(feature = "keyring-auth")] +use anyhow::anyhow; +use anyhow::{Context, Result}; +#[cfg(feature = "keyring-auth")] use colored::Colorize as _; use indicatif::ProgressBar; use once_cell::sync::Lazy; @@ -92,37 +95,37 @@ macro_rules! log { macro_rules! info { ($t:tt) => { - println!($t); + log!(0, $t); }; } macro_rules! success { ($t:tt) => { - println!("{}", format!($t).bright_green()); + log!(0, "{}", format!($t).bright_green()); }; } macro_rules! warning { ($e:expr) => { - println!("Warning: {}", format!("{:?}", $e).bright_yellow()); + log!(0, "Warning: {}", format!("{:?}", $e).bright_yellow()); }; ($msg:expr, $e:expr) => { - println!("Warning: {}", format!("{} {:?}", $msg, $e).bright_yellow()); + log!(0, "Warning: {}", format!("{} {:?}", $msg, $e).bright_yellow()); }; ($msg1:expr, $msg2:expr, $e:expr) => { - println!("Warning: {}", format!("{} {} {:?}", $msg1, $msg2, $e).bright_yellow()); + log!(0, "Warning: {}", format!("{} {} {:?}", $msg1, $msg2, $e).bright_yellow()); }; (format => $($e:expr),+) => { - println!("Warning: {}", format!($($e),+).bright_yellow()); + log!(0, "Warning: {}", format!($($e),+).bright_yellow()); }; } macro_rules! error { ($($prefix:expr),+; $e:expr) => { - println!("{}: {}", format!($($prefix),+), format!("{:?}", $e).bright_red()); + log!(0, "{}: {}", format!($($prefix),+), format!("{:?}", $e).bright_red()); }; ($e:expr) => { - println!("Error: {}", format!("{:?}", $e).bright_red()); + log!(0, "Error: {}", format!("{:?}", $e).bright_red()); }; } From b23192e7bcc718cedf78c935e4a746d3ca2bf81a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 17 May 2021 18:22:34 +0200 Subject: [PATCH 053/103] Update changelog, CI config and dependencies --- .github/workflows/ci.yml | 1 + CHANGELOG.md | 5 ++++- Cargo.lock | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f539780..6034d4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,7 @@ jobs: - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: + profile: minimal toolchain: stable - name: Cache cargo directories diff --git a/CHANGELOG.md b/CHANGELOG.md index f9868ac..049ded0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project loosely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Automatic output directory creation +- HTTP/2 [`NO_ERROR`](https://docs.rs/h2/0.3.3/h2/struct.Reason.html#associatedconstant.NO_ERROR) handling (issue [#15]) +- Correct logging output when the progress bar is displayed ## [0.2.20] - 2021-05-13 ### Fixed -- HTTP/2 [`NO_ERROR`](https://docs.rs/h2/0.3.3/h2/struct.Reason.html#associatedconstant.NO_ERROR) handling (issue [#15]) - Status display no longer prints every path when running in a small terminal ## [0.2.19] - 2021-05-11 diff --git a/Cargo.lock b/Cargo.lock index ec166fd..f2adb97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,7 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 - [[package]] name = "KIT-ILIAS-downloader" version = "0.2.20" @@ -310,9 +308,9 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "cpufeatures" -version = "0.1.1" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec1028182c380cc45a2e2c5ec841134f2dfd0f8f5f0a5bcd68004f81b5efdf4" +checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8" dependencies = [ "libc", ] @@ -385,9 +383,9 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.13" +version = "0.99.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b1b72f1263f214c0f823371768776c4f5841b942c9883aa8e5ec584fd0ba6" +checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320" dependencies = [ "convert_case", "proc-macro2", @@ -1786,9 +1784,9 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" dependencies = [ "libc", "winapi", @@ -1893,9 +1891,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" +checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37" dependencies = [ "autocfg", "bytes", @@ -1909,9 +1907,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" +checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" dependencies = [ "proc-macro2", "quote", @@ -1943,9 +1941,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" +checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" dependencies = [ "bytes", "futures-core", From ac02493dbde72b23cfcbb630aa1dd248c3aa24da Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 18 May 2021 08:47:52 +0200 Subject: [PATCH 054/103] Only show HTTP/2 warning in verbose mode --- src/cli.rs | 3 +++ src/ilias.rs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 12fc826..76ada77 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -118,6 +118,9 @@ macro_rules! warning { (format => $($e:expr),+) => { log!(0, "Warning: {}", format!($($e),+).bright_yellow()); }; + ($lvl:expr; $($e:expr),+) => { + log!($lvl, "Warning: {}", format!($($e),+).bright_yellow()); + } } macro_rules! error { diff --git a/src/ilias.rs b/src/ilias.rs index 5f08f8b..42c3d2b 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -110,7 +110,7 @@ impl ILIAS { match result { Ok(x) => return Ok(x), Err(e) if attempt <= 3 && error_is_http2(&e) => { - warning!("encountered HTTP/2 NO_ERROR, retrying download.."); + warning!(1; "encountered HTTP/2 NO_ERROR, retrying download.."); continue }, Err(e) => return Err(e.into()) @@ -127,7 +127,7 @@ impl ILIAS { match result { Ok(x) => return Ok(x), Err(e) if attempt <= 3 && error_is_http2(&e) => { - warning!("encountered HTTP/2 NO_ERROR, retrying HEAD request.."); + warning!(1; "encountered HTTP/2 NO_ERROR, retrying HEAD request.."); continue }, Err(e) => return Err(e) From ca939393c9cfc2f27a26c2b39d5da7dd241b817a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 18 May 2021 08:50:24 +0200 Subject: [PATCH 055/103] Version 0.2.21 --- CHANGELOG.md | 5 ++++- Cargo.lock | 4 +++- Cargo.toml | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 049ded0..00b6f69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project loosely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [0.2.21] - 2021-05-18 ### Fixed - Automatic output directory creation - HTTP/2 [`NO_ERROR`](https://docs.rs/h2/0.3.3/h2/struct.Reason.html#associatedconstant.NO_ERROR) handling (issue [#15]) @@ -128,7 +130,8 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe [@Craeckie]: https://github.com/Craeckie [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 -[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.20...HEAD +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.21...HEAD +[0.2.21]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.20...v0.2.21 [0.2.20]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.19...v0.2.20 [0.2.19]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.18...v0.2.19 [0.2.18]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.17...v0.2.18 diff --git a/Cargo.lock b/Cargo.lock index f2adb97..78c5cb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,8 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.20" +version = "0.2.21" dependencies = [ "anyhow", "atty", diff --git a/Cargo.toml b/Cargo.toml index 0b5cf00..903e3cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.20" +version = "0.2.21" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-2.0-or-later" edition = "2018" From a52869908bd26b5fadd581d54bc71f9478f2dfc4 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 19 May 2021 11:08:01 +0200 Subject: [PATCH 056/103] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4280459..725fdae 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ $ cargo install --all-features --git 'https://github.com/FliegendeWurst/KIT-ILIA First, open a terminal. Navigate to the directory that contains the downloaded binary. -Use `-o ` to specify the download directory: +Then execute the program (use `-o ` to specify the download directory): ``` $ KIT-ILIAS-downloader -o ./ILIAS @@ -36,7 +36,7 @@ $ KIT-ILIAS-downloader -o ./ILIAS/WS2021-HM1 --sync-url 'https://ilias.studium.k ``` $ KIT-ILIAS-downloader --help -KIT-ILIAS-downloader 0.2.20 +KIT-ILIAS-downloader 0.2.21 USAGE: KIT-ILIAS-downloader [FLAGS] [OPTIONS] --output @@ -65,7 +65,7 @@ OPTIONS: ### .iliasignore -.gitignore syntax can be used in a `.iliasignore` file: (located in the download folder) +.gitignore syntax can be used in a `.iliasignore` file: (located in the output folder) ```ignore # example 1: only download a single course /*/ From 9da1a9d2d7b8a41fb0e606184260a2a06e5e18a1 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 27 May 2021 16:45:18 +0200 Subject: [PATCH 057/103] Update dependencies and license Since rpassword and rprompt are licensed under the Apache 2.0 the combined product has to be GPLv3+, not GPLv2. --- Cargo.lock | 38 ++- Cargo.toml | 2 +- LICENSE | 833 ++++++++++++++++++++++++++++++++++++--------------- src/cli.rs | 2 +- src/ilias.rs | 2 +- src/main.rs | 2 +- src/util.rs | 2 +- 7 files changed, 607 insertions(+), 274 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78c5cb3..3de0393 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -193,9 +193,9 @@ checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cc" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" [[package]] name = "cfg-if" @@ -247,17 +247,15 @@ dependencies = [ "encode_unicode", "lazy_static", "libc", - "regex", "terminal_size", - "unicode-width", "winapi", ] [[package]] name = "const_fn" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402da840495de3f976eaefc3485b7f5eb5b0bf9761f9a47be27fe975b3b8c2ec" +checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" [[package]] name = "convert_case" @@ -743,15 +741,15 @@ checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" [[package]] name = "httpdate" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05842d0d43232b23ccb7060ecb0f0626922c21f30012e97b767b30afd4a5d4b9" +checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" [[package]] name = "hyper" -version = "0.14.7" +version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e5f105c494081baa3bf9e200b279e27ec1623895cd504c7dbef8d0b080fcf54" +checksum = "d3f71a7eea53a3f8257a7b4795373ff886397178cd634430ea94e12d7fe4fe34" dependencies = [ "bytes", "futures-channel", @@ -827,9 +825,9 @@ dependencies = [ [[package]] name = "indicatif" -version = "0.16.0" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "507cf157a0dab3c837bef6e2086466255d9de4a6b1af69e62b62c54cd52f6062" +checksum = "2d207dc617c7a380ab07ff572a6e52fa202a2a8f355860ac9c38e23f8196be1b" dependencies = [ "console", "lazy_static", @@ -877,9 +875,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.94" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" +checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" [[package]] name = "log" @@ -1227,9 +1225,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] @@ -1811,18 +1809,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" +checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" +checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 903e3cd..6e6b02c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "KIT-ILIAS-downloader" version = "0.2.21" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] -license = "GPL-2.0-or-later" +license = "GPL-3.0-or-later" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/LICENSE b/LICENSE index d159169..f288702 100644 --- a/LICENSE +++ b/LICENSE @@ -1,281 +1,622 @@ GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 + Version 3, 29 June 2007 - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + TERMS AND CONDITIONS - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". + 0. Definitions. -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. + "This License" refers to version 3 of the GNU General Public License. - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. + A "covered work" means either the unmodified Program or a work based +on the Program. - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. + 1. Source Code. -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. + The Corresponding Source for a work in source code form is that +same work. -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. + 2. Basic Permissions. - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of this License. - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. + 13. Use with the GNU Affero General Public License. -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. + 14. Revised Versions of this License. - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. - NO WARRANTY + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. + 15. Disclaimer of Warranty. - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. END OF TERMS AND CONDITIONS @@ -287,15 +628,15 @@ free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least +state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) - This program is free software; you can redistribute it and/or modify + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -303,37 +644,31 @@ the "copyright" line and a pointer to where the full notice is found. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + You should have received a copy of the GNU General Public License + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/src/cli.rs b/src/cli.rs index 76ada77..63e27fe 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-License-Identifier: GPL-3.0-or-later use std::{path::PathBuf, sync::atomic::{AtomicBool, AtomicUsize}}; diff --git a/src/ilias.rs b/src/ilias.rs index 42c3d2b..fe6bbd9 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-License-Identifier: GPL-3.0-or-later use std::error::Error as _; diff --git a/src/main.rs b/src/main.rs index 227b9b3..097e96b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-License-Identifier: GPL-3.0-or-later #![allow(clippy::comparison_to_empty, clippy::upper_case_acronyms)] diff --git a/src/util.rs b/src/util.rs index 7404f13..a38c267 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-License-Identifier: GPL-3.0-or-later use anyhow::Context; use tokio::fs::File as AsyncFile; From a003d274427f8c951bce31fbe15254be6ab989ee Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 28 May 2021 15:32:24 +0200 Subject: [PATCH 058/103] Support download of other personal desktop pages --- CHANGELOG.md | 2 ++ src/ilias.rs | 36 +++++++++++++++--------------------- src/main.rs | 33 ++++++++++++++++----------------- 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00b6f69..ac05da6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project loosely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `--sync-url https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToMemberships` to download all courses (unless specified otherwise in the `.iliasignore`) ## [0.2.21] - 2021-05-18 ### Fixed diff --git a/src/ilias.rs b/src/ilias.rs index fe6bbd9..eaecf55 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -167,12 +167,15 @@ impl ILIAS { .collect() } - /// Returns subfolders and the main text on the course page. + /// Returns subfolders and the main text in a course/folder/personal desktop. pub async fn get_course_content(&self, url: &URL) -> Result<(Vec>, Option)> { let html = self.get_html(&url.url).await?; + let main_text = if let Some(el) = html.select(&il_content_container).next() { - if !el.children().flat_map(|x| x.value().as_element()).next().map(|x| - x.attr("class").unwrap_or_default().contains("ilContainerBlock")).unwrap_or(false) + + if !el.children().flat_map(|x| x.value().as_element()).next() + .map(|x| x.attr("class").unwrap_or_default() + .contains("ilContainerBlock")).unwrap_or(false) && el.inner_html().len() > 40 { // ^ minimum length of useful content? Some(el.inner_html()) @@ -186,15 +189,6 @@ impl ILIAS { Ok((ILIAS::get_items(&html), main_text)) } - pub async fn personal_desktop(&self) -> Result { - let html = self.get_html("https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems").await?; - let items = ILIAS::get_items(&html) - .into_iter() - .flat_map(Result::ok) - .collect(); - Ok(Dashboard { items }) - } - pub async fn get_course_content_tree(&self, ref_id: &str, cmd_node: &str) -> Result> { // TODO: this magically does not return sub-folders // opening the same url in browser does show sub-folders?! @@ -213,15 +207,11 @@ impl ILIAS { } } -#[derive(Debug)] -pub struct Dashboard { - pub items: Vec, -} - #[derive(Debug)] pub enum Object { Course { name: String, url: URL }, Folder { name: String, url: URL }, + PersonalDesktop { url: URL }, File { name: String, url: URL }, Forum { name: String, url: URL }, Thread { url: URL }, @@ -253,6 +243,7 @@ impl Object { | Generic { name, .. } => &name, Thread { url } => &url.thr_pk.as_ref().unwrap(), Video { url } => &url.url, + PersonalDesktop { url } => url.cmd.as_ref().unwrap() } } @@ -260,6 +251,7 @@ impl Object { match self { Course { url, .. } | Folder { url, .. } + | PersonalDesktop { url } | File { url, .. } | Forum { url, .. } | Thread { url } @@ -278,6 +270,7 @@ impl Object { match self { Course { .. } => "course", Folder { .. } => "folder", + PersonalDesktop { .. } => "personal desktop", File { .. } => "file", Forum { .. } => "forum", Thread { .. } => "thread", @@ -293,16 +286,16 @@ impl Object { } pub fn is_dir(&self) -> bool { - match self { + matches!(self, Course { .. } | Folder { .. } + | PersonalDesktop { .. } | Forum { .. } | Thread { .. } | Wiki { .. } | ExerciseHandler { .. } - | PluginDispatch { .. } => true, - _ => false, - } + | PluginDispatch { .. } + ) } pub fn from_link(item: ElementRef, link: ElementRef) -> Result { @@ -399,6 +392,7 @@ impl Object { None => Course { name, url }, }, "ilobjplugindispatchgui" => PluginDispatch { name, url }, + "ilpersonaldesktopgui" => PersonalDesktop { url }, _ => Generic { name, url }, }) } diff --git a/src/main.rs b/src/main.rs index 097e96b..143eec6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -120,23 +120,19 @@ async fn real_main(mut opt: Opt) -> Result<()> { if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { PROGRESS_BAR.set_draw_target(ProgressDrawTarget::stderr_nohz()); PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}+] {wide_msg}")); - PROGRESS_BAR.inc_length(1); PROGRESS_BAR.set_message("initializing.."); } - if let Some(url) = ilias.opt.sync_url.as_ref() { - // TODO: this should be unified with the download logic below - let obj = Object::from_url(URL::from_href(url).context("invalid sync URL")?, "Sync URL".to_owned(), None).context("invalid sync object")?; // name can be empty for first element - spawn!(process_gracefully(ilias.clone(), ilias.opt.output.clone(), obj)); - } else { - let desktop = ilias.personal_desktop().await.context("Failed to load personal desktop")?; - for item in desktop.items { - let path = ilias.opt.output.join(file_escape(item.name())); - tx.unbounded_send(task::spawn(process_gracefully(ilias.clone(), path, item))).unwrap(); - } - } + + // default sync URL: main personal desktop + let sync_url = ilias.opt.sync_url.clone().unwrap_or_else(|| format!("{}ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems", ILIAS_URL)); + let obj = Object::from_url(URL::from_href(&sync_url).context("invalid sync URL")?, String::new(), None).context("invalid sync object")?; // name can be empty for first element + spawn!(process_gracefully(ilias.clone(), ilias.opt.output.clone(), obj)); + while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await { if let Some(task) = task { - let _ = task.await; + if let Err(e) = task.await { + error!(e) + } } else { break; } @@ -149,7 +145,6 @@ async fn real_main(mut opt: Opt) -> Result<()> { } } if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { - PROGRESS_BAR.inc(1); PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}] {wide_msg}")); PROGRESS_BAR.finish_with_message("done"); } @@ -220,9 +215,13 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let relative_path = path.strip_prefix(&ilias.opt.output).unwrap(); if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { PROGRESS_BAR.inc(1); - PROGRESS_BAR.set_message(relative_path.display().to_string()); + let path = relative_path.display().to_string(); + if !path.is_empty() { + PROGRESS_BAR.set_message(path); + } } - if ilias.ignore.matched(relative_path, obj.is_dir()).is_ignore() { + // root path should not be matched + if relative_path.parent().is_some() && ilias.ignore.matched(relative_path, obj.is_dir()).is_ignore() { log!(1, "Ignored {}", relative_path.to_string_lossy()); return Ok(()); } @@ -263,7 +262,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { spawn!(process_gracefully(ilias, path, item)); } }, - Folder { url, .. } => { + Folder { url, .. } | PersonalDesktop { url } => { let content = ilias.get_course_content(&url).await?; if let Some(s) = content.1.as_ref() { let path = path.join("folder.html"); From 56764767659dc5552ba3f0e741c1024cf9cb9e76 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 28 May 2021 15:33:31 +0200 Subject: [PATCH 059/103] CI: remove useless stage --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6034d4f..c80f07d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,9 +46,6 @@ jobs: if: runner.os == 'Linux' - name: Build run: cargo build --release ${{ matrix.features }} --verbose - # there are currently no automated tests - - name: Run tests - run: cargo test --release ${{ matrix.features }} --verbose - name: Archive artifacts uses: actions/upload-artifact@v2 if: matrix.features == '--all-features' From 5fb2faabfd8475e008a6ea3fc0229e20d6f09b5b Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 28 May 2021 16:02:05 +0200 Subject: [PATCH 060/103] Consistent code formatting --- rustfmt.toml | 3 + src/cli.rs | 9 ++- src/ilias.rs | 106 ++++++++++++++-------------- src/main.rs | 193 +++++++++++++++++++-------------------------------- src/util.rs | 6 +- 5 files changed, 140 insertions(+), 177 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..9345fb0 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +hard_tabs = true +match_block_trailing_comma = true +max_width = 145 diff --git a/src/cli.rs b/src/cli.rs index 63e27fe..ef827c3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later -use std::{path::PathBuf, sync::atomic::{AtomicBool, AtomicUsize}}; +use std::path::PathBuf; +use std::sync::atomic::{AtomicBool, AtomicUsize}; #[cfg(feature = "keyring-auth")] use anyhow::anyhow; @@ -73,7 +74,11 @@ pub struct Opt { /// Requests per minute #[structopt(long, default_value = "8")] - pub rate: usize + pub rate: usize, + + /// Attempt to re-use session cookies + #[structopt(long)] + pub keep_session: bool, } pub static LOG_LEVEL: AtomicUsize = AtomicUsize::new(0); diff --git a/src/ilias.rs b/src/ilias.rs index eaecf55..0de3893 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -9,7 +9,7 @@ use reqwest::{Client, IntoUrl, Proxy, Url}; use scraper::{ElementRef, Html, Selector}; use serde_json::json; -use crate::{ILIAS_URL, cli::Opt, get_request_ticket, selectors::*}; +use crate::{cli::Opt, get_request_ticket, selectors::*, ILIAS_URL}; pub struct ILIAS { pub opt: Opt, @@ -23,8 +23,9 @@ pub struct ILIAS { /// Returns true if the error is caused by: /// "http2 error: protocol error: not a result of an error" fn error_is_http2(error: &reqwest::Error) -> bool { - error.source() // hyper::Error - .map(|x| x.source()) // -> h2::Error + error + .source() // hyper::Error + .map(|x| x.source()) // h2::Error .flatten() .map(|x| x.downcast_ref::()) .flatten() @@ -48,9 +49,16 @@ impl ILIAS { let client = builder // timeout is infinite by default .build()?; - let this = ILIAS { opt, ignore, user, pass, client }; + let this = ILIAS { + opt, + ignore, + user, + pass, + client, + }; info!("Logging into ILIAS using KIT account.."); - let session_establishment = this.client + let session_establishment = this + .client .post("https://ilias.studium.kit.edu/Shibboleth.sso/Login") .form(&json!({ "sendLogin": "1", @@ -58,29 +66,33 @@ impl ILIAS { "target": "/shib_login.php?target=", "home_organization_selection": "Mit KIT-Account anmelden" })) - .send().await?; + .send() + .await?; let url = session_establishment.url().clone(); let text = session_establishment.text().await?; let dom_sso = Html::parse_document(text.as_str()); let csrf_token = dom_sso .select(&Selector::parse(r#"input[name="csrf_token"]"#).unwrap()) - .next().context("no csrf token")?; + .next() + .context("no CSRF token found")? + .value().attr("value").context("no CSRF token value")?; info!("Logging into Shibboleth.."); - let login_response = this.client + let login_response = this + .client .post(url) .form(&json!({ "j_username": &this.user, "j_password": &this.pass, "_eventId_proceed": "", - "csrf_token": csrf_token.value().attr("value").context("no csrf token")?, + "csrf_token": csrf_token, })) - .send().await? - .text().await?; + .send() + .await? + .text() + .await?; let dom = Html::parse_document(&login_response); let saml = Selector::parse(r#"input[name="SAMLResponse"]"#).unwrap(); - let saml = dom - .select(&saml) - .next().context("no SAML response, incorrect password?")?; + let saml = dom.select(&saml).next().context("no SAML response, incorrect password?")?; let relay_state = Selector::parse(r#"input[name="RelayState"]"#).unwrap(); let relay_state = dom.select(&relay_state).next().context("no relay state")?; info!("Logging into ILIAS.."); @@ -90,7 +102,8 @@ impl ILIAS { "SAMLResponse": saml.value().attr("value").context("no SAML value")?, "RelayState": relay_state.value().attr("value").context("no RelayState value")? })) - .send().await?; + .send() + .await?; success!("Logged in!"); Ok(this) } @@ -111,9 +124,9 @@ impl ILIAS { Ok(x) => return Ok(x), Err(e) if attempt <= 3 && error_is_http2(&e) => { warning!(1; "encountered HTTP/2 NO_ERROR, retrying download.."); - continue + continue; }, - Err(e) => return Err(e.into()) + Err(e) => return Err(e.into()), } } unreachable!() @@ -128,9 +141,9 @@ impl ILIAS { Ok(x) => return Ok(x), Err(e) if attempt <= 3 && error_is_http2(&e) => { warning!(1; "encountered HTTP/2 NO_ERROR, retrying HEAD request.."); - continue + continue; }, - Err(e) => return Err(e) + Err(e) => return Err(e), } } unreachable!() @@ -159,10 +172,8 @@ impl ILIAS { pub fn get_items(html: &Html) -> Vec> { html.select(&container_items) .flat_map(|item| { - item.select(&container_item_title) - .next() - .map(|link| Object::from_link(item, link)) - // items without links are ignored + item.select(&container_item_title).next().map(|link| Object::from_link(item, link)) + // items without links are ignored }) .collect() } @@ -172,11 +183,14 @@ impl ILIAS { let html = self.get_html(&url.url).await?; let main_text = if let Some(el) = html.select(&il_content_container).next() { - - if !el.children().flat_map(|x| x.value().as_element()).next() - .map(|x| x.attr("class").unwrap_or_default() - .contains("ilContainerBlock")).unwrap_or(false) - && el.inner_html().len() > 40 { + if !el + .children() + .flat_map(|x| x.value().as_element()) + .next() + .map(|x| x.attr("class").unwrap_or_default().contains("ilContainerBlock")) + .unwrap_or(false) + && el.inner_html().len() > 40 + { // ^ minimum length of useful content? Some(el.inner_html()) } else { @@ -198,7 +212,7 @@ impl ILIAS { ); let html = self.get_html_fragment(&url).await?; let mut items = Vec::new(); - for link in html.select(&a) { + for link in html.select(&LINKS) { if link.value().attr("href").is_some() { items.push(Object::from_link(link, link)?); } // else: disabled course @@ -243,7 +257,7 @@ impl Object { | Generic { name, .. } => &name, Thread { url } => &url.thr_pk.as_ref().unwrap(), Video { url } => &url.url, - PersonalDesktop { url } => url.cmd.as_ref().unwrap() + PersonalDesktop { .. } => panic!("name of personal desktop requested (this should never happen)"), } } @@ -286,25 +300,18 @@ impl Object { } pub fn is_dir(&self) -> bool { - matches!(self, + matches!( + self, Course { .. } - | Folder { .. } - | PersonalDesktop { .. } - | Forum { .. } - | Thread { .. } - | Wiki { .. } - | ExerciseHandler { .. } - | PluginDispatch { .. } + | Folder { .. } | PersonalDesktop { .. } + | Forum { .. } | Thread { .. } + | Wiki { .. } | ExerciseHandler { .. } + | PluginDispatch { .. } ) } pub fn from_link(item: ElementRef, link: ElementRef) -> Result { - let name = link - .text() - .collect::() - .replace('/', "-") - .trim() - .to_owned(); + let name = link.text().collect::().replace('/', "-").trim().to_owned(); let url = URL::from_href(link.value().attr("href").context("link missing href")?)?; Object::from_url(url, name, Some(item)) } @@ -314,10 +321,7 @@ impl Object { return Ok(Thread { url }); } - if url - .url - .starts_with("https://ilias.studium.kit.edu/goto.php") - { + if url.url.starts_with("https://ilias.studium.kit.edu/goto.php") { let target = url.target.as_deref().unwrap_or("NONE"); if target.starts_with("wiki_") { return Ok(Wiki { @@ -356,11 +360,7 @@ impl Object { } else { let mut item_props = item.context("can't construct file object without HTML object")?.select(&item_prop); let ext = item_props.next().context("cannot find file extension")?; - let version = item_props - .nth(1) - .context("cannot find 3rd file metadata")? - .text() - .collect::(); + let version = item_props.nth(1).context("cannot find 3rd file metadata")?.text().collect::(); let version = version.trim(); if let Some(v) = version.strip_prefix("Version: ") { name += "_v"; diff --git a/src/main.rs b/src/main.rs index 143eec6..58d3773 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later -#![allow(clippy::comparison_to_empty, clippy::upper_case_acronyms)] +#![allow(clippy::upper_case_acronyms)] use anyhow::{anyhow, Context, Result}; use colored::Colorize; @@ -13,17 +13,17 @@ use indicatif::{ProgressDrawTarget, ProgressStyle}; use once_cell::sync::{Lazy, OnceCell}; use scraper::Html; use structopt::StructOpt; -use tokio::{fs, sync::Semaphore, time}; use tokio::task::{self, JoinHandle}; +use tokio::{fs, sync::Semaphore, time}; use tokio_util::io::StreamReader; use url::Url; +use std::collections::HashSet; use std::future::Future; use std::io; use std::path::PathBuf; use std::sync::atomic::Ordering; use std::sync::Arc; -use std::collections::HashSet; pub const ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; @@ -72,8 +72,8 @@ async fn real_main(mut opt: Opt) -> Result<()> { #[cfg(windows)] let _ = colored::control::set_virtual_terminal(true); - // use UNC paths on Windows create_dir(&opt.output).await.context("failed to create output directory")?; + // use UNC paths on Windows (#6) opt.output = fs::canonicalize(opt.output).await.context("failed to canonicalize output directory")?; // load .iliasignore file @@ -107,8 +107,10 @@ async fn real_main(mut opt: Opt) -> Result<()> { }, }; if ilias.opt.content_tree { - // need this to get the content tree - if let Err(e) = ilias.download("ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=tree&ref_id=1").await { + if let Err(e) = ilias + .download("ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=tree&ref_id=1") + .await + { warning!("could not enable content tree:", e); } } @@ -123,8 +125,10 @@ async fn real_main(mut opt: Opt) -> Result<()> { PROGRESS_BAR.set_message("initializing.."); } - // default sync URL: main personal desktop - let sync_url = ilias.opt.sync_url.clone().unwrap_or_else(|| format!("{}ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems", ILIAS_URL)); + let sync_url = ilias.opt.sync_url.clone().unwrap_or_else(|| { + // default sync URL: main personal desktop + format!("{}ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems", ILIAS_URL) + }); let obj = Object::from_url(URL::from_href(&sync_url).context("invalid sync URL")?, String::new(), None).context("invalid sync object")?; // name can be empty for first element spawn!(process_gracefully(ilias.clone(), ilias.opt.output.clone(), obj)); @@ -134,13 +138,14 @@ async fn real_main(mut opt: Opt) -> Result<()> { error!(e) } } else { - break; + break; // channel is empty => all tasks are completed } } - // channel is empty => all tasks are completed if ilias.opt.content_tree { - // restore fast page loading times - if let Err(e) = ilias.download("ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=flat&ref_id=1").await { + if let Err(e) = ilias + .download("ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=flat&ref_id=1") + .await + { warning!("could not disable content tree:", e); } } @@ -153,21 +158,19 @@ async fn real_main(mut opt: Opt) -> Result<()> { // https://github.com/rust-lang/rust/issues/53690#issuecomment-418911229 #[allow(clippy::manual_async_fn)] -fn process_gracefully( - ilias: Arc, - path: PathBuf, - obj: Object, -) -> impl Future + Send { async move { - if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { - PROGRESS_BAR.inc_length(1); +fn process_gracefully(ilias: Arc, path: PathBuf, obj: Object) -> impl Future + Send { + async move { + if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { + PROGRESS_BAR.inc_length(1); + } + let permit = TASKS_RUNNING.acquire().await.unwrap(); + let path_text = path.to_string_lossy().into_owned(); + if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { + error!("Syncing {}", path_text; e); + } + drop(permit); } - let permit = TASKS_RUNNING.acquire().await.unwrap(); - let path_text = path.to_string_lossy().into_owned(); - if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { - error!("Syncing {}", path_text; e); - } - drop(permit); -}} +} async fn handle_gracefully(fut: impl Future>) { if let Err(e) = fut.await { @@ -181,11 +184,11 @@ mod selectors { use regex::Regex; use scraper::Selector; // construct CSS selectors once - pub static a: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); + pub static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); pub static a_target_blank: Lazy = Lazy::new(|| Selector::parse(r#"a[target="_blank"]"#).unwrap()); - pub static img: Lazy = Lazy::new(|| Selector::parse("img").unwrap()); - pub static table: Lazy = Lazy::new(|| Selector::parse("table").unwrap()); - pub static video_tr: Lazy = Lazy::new(|| Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap()); + pub static IMAGES: Lazy = Lazy::new(|| Selector::parse("img").unwrap()); + pub static TABLES: Lazy = Lazy::new(|| Selector::parse("table").unwrap()); + pub static VIDEO_ROWS: Lazy = Lazy::new(|| Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap()); pub static links_in_table: Lazy = Lazy::new(|| Selector::parse("tbody tr td a").unwrap()); pub static th: Lazy = Lazy::new(|| Selector::parse("th").unwrap()); pub static td: Lazy = Lazy::new(|| Selector::parse("td").unwrap()); @@ -253,7 +256,9 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { }; if let Some(s) = content.1.as_ref() { let path = path.join("course.html"); - write_file_data(&path, &mut s.as_bytes()).await.context("failed to write course page html")?; + write_file_data(&path, &mut s.as_bytes()) + .await + .context("failed to write course page html")?; } for item in content.0 { let item = item?; @@ -266,7 +271,9 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let content = ilias.get_course_content(&url).await?; if let Some(s) = content.1.as_ref() { let path = path.join("folder.html"); - write_file_data(&path, &mut s.as_bytes()).await.context("failed to write folder page html")?; + write_file_data(&path, &mut s.as_bytes()) + .await + .context("failed to write folder page html")?; } for item in content.0 { let item = item?; @@ -284,9 +291,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { return Ok(()); } let data = ilias.download(&url.url).await?; - let mut reader = StreamReader::new(data.bytes_stream().map_err(|x| { - io::Error::new(io::ErrorKind::Other, x) - })); + let mut reader = StreamReader::new(data.bytes_stream().map_err(|x| io::Error::new(io::ErrorKind::Other, x))); log!(0, "Writing {}", relative_path.to_string_lossy()); write_file_data(&path, &mut reader).await?; }, @@ -301,10 +306,12 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let data = ilias.download(&list_url).await?; let html = data.text().await?; let html = Html::parse_fragment(&html); - html.select(&a) + html.select(&LINKS) .filter_map(|link| link.value().attr("href")) .filter(|href| href.contains("trows=800")) - .map(|x| x.to_string()).next().context("video list link not found")? + .map(|x| x.to_string()) + .next() + .context("video list link not found")? }; log!(1, "Rewriting {}", full_url); let mut full_url = Url::parse(&format!("{}{}", ILIAS_URL, full_url))?; @@ -322,7 +329,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let data = ilias.download(full_url.as_str()).await?; let html = data.text().await?; let html = Html::parse_fragment(&html); - for row in html.select(&video_tr) { + for row in html.select(&VIDEO_ROWS) { let link = row.select(&a_target_blank).next(); if link.is_none() { if !row.text().any(|x| x == NO_ENTRIES) { @@ -342,17 +349,10 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { path.push(format!("{}.mp4", file_escape(title))); log!(1, "Found video: {}", title); let video = Video { - url: URL::raw( - link.value() - .attr("href") - .context("video link without href")? - .to_owned(), - ), + url: URL::raw(link.value().attr("href").context("video link without href")?.to_owned()), }; let ilias = Arc::clone(&ilias); - spawn!(async { - process_gracefully(ilias, path, video).await; - }); + spawn!(process_gracefully(ilias, path, video)); } } }, @@ -372,10 +372,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let mut json_capture = XOCT_REGEX.captures_iter(&html); let json = &json_capture.next().context("xoct player json not found")?[1]; log!(2, "{}", json); - let json = json - .split(",\n") - .next() - .context("invalid xoct player json")?; + let json = json.split(",\n").next().context("invalid xoct player json")?; serde_json::from_str(&json.trim())? }; log!(2, "{}", json); @@ -386,10 +383,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { .context("video src not string")?; let meta = fs::metadata(&path).await; if !ilias.opt.force && meta.is_ok() && ilias.opt.check_videos { - let head = ilias - .head(url) - .await - .context("HEAD request failed")?; + let head = ilias.head(url).await.context("HEAD request failed")?; if let Some(len) = head.headers().get("content-length") { if meta?.len() != len.to_str()?.parse::()? { warning!(relative_path.to_string_lossy(), "was updated, consider moving the outdated file"); @@ -397,10 +391,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { } } else { let resp = ilias.download(&url).await?; - let mut reader = StreamReader::new( - resp.bytes_stream() - .map_err(|x| io::Error::new(io::ErrorKind::Other, x)), - ); + let mut reader = StreamReader::new(resp.bytes_stream().map_err(|x| io::Error::new(io::ErrorKind::Other, x))); log!(0, "Writing {}", relative_path.to_string_lossy()); write_file_data(&path, &mut reader).await?; } @@ -415,9 +406,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let html_text = data.await?.text().await?; let url = { let html = Html::parse_document(&html_text); - let thread_count_selector = html.select(&a) - .flat_map(|x| x.value().attr("href")) - .find(|x| x.contains("trows=800")); + let thread_count_selector = html.select(&LINKS).flat_map(|x| x.value().attr("href")).find(|x| x.contains("trows=800")); if thread_count_selector.is_none() { if let Some(cell) = html.select(&td).next() { if cell.text().any(|x| x == NO_ENTRIES) { @@ -448,19 +437,12 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { ); continue; } - let link = cells[1] - .select(&a) - .next() - .context("thread link not found")?; + let link = cells[1].select(&LINKS).next().context("thread link not found")?; let object = Object::from_link(link, link)?; let mut path = path.clone(); let name = format!( "{}_{}", - object - .url() - .thr_pk - .as_ref() - .context("thr_pk not found for thread")?, + object.url().thr_pk.as_ref().context("thr_pk not found for thread")?, link.text().collect::().trim() ); path.push(file_escape(&name)); @@ -504,15 +486,9 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { .context("post title not found")? .text() .collect::(); - let author = post - .select(&span_small) - .next() - .context("post author not found")?; + let author = post.select(&span_small).next().context("post author not found")?; let author = author.text().collect::(); - let author = author - .trim() - .split('|') - .collect::>(); + let author = author.trim().split('|').collect::>(); let author = if author.len() == 2 { author[0] // pseudonymous forum } else if author.len() == 3 { @@ -523,36 +499,26 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { } } else { return Err(anyhow!("author data in unknown format")); - }.trim(); - let container = post - .select(&post_container) - .next() - .context("post container not found")?; - let link = container.select(&a).next().context("post link not found")?; - let id = link - .value() - .attr("id") - .context("no id in thread link")? - .to_owned(); + } + .trim(); + let container = post.select(&post_container).next().context("post container not found")?; + let link = container.select(&LINKS).next().context("post link not found")?; + let id = link.value().attr("id").context("no id in thread link")?.to_owned(); let name = format!("{}_{}_{}.html", id, author, title.trim()); let data = container.inner_html(); let path = path.join(file_escape(&name)); let relative_path = relative_path.join(file_escape(&name)); spawn!(handle_gracefully(async move { log!(0, "Writing {}", relative_path.display()); - write_file_data(&path, &mut data.as_bytes()) - .await - .context("failed to write forum post") + write_file_data(&path, &mut data.as_bytes()).await.context("failed to write forum post") })); - let images = container - .select(&img) - .map(|x| x.value().attr("src").map(|x| x.to_owned())); + let images = container.select(&IMAGES).map(|x| x.value().attr("src").map(|x| x.to_owned())); for image in images { let image = image.context("no src on image")?; all_images.push((id.clone(), image)); } if let Some(container) = container.select(&post_attachments).next() { - for attachment in container.select(&a) { + for attachment in container.select(&LINKS) { attachments.push(( id.clone(), attachment.text().collect::(), @@ -562,16 +528,14 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { } } // pagination - if let Some(pages) = html.select(&table).next() { + if let Some(pages) = html.select(&TABLES).next() { if let Some(last) = pages.select(&links_in_table).last() { let text = last.text().collect::(); if text.trim() == ">>" { // not last page yet let ilias = Arc::clone(&ilias); let next_page = Thread { - url: URL::from_href( - last.value().attr("href").context("page link not found")?, - )?, + url: URL::from_href(last.value().attr("href").context("page link not found")?)?, }; spawn!(process_gracefully(ilias, path.clone(), next_page)); } @@ -622,7 +586,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let html = ilias.get_html(&url.url).await?; let mut filenames = HashSet::new(); for row in html.select(&form_group) { - let link = row.select(&a).next(); + let link = row.select(&LINKS).next(); if link.is_none() { continue; } @@ -634,10 +598,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let href = href.unwrap(); let url = URL::from_href(href)?; let cmd = url.cmd.as_deref().unwrap_or(""); - if cmd != "downloadFile" - && cmd != "downloadGlobalFeedbackFile" - && cmd != "downloadFeedbackFile" - { + if cmd != "downloadFile" && cmd != "downloadGlobalFeedbackFile" && cmd != "downloadFeedbackFile" { continue; } // link is definitely just a download link to the exercise or the solution @@ -660,10 +621,10 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let mut i = 1; while filenames.contains(&unique_filename) { i += 1; - if name != "" { - unique_filename = format!("{}{}.{}", name, i, extension); - } else { + if name.is_empty() { unique_filename = format!("{}{}", extension, i); + } else { + unique_filename = format!("{}{}.{}", name, i, extension); } } filenames.insert(unique_filename.clone()); @@ -691,17 +652,9 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let urls = { let html = ilias.get_html(url).await?; - html.select(&a) - .filter_map(|x| { - x.value() - .attr("href") - .map(|y| (y, x.text().collect::())) - }) - .map(|(x, y)| { - URL::from_href(x) - .map(|z| (z, y.trim().to_owned())) - .context("parsing weblink") - }) + html.select(&LINKS) + .filter_map(|x| x.value().attr("href").map(|y| (y, x.text().collect::()))) + .map(|(x, y)| URL::from_href(x).map(|z| (z, y.trim().to_owned())).context("parsing weblink")) .collect::>>() }?; diff --git a/src/util.rs b/src/util.rs index a38c267..17f4082 100644 --- a/src/util.rs +++ b/src/util.rs @@ -9,8 +9,10 @@ use std::path::Path; use crate::Result; /// Write all data to the specified path. Will overwrite previous file data. -pub async fn write_file_data(path: impl AsRef, data: &mut R) -> Result<()> -where R: AsyncRead + Unpin { +pub async fn write_file_data(path: impl AsRef, data: &mut R) -> Result<()> +where + R: AsyncRead + Unpin, +{ let file = AsyncFile::create(path.as_ref()).await.context("failed to create file")?; let mut file = BufWriter::new(file); tokio::io::copy(data, &mut file).await.context("failed to write to file")?; From 8ea2cae769c208fc05e51172b323f3d264a164e9 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sun, 30 May 2021 13:38:52 +0200 Subject: [PATCH 061/103] Session re-use --- CHANGELOG.md | 3 +- Cargo.lock | 88 +++++++++++++++++++++++++++++++++++++++++++++------- Cargo.toml | 2 ++ src/cli.rs | 6 ++-- src/ilias.rs | 64 +++++++++++++++++++++++++++++--------- src/main.rs | 79 ++++++++++++++++++++++++++++++++++------------ 6 files changed, 193 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac05da6..5852800 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe ## [Unreleased] ### Added -- `--sync-url https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToMemberships` to download all courses (unless specified otherwise in the `.iliasignore`) +- `--sync-url` can now download all courses (unless specified otherwise in the `.iliasignore`) +- `--keep-session` flag to save and restore session cookies ## [0.2.21] - 2021-05-18 ### Fixed diff --git a/Cargo.lock b/Cargo.lock index 3de0393..2ee73f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,6 +10,7 @@ dependencies = [ "atty", "cfg-if", "colored", + "cookie_store 0.14.1", "futures", "futures-channel", "futures-util", @@ -20,6 +21,7 @@ dependencies = [ "once_cell", "regex", "reqwest", + "reqwest_cookie_store", "rpassword", "rprompt", "scraper", @@ -175,9 +177,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] name = "byteorder" @@ -274,16 +276,43 @@ dependencies = [ "version_check", ] +[[package]] +name = "cookie" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf8865bac3d9a3bde5bde9088ca431b11f5d37c7a578b8086af77248b76627" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + [[package]] name = "cookie_store" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3818dfca4b0cb5211a659bbcbb94225b7127407b2b135e650d717bfb78ab10d3" dependencies = [ - "cookie", + "cookie 0.14.4", "idna", "log", - "publicsuffix", + "publicsuffix 1.5.6", + "serde", + "serde_json", + "time", + "url", +] + +[[package]] +name = "cookie_store" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba4e410d33a326cee69c778c761b6a822469ed7c6b82aa7802bef6e12716060" +dependencies = [ + "cookie 0.15.0", + "idna", + "log", + "publicsuffix 2.1.0", "serde", "serde_json", "time", @@ -659,6 +688,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "heck" version = "0.3.2" @@ -820,7 +855,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.9.1", ] [[package]] @@ -1232,6 +1267,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "psl-types" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66b398073e7cdd6f05934389a8f5961e3aabfa66675b6f440df4e2c793d51a4f" + [[package]] name = "publicsuffix" version = "1.5.6" @@ -1242,6 +1283,18 @@ dependencies = [ "url", ] +[[package]] +name = "publicsuffix" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac055aef7cc7a1caefbc65144be879e862467dcd9b8a8d57b64a13e7dce15d" +dependencies = [ + "byteorder", + "hashbrown 0.11.2", + "idna", + "psl-types", +] + [[package]] name = "quote" version = "1.0.9" @@ -1328,8 +1381,8 @@ dependencies = [ "async-compression", "base64", "bytes", - "cookie", - "cookie_store", + "cookie 0.14.4", + "cookie_store 0.12.0", "encoding_rs", "futures-core", "futures-util", @@ -1361,6 +1414,19 @@ dependencies = [ "winreg", ] +[[package]] +name = "reqwest_cookie_store" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a81253b4f49eba884e5b555d08617d2b59be9478fcb53875ded9825d957af4a" +dependencies = [ + "bytes", + "cookie 0.15.0", + "cookie_store 0.14.1", + "reqwest", + "url", +] + [[package]] name = "ring" version = "0.16.20" @@ -1891,9 +1957,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37" +checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975" dependencies = [ "autocfg", "bytes", @@ -2002,9 +2068,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +checksum = "33717dca7ac877f497014e10d73f3acf948c342bee31b5ca7892faf94ccc6b49" dependencies = [ "tinyvec", ] diff --git a/Cargo.toml b/Cargo.toml index 6e6b02c..3c81f60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,8 @@ indicatif = "0.16.0" once_cell = "1.7.2" atty = "0.2.14" h2 = "0.3.3" +cookie_store = "0.14.0" +reqwest_cookie_store = "0.1.5" [features] default = [] diff --git a/src/cli.rs b/src/cli.rs index ef827c3..d6f952d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,7 +12,7 @@ use indicatif::ProgressBar; use once_cell::sync::Lazy; use structopt::StructOpt; -#[derive(Debug, StructOpt)] +#[derive(Debug, Clone, StructOpt)] #[structopt(name = env!("CARGO_PKG_NAME"))] pub struct Opt { /// Do not download files @@ -86,7 +86,7 @@ pub static PROGRESS_BAR_ENABLED: AtomicBool = AtomicBool::new(false); pub static PROGRESS_BAR: Lazy = Lazy::new(|| ProgressBar::new(0)); macro_rules! log { - ($lvl:expr, $($t:expr),+) => { + ($lvl:expr, $($t:expr),+) => {{ #[allow(unused_comparisons)] // 0 <= 0 if $lvl <= crate::cli::LOG_LEVEL.load(std::sync::atomic::Ordering::SeqCst) { if crate::cli::PROGRESS_BAR_ENABLED.load(std::sync::atomic::Ordering::SeqCst) { @@ -95,7 +95,7 @@ macro_rules! log { println!($($t),+); } } - } + }} } macro_rules! info { diff --git a/src/ilias.rs b/src/ilias.rs index 0de3893..f5243bc 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -1,11 +1,13 @@ // SPDX-License-Identifier: GPL-3.0-or-later -use std::error::Error as _; +use std::{error::Error as _, sync::Arc}; use anyhow::{anyhow, Context, Result}; use colored::Colorize; +use cookie_store::CookieStore; use ignore::gitignore::Gitignore; use reqwest::{Client, IntoUrl, Proxy, Url}; +use reqwest_cookie_store::CookieStoreMutex; use scraper::{ElementRef, Html, Selector}; use serde_json::json; @@ -14,10 +16,8 @@ use crate::{cli::Opt, get_request_ticket, selectors::*, ILIAS_URL}; pub struct ILIAS { pub opt: Opt, pub ignore: Gitignore, - // TODO: use these for re-authentication in case of session timeout/invalidation - user: String, - pass: String, client: Client, + cookies: Arc, } /// Returns true if the error is caused by: @@ -36,12 +36,37 @@ fn error_is_http2(error: &reqwest::Error) -> bool { } impl ILIAS { - pub async fn login(opt: Opt, user: impl Into, pass: impl Into, ignore: Gitignore) -> Result { - let user = user.into(); - let pass = pass.into(); - let mut builder = Client::builder() - .cookie_store(true) - .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); + // TODO: de-duplicate the logic below + pub async fn with_session(opt: Opt, session: Arc, ignore: Gitignore) -> Result { + let mut builder = + Client::builder() + .cookie_provider(Arc::clone(&session)) + .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); + if let Some(proxy) = opt.proxy.as_ref() { + let proxy = Proxy::all(proxy)?; + builder = builder.proxy(proxy); + } + let client = builder + // timeout is infinite by default + .build()?; + info!("Re-using previous session cookies.."); + Ok(ILIAS { + opt, + ignore, + client, + cookies: session, + }) + } + + pub async fn login(opt: Opt, user: &str, pass: &str, ignore: Gitignore) -> Result { + let cookie_store = CookieStore::default(); + let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(cookie_store); + let cookie_store = std::sync::Arc::new(cookie_store); + let mut builder = Client::builder().cookie_provider(Arc::clone(&cookie_store)).user_agent(concat!( + env!("CARGO_PKG_NAME"), + "/", + env!("CARGO_PKG_VERSION") + )); if let Some(proxy) = opt.proxy.as_ref() { let proxy = Proxy::all(proxy)?; builder = builder.proxy(proxy); @@ -52,9 +77,8 @@ impl ILIAS { let this = ILIAS { opt, ignore, - user, - pass, client, + cookies: cookie_store, }; info!("Logging into ILIAS using KIT account.."); let session_establishment = this @@ -75,14 +99,16 @@ impl ILIAS { .select(&Selector::parse(r#"input[name="csrf_token"]"#).unwrap()) .next() .context("no CSRF token found")? - .value().attr("value").context("no CSRF token value")?; + .value() + .attr("value") + .context("no CSRF token value")?; info!("Logging into Shibboleth.."); let login_response = this .client .post(url) .form(&json!({ - "j_username": &this.user, - "j_password": &this.pass, + "j_username": user, + "j_password": pass, "_eventId_proceed": "", "csrf_token": csrf_token, })) @@ -108,6 +134,14 @@ impl ILIAS { Ok(this) } + pub async fn save_session(&self) -> Result<()> { + let session_path = self.opt.output.join(".iliassession"); + let mut writer = std::fs::File::create(session_path).map(std::io::BufWriter::new).unwrap(); + let store = self.cookies.lock().map_err(|x| anyhow!("{}", x))?; + store.save_json(&mut writer).map_err(|x| anyhow!(x))?; + Ok(()) + } + pub async fn download(&self, url: &str) -> Result { get_request_ticket().await; log!(2, "Downloading {}", url); diff --git a/src/main.rs b/src/main.rs index 58d3773..55f751b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,9 +21,11 @@ use url::Url; use std::collections::HashSet; use std::future::Future; use std::io; +use std::io::BufReader; use std::path::PathBuf; use std::sync::atomic::Ordering; use std::sync::Arc; +use std::time::SystemTime; pub const ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; @@ -67,26 +69,41 @@ async fn main() { } } -async fn real_main(mut opt: Opt) -> Result<()> { - LOG_LEVEL.store(opt.verbose, Ordering::SeqCst); - #[cfg(windows)] - let _ = colored::control::set_virtual_terminal(true); - - create_dir(&opt.output).await.context("failed to create output directory")?; - // use UNC paths on Windows (#6) - opt.output = fs::canonicalize(opt.output).await.context("failed to canonicalize output directory")?; - - // load .iliasignore file - opt.output.push(".iliasignore"); - let (ignore, error) = Gitignore::new(&opt.output); - if let Some(err) = error { - warning!(err); +async fn try_to_load_session(opt: Opt, ignore: Gitignore) -> Result { + let session_path = opt.output.join(".iliassession"); + let meta = tokio::fs::metadata(&session_path).await?; + let modified = meta.modified()?; + let now = SystemTime::now(); + // the previous session is only useful if it isn't older than ~1 hour + let duration = now.duration_since(modified)?; + if duration.as_secs() <= 60 * 60 { + let file = std::fs::File::open(session_path)?; + let cookies = cookie_store::CookieStore::load_json(BufReader::new(file)) + .map_err(|err| anyhow!(err)) + .context("failed to load session cookies")?; + let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(cookies); + let cookie_store = std::sync::Arc::new(cookie_store); + Ok(ILIAS::with_session(opt, cookie_store, ignore).await?) + } else { + Err(anyhow!("session data too old")) + } +} + +async fn login(opt: Opt, ignore: Gitignore) -> Result { + // load .iliassession file + if opt.keep_session { + match try_to_load_session(opt.clone(), ignore.clone()) + .await + .context("failed to load previous session") + { + Ok(ilias) => return Ok(ilias), + Err(e) => warning!(e), + } } - opt.output.pop(); // loac .iliaslogin file - opt.output.push(".iliaslogin"); - let login = std::fs::read_to_string(&opt.output); + let iliaslogin = opt.output.join(".iliaslogin"); + let login = std::fs::read_to_string(&iliaslogin); let (user, pass) = if let Ok(login) = login { let mut lines = login.split('\n'); let user = lines.next().context("missing user in .iliaslogin")?; @@ -97,15 +114,34 @@ async fn real_main(mut opt: Opt) -> Result<()> { } else { ask_user_pass(&opt).context("credentials input failed")? }; - opt.output.pop(); - let ilias = match ILIAS::login(opt, user, pass, ignore).await { + let ilias = match ILIAS::login(opt, &user, &pass, ignore).await { Ok(ilias) => ilias, Err(e) => { error!(e); std::process::exit(77); }, }; + Ok(ilias) +} + +async fn real_main(mut opt: Opt) -> Result<()> { + LOG_LEVEL.store(opt.verbose, Ordering::SeqCst); + #[cfg(windows)] + let _ = colored::control::set_virtual_terminal(true); + + create_dir(&opt.output).await.context("failed to create output directory")?; + // use UNC paths on Windows (to avoid the default max. path length of 255) + opt.output = fs::canonicalize(opt.output).await.context("failed to canonicalize output directory")?; + + // load .iliasignore file + let (ignore, error) = Gitignore::new(opt.output.join(".iliasignore")); + if let Some(err) = error { + warning!(err); + } + + let ilias = login(opt, ignore).await?; + if ilias.opt.content_tree { if let Err(e) = ilias .download("ilias.php?baseClass=ilRepositoryGUI&cmd=frameset&set_mode=tree&ref_id=1") @@ -149,6 +185,11 @@ async fn real_main(mut opt: Opt) -> Result<()> { warning!("could not disable content tree:", e); } } + if ilias.opt.keep_session { + if let Err(e) = ilias.save_session().await.context("failed to save session cookies") { + warning!(e) + } + } if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { PROGRESS_BAR.set_style(ProgressStyle::default_bar().template("[{pos}/{len}] {wide_msg}")); PROGRESS_BAR.finish_with_message("done"); From daa9bdbfa406fdced5b96b75f9e3f919b038e8e7 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sun, 30 May 2021 14:05:29 +0200 Subject: [PATCH 062/103] Error on expired session --- src/ilias.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ilias.rs b/src/ilias.rs index f5243bc..3699db1 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -184,6 +184,15 @@ impl ILIAS { } pub async fn get_html(&self, url: &str) -> Result { + let resp = self.download(url).await?; + if resp + .url() + .query() + .map(|x| x.contains("reloadpublic=1") || x.contains("cmd=force_login")) + .unwrap_or(false) + { + return Err(anyhow!("not logged in / session expired")); + } let text = self.download(url).await?.text().await?; let html = Html::parse_document(&text); if html.select(&alert_danger).next().is_some() { From 6ea00d5f590cc91b9233c99f3bcfd5bd06018000 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sun, 30 May 2021 14:12:38 +0200 Subject: [PATCH 063/103] Actually save session cookies the cookie store crate by default only saves persistent cookies ... --- src/ilias.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ilias.rs b/src/ilias.rs index 3699db1..5bf342b 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later -use std::{error::Error as _, sync::Arc}; +use std::{error::Error as _, io::Write, sync::Arc}; use anyhow::{anyhow, Context, Result}; use colored::Colorize; @@ -138,7 +138,11 @@ impl ILIAS { let session_path = self.opt.output.join(".iliassession"); let mut writer = std::fs::File::create(session_path).map(std::io::BufWriter::new).unwrap(); let store = self.cookies.lock().map_err(|x| anyhow!("{}", x))?; - store.save_json(&mut writer).map_err(|x| anyhow!(x))?; + // save all cookies, including session cookies + for cookie in store.iter_unexpired().map(serde_json::to_string) { + writeln!(writer, "{}", cookie?)?; + } + writer.flush()?; Ok(()) } From b7330130fb9da605b48d378b153569de8ad1899c Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sun, 30 May 2021 14:29:40 +0200 Subject: [PATCH 064/103] Actually check previous session --- src/main.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 55f751b..c11623c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,9 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::SystemTime; -pub const ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; +static ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; +/// main personal desktop +static DEFAULT_SYNC_URL: &str = "https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems"; #[macro_use] mod cli; @@ -96,7 +98,15 @@ async fn login(opt: Opt, ignore: Gitignore) -> Result { .await .context("failed to load previous session") { - Ok(ilias) => return Ok(ilias), + Ok(ilias) => { + info!("checking session validity.."); + // TODO: this probably isn't the best solution.. + if let Err(e) = ilias.get_html(DEFAULT_SYNC_URL).await { + error!(e) + } else { + return Ok(ilias) + } + }, Err(e) => warning!(e), } } @@ -161,11 +171,8 @@ async fn real_main(mut opt: Opt) -> Result<()> { PROGRESS_BAR.set_message("initializing.."); } - let sync_url = ilias.opt.sync_url.clone().unwrap_or_else(|| { - // default sync URL: main personal desktop - format!("{}ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems", ILIAS_URL) - }); - let obj = Object::from_url(URL::from_href(&sync_url).context("invalid sync URL")?, String::new(), None).context("invalid sync object")?; // name can be empty for first element + let sync_url = ilias.opt.sync_url.as_deref().unwrap_or(DEFAULT_SYNC_URL); + let obj = Object::from_url(URL::from_href(sync_url).context("invalid sync URL")?, String::new(), None).context("invalid sync object")?; // name can be empty for first element spawn!(process_gracefully(ilias.clone(), ilias.opt.output.clone(), obj)); while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await { From 0ebe5bc3cffa55d3dabe9a1482a2e5c819f64062 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Sun, 30 May 2021 17:14:58 +0200 Subject: [PATCH 065/103] Display session validation result --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index c11623c..9b29d9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,11 +99,12 @@ async fn login(opt: Opt, ignore: Gitignore) -> Result { .context("failed to load previous session") { Ok(ilias) => { - info!("checking session validity.."); + info!("Checking session validity.."); // TODO: this probably isn't the best solution.. if let Err(e) = ilias.get_html(DEFAULT_SYNC_URL).await { error!(e) } else { + success!("Session still active!"); return Ok(ilias) } }, From e7354e0ad1e041f1a8486453ae832aa2fac4f4a9 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 2 Jun 2021 11:13:13 +0200 Subject: [PATCH 066/103] Split downloading logic into modules --- Cargo.lock | 6 +- Cargo.toml | 1 + rustfmt.toml | 2 +- src/cli.rs | 24 +- src/ilias.rs | 75 +++-- src/ilias/course.rs | 50 ++++ src/ilias/exercise.rs | 66 +++++ src/ilias/file.rs | 22 ++ src/ilias/folder.rs | 28 ++ src/ilias/forum.rs | 100 +++++++ src/ilias/plugin_dispatch.rs | 87 ++++++ src/ilias/thread.rs | 145 +++++++++ src/ilias/video.rs | 57 ++++ src/ilias/weblink.rs | 70 +++++ src/main.rs | 555 +++-------------------------------- src/queue.rs | 50 ++++ src/util.rs | 21 +- 17 files changed, 806 insertions(+), 553 deletions(-) create mode 100644 src/ilias/course.rs create mode 100644 src/ilias/exercise.rs create mode 100644 src/ilias/file.rs create mode 100644 src/ilias/folder.rs create mode 100644 src/ilias/forum.rs create mode 100644 src/ilias/plugin_dispatch.rs create mode 100644 src/ilias/thread.rs create mode 100644 src/ilias/video.rs create mode 100644 src/ilias/weblink.rs create mode 100644 src/queue.rs diff --git a/Cargo.lock b/Cargo.lock index 2ee73f1..22f2023 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,7 @@ version = "0.2.21" dependencies = [ "anyhow", "atty", + "bytes", "cfg-if", "colored", "cookie_store 0.14.1", @@ -355,11 +356,10 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "autocfg", "cfg-if", "lazy_static", ] diff --git a/Cargo.toml b/Cargo.toml index 3c81f60..6df67db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ atty = "0.2.14" h2 = "0.3.3" cookie_store = "0.14.0" reqwest_cookie_store = "0.1.5" +bytes = "1.0.1" [features] default = [] diff --git a/rustfmt.toml b/rustfmt.toml index 9345fb0..350f6e3 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,3 @@ hard_tabs = true match_block_trailing_comma = true -max_width = 145 +max_width = 120 diff --git a/src/cli.rs b/src/cli.rs index d6f952d..faf4f5a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,8 +6,6 @@ use std::sync::atomic::{AtomicBool, AtomicUsize}; #[cfg(feature = "keyring-auth")] use anyhow::anyhow; use anyhow::{Context, Result}; -#[cfg(feature = "keyring-auth")] -use colored::Colorize as _; use indicatif::ProgressBar; use once_cell::sync::Lazy; use structopt::StructOpt; @@ -87,6 +85,8 @@ pub static PROGRESS_BAR: Lazy = Lazy::new(|| ProgressBar::new(0)); macro_rules! log { ($lvl:expr, $($t:expr),+) => {{ + #[allow(unused_imports)] + use colored::Colorize as _; #[allow(unused_comparisons)] // 0 <= 0 if $lvl <= crate::cli::LOG_LEVEL.load(std::sync::atomic::Ordering::SeqCst) { if crate::cli::PROGRESS_BAR_ENABLED.load(std::sync::atomic::Ordering::SeqCst) { @@ -111,21 +111,21 @@ macro_rules! success { } macro_rules! warning { - ($e:expr) => { + ($e:expr) => {{ log!(0, "Warning: {}", format!("{:?}", $e).bright_yellow()); - }; - ($msg:expr, $e:expr) => { + }}; + ($msg:expr, $e:expr) => {{ log!(0, "Warning: {}", format!("{} {:?}", $msg, $e).bright_yellow()); - }; - ($msg1:expr, $msg2:expr, $e:expr) => { + }}; + ($msg1:expr, $msg2:expr, $e:expr) => {{ log!(0, "Warning: {}", format!("{} {} {:?}", $msg1, $msg2, $e).bright_yellow()); - }; - (format => $($e:expr),+) => { + }}; + (format => $($e:expr),+) => {{ log!(0, "Warning: {}", format!($($e),+).bright_yellow()); - }; - ($lvl:expr; $($e:expr),+) => { + }}; + ($lvl:expr; $($e:expr),+) => {{ log!($lvl, "Warning: {}", format!($($e),+).bright_yellow()); - } + }}; } macro_rules! error { diff --git a/src/ilias.rs b/src/ilias.rs index 5bf342b..ec497d9 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -3,15 +3,32 @@ use std::{error::Error as _, io::Write, sync::Arc}; use anyhow::{anyhow, Context, Result}; -use colored::Colorize; use cookie_store::CookieStore; use ignore::gitignore::Gitignore; +use once_cell::sync::Lazy; use reqwest::{Client, IntoUrl, Proxy, Url}; use reqwest_cookie_store::CookieStoreMutex; use scraper::{ElementRef, Html, Selector}; use serde_json::json; -use crate::{cli::Opt, get_request_ticket, selectors::*, ILIAS_URL}; +use crate::{cli::Opt, queue, ILIAS_URL}; + +pub mod course; +pub mod exercise; +pub mod file; +pub mod folder; +pub mod forum; +pub mod plugin_dispatch; +pub mod thread; +pub mod video; +pub mod weblink; + +static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); +static ALERT_DANGER: Lazy = Lazy::new(|| Selector::parse("div.alert-danger").unwrap()); +static IL_CONTENT_CONTAINER: Lazy = Lazy::new(|| Selector::parse("#il_center_col").unwrap()); +static ITEM_PROP: Lazy = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap()); +static CONTAINER_ITEMS: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem").unwrap()); +static CONTAINER_ITEM_TITLE: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle").unwrap()); pub struct ILIAS { pub opt: Opt, @@ -38,10 +55,9 @@ fn error_is_http2(error: &reqwest::Error) -> bool { impl ILIAS { // TODO: de-duplicate the logic below pub async fn with_session(opt: Opt, session: Arc, ignore: Gitignore) -> Result { - let mut builder = - Client::builder() - .cookie_provider(Arc::clone(&session)) - .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); + let mut builder = Client::builder() + .cookie_provider(Arc::clone(&session)) + .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); if let Some(proxy) = opt.proxy.as_ref() { let proxy = Proxy::all(proxy)?; builder = builder.proxy(proxy); @@ -62,11 +78,9 @@ impl ILIAS { let cookie_store = CookieStore::default(); let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(cookie_store); let cookie_store = std::sync::Arc::new(cookie_store); - let mut builder = Client::builder().cookie_provider(Arc::clone(&cookie_store)).user_agent(concat!( - env!("CARGO_PKG_NAME"), - "/", - env!("CARGO_PKG_VERSION") - )); + let mut builder = Client::builder() + .cookie_provider(Arc::clone(&cookie_store)) + .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); if let Some(proxy) = opt.proxy.as_ref() { let proxy = Proxy::all(proxy)?; builder = builder.proxy(proxy); @@ -118,7 +132,10 @@ impl ILIAS { .await?; let dom = Html::parse_document(&login_response); let saml = Selector::parse(r#"input[name="SAMLResponse"]"#).unwrap(); - let saml = dom.select(&saml).next().context("no SAML response, incorrect password?")?; + let saml = dom + .select(&saml) + .next() + .context("no SAML response, incorrect password?")?; let relay_state = Selector::parse(r#"input[name="RelayState"]"#).unwrap(); let relay_state = dom.select(&relay_state).next().context("no relay state")?; info!("Logging into ILIAS.."); @@ -136,7 +153,9 @@ impl ILIAS { pub async fn save_session(&self) -> Result<()> { let session_path = self.opt.output.join(".iliassession"); - let mut writer = std::fs::File::create(session_path).map(std::io::BufWriter::new).unwrap(); + let mut writer = std::fs::File::create(session_path) + .map(std::io::BufWriter::new) + .unwrap(); let store = self.cookies.lock().map_err(|x| anyhow!("{}", x))?; // save all cookies, including session cookies for cookie in store.iter_unexpired().map(serde_json::to_string) { @@ -147,7 +166,7 @@ impl ILIAS { } pub async fn download(&self, url: &str) -> Result { - get_request_ticket().await; + queue::get_request_ticket().await; log!(2, "Downloading {}", url); let url = if url.starts_with("http://") || url.starts_with("https://") { url.to_owned() @@ -171,7 +190,7 @@ impl ILIAS { } pub async fn head(&self, url: U) -> Result { - get_request_ticket().await; + queue::get_request_ticket().await; let url = url.into_url()?; for attempt in 1..10 { let result = self.client.head(url.clone()).send().await; @@ -199,7 +218,7 @@ impl ILIAS { } let text = self.download(url).await?.text().await?; let html = Html::parse_document(&text); - if html.select(&alert_danger).next().is_some() { + if html.select(&ALERT_DANGER).next().is_some() { Err(anyhow!("ILIAS error")) } else { Ok(html) @@ -209,7 +228,7 @@ impl ILIAS { pub async fn get_html_fragment(&self, url: &str) -> Result { let text = self.download(url).await?.text().await?; let html = Html::parse_fragment(&text); - if html.select(&alert_danger).next().is_some() { + if html.select(&ALERT_DANGER).next().is_some() { Err(anyhow!("ILIAS error")) } else { Ok(html) @@ -217,9 +236,11 @@ impl ILIAS { } pub fn get_items(html: &Html) -> Vec> { - html.select(&container_items) + html.select(&CONTAINER_ITEMS) .flat_map(|item| { - item.select(&container_item_title).next().map(|link| Object::from_link(item, link)) + item.select(&CONTAINER_ITEM_TITLE) + .next() + .map(|link| Object::from_link(item, link)) // items without links are ignored }) .collect() @@ -229,7 +250,7 @@ impl ILIAS { pub async fn get_course_content(&self, url: &URL) -> Result<(Vec>, Option)> { let html = self.get_html(&url.url).await?; - let main_text = if let Some(el) = html.select(&il_content_container).next() { + let main_text = if let Some(el) = html.select(&IL_CONTENT_CONTAINER).next() { if !el .children() .flat_map(|x| x.value().as_element()) @@ -268,6 +289,10 @@ impl ILIAS { } } +trait IliasObject { + fn download(ilias: Arc) -> Result<()>; +} + #[derive(Debug)] pub enum Object { Course { name: String, url: URL }, @@ -405,9 +430,15 @@ impl Object { // download page containing metadata return Ok(Generic { name, url }); } else { - let mut item_props = item.context("can't construct file object without HTML object")?.select(&item_prop); + let mut item_props = item + .context("can't construct file object without HTML object")? + .select(&ITEM_PROP); let ext = item_props.next().context("cannot find file extension")?; - let version = item_props.nth(1).context("cannot find 3rd file metadata")?.text().collect::(); + let version = item_props + .nth(1) + .context("cannot find 3rd file metadata")? + .text() + .collect::(); let version = version.trim(); if let Some(v) = version.strip_prefix("Version: ") { name += "_v"; diff --git a/src/ilias/course.rs b/src/ilias/course.rs new file mode 100644 index 0000000..211b365 --- /dev/null +++ b/src/ilias/course.rs @@ -0,0 +1,50 @@ +use std::{path::PathBuf, sync::Arc}; + +use anyhow::{Context, Result}; +use once_cell::sync::Lazy; +use regex::Regex; + +use crate::{ + process_gracefully, + queue::spawn, + util::{file_escape, write_file_data}, +}; + +use super::{ILIAS, URL}; + +static CMD_NODE_REGEX: Lazy = Lazy::new(|| Regex::new(r#"cmdNode=uf:\w\w"#).unwrap()); + +pub async fn download(path: PathBuf, ilias: Arc, url: &URL, name: &str) -> Result<()> { + let content = if ilias.opt.content_tree { + let html = ilias.download(&url.url).await?.text().await?; + let cmd_node = CMD_NODE_REGEX.find(&html).context("can't find cmdNode")?.as_str()[8..].to_owned(); + let content_tree = ilias.get_course_content_tree(&url.ref_id, &cmd_node).await; + match content_tree { + Ok(tree) => (tree.into_iter().map(Result::Ok).collect(), None), + Err(e) => { + // some folders are hidden on the course page and can only be found via the RSS feed / recent activity / content tree sidebar + // TODO: this is probably never the case for folders? + if html.contains(r#"input[name="cmd[join]""#) { + return Ok(()); // ignore groups we are not in + } + warning!(name, "falling back to incomplete course content extractor!", e); + ilias.get_course_content(&url).await? // TODO: perhaps don't download almost the same content 3x + }, + } + } else { + ilias.get_course_content(&url).await? + }; + if let Some(s) = content.1.as_ref() { + let path = path.join("course.html"); + write_file_data(&path, &mut s.as_bytes()) + .await + .context("failed to write course page html")?; + } + for item in content.0 { + let item = item?; + let path = path.join(file_escape(item.name())); + let ilias = Arc::clone(&ilias); + spawn(process_gracefully(ilias, path, item)); + } + Ok(()) +} diff --git a/src/ilias/exercise.rs b/src/ilias/exercise.rs new file mode 100644 index 0000000..b2f48c2 --- /dev/null +++ b/src/ilias/exercise.rs @@ -0,0 +1,66 @@ +use std::{collections::HashSet, path::Path, sync::Arc}; + +use anyhow::{Context, Result}; +use once_cell::sync::Lazy; +use scraper::Selector; + +use crate::{process_gracefully, queue::spawn, util::file_escape}; + +use super::{Object, ILIAS, URL}; + +static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); +static FORM_GROUP: Lazy = Lazy::new(|| Selector::parse(".form-group").unwrap()); +static FORM_NAME: Lazy = Lazy::new(|| Selector::parse(".il_InfoScreenProperty").unwrap()); + +pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { + let html = ilias.get_html(&url.url).await?; + let mut filenames = HashSet::new(); + for row in html.select(&FORM_GROUP) { + let link = row.select(&LINKS).next(); + if link.is_none() { + continue; + } + let link = link.unwrap(); + let href = link.value().attr("href"); + if href.is_none() { + continue; + } + let href = href.unwrap(); + let url = URL::from_href(href)?; + let cmd = url.cmd.as_deref().unwrap_or(""); + if cmd != "downloadFile" && cmd != "downloadGlobalFeedbackFile" && cmd != "downloadFeedbackFile" { + continue; + } + // link is definitely just a download link to the exercise or the solution + let name = row + .select(&FORM_NAME) + .next() + .context("link without file name")? + .text() + .collect::() + .trim() + .to_owned(); + let item = Object::File { url, name }; + let mut path = path.to_owned(); + // handle files with the same name + let filename = file_escape(item.name()); + let mut parts = filename.rsplitn(2, '.'); + let extension = parts.next().unwrap_or(&filename); + let name = parts.next().unwrap_or(""); + let mut unique_filename = filename.clone(); + let mut i = 1; + while filenames.contains(&unique_filename) { + i += 1; + if name.is_empty() { + unique_filename = format!("{}{}", extension, i); + } else { + unique_filename = format!("{}{}.{}", name, i, extension); + } + } + filenames.insert(unique_filename.clone()); + path.push(unique_filename); + let ilias = Arc::clone(&ilias); + spawn(process_gracefully(ilias, path, item)); + } + Ok(()) +} diff --git a/src/ilias/file.rs b/src/ilias/file.rs new file mode 100644 index 0000000..1df7b2a --- /dev/null +++ b/src/ilias/file.rs @@ -0,0 +1,22 @@ +use std::{path::Path, sync::Arc}; + +use anyhow::Result; +use tokio::fs; + +use crate::util::write_stream_to_file; + +use super::{ILIAS, URL}; + +pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: &URL) -> Result<()> { + if ilias.opt.skip_files { + return Ok(()); + } + if !ilias.opt.force && fs::metadata(&path).await.is_ok() { + log!(2, "Skipping download, file exists already"); + return Ok(()); + } + let data = ilias.download(&url.url).await?; + log!(0, "Writing {}", relative_path.to_string_lossy()); + write_stream_to_file(&path, data.bytes_stream()).await?; + Ok(()) +} diff --git a/src/ilias/folder.rs b/src/ilias/folder.rs new file mode 100644 index 0000000..2948c18 --- /dev/null +++ b/src/ilias/folder.rs @@ -0,0 +1,28 @@ +use std::{path::Path, sync::Arc}; + +use anyhow::{Context, Result}; + +use crate::{ + process_gracefully, + queue::spawn, + util::{file_escape, write_file_data}, +}; + +use super::{ILIAS, URL}; + +pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { + let content = ilias.get_course_content(&url).await?; + if let Some(s) = content.1.as_ref() { + let path = path.join("folder.html"); + write_file_data(&path, &mut s.as_bytes()) + .await + .context("failed to write folder page html")?; + } + for item in content.0 { + let item = item?; + let path = path.join(file_escape(item.name())); + let ilias = Arc::clone(&ilias); + spawn(process_gracefully(ilias, path, item)); + } + Ok(()) +} diff --git a/src/ilias/forum.rs b/src/ilias/forum.rs new file mode 100644 index 0000000..0e141bc --- /dev/null +++ b/src/ilias/forum.rs @@ -0,0 +1,100 @@ +use std::{path::Path, sync::Arc}; + +use anyhow::{Context, Result}; +use once_cell::sync::Lazy; +use scraper::{Html, Selector}; + +use crate::{ilias::Object, process_gracefully, queue::spawn, util::file_escape}; + +use super::{ILIAS, URL}; + +static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); +static TABLE_HEADER: Lazy = Lazy::new(|| Selector::parse("th").unwrap()); +static TABLE_ROW: Lazy = Lazy::new(|| Selector::parse("tr").unwrap()); +static TABLE_CELLS: Lazy = Lazy::new(|| Selector::parse("td").unwrap()); + +static FORUM_PAGES: Lazy = + Lazy::new(|| Selector::parse("div.ilTableNav > table > tbody > tr > td > a").unwrap()); + +const NO_ENTRIES: &str = "Keine Einträge"; + +pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { + if !ilias.opt.forum { + return Ok(()); + } + let url = &url.url; + let html = { + let data = ilias.download(url); + let html_text = data.await?.text().await?; + let url = { + let html = Html::parse_document(&html_text); + let thread_count_selector = html + .select(&LINKS) + .flat_map(|x| x.value().attr("href")) + .find(|x| x.contains("trows=800")); + if thread_count_selector.is_none() { + if let Some(cell) = html.select(&TABLE_CELLS).next() { + if cell.text().any(|x| x == NO_ENTRIES) { + return Ok(()); // empty forum + } + } + } + thread_count_selector + .context("can't find forum thread count selector (empty forum?)")? + .to_owned() + }; + let data = ilias.download(&url); + let html = data.await?.text().await?; + Html::parse_document(&html) + }; + for row in html.select(&TABLE_ROW) { + if row.value().attr("class") == Some("hidden-print") { + continue; // thread count + } + if row.select(&TABLE_HEADER).next().is_some() { + continue; + } + let cells = row.select(&TABLE_CELLS).collect::>(); + if cells.len() != 6 { + warning!(format => + "Warning: {}{} {} {}", + "unusual table row (", cells.len(), "cells) in", url.to_string() + ); + continue; + } + let link = cells[1].select(&LINKS).next().context("thread link not found")?; + let object = Object::from_link(link, link)?; + let mut path = path.to_owned(); + let name = format!( + "{}_{}", + object.url().thr_pk.as_ref().context("thr_pk not found for thread")?, + link.text().collect::().trim() + ); + path.push(file_escape(&name)); + // FIXME: this heuristic no longer works after downloading attachments + // TODO: set modification date? + let saved_posts = { + match std::fs::read_dir(&path) { + // TODO: make this async + Ok(stream) => stream.count(), + Err(_) => 0, + } + }; + let available_posts = cells[3] + .text() + .next() + .unwrap_or_default() + .trim() + .parse::() + .context("parsing post count failed")?; + if available_posts <= saved_posts && !ilias.opt.force { + continue; + } + let ilias = Arc::clone(&ilias); + spawn(process_gracefully(ilias, path, object)); + } + if html.select(&FORUM_PAGES).count() > 0 { + log!(0, "Ignoring older threads in {:?}..", path); + } + Ok(()) +} diff --git a/src/ilias/plugin_dispatch.rs b/src/ilias/plugin_dispatch.rs new file mode 100644 index 0000000..f5bdaa2 --- /dev/null +++ b/src/ilias/plugin_dispatch.rs @@ -0,0 +1,87 @@ +use std::{path::Path, sync::Arc}; + +use anyhow::{Context, Result}; +use once_cell::sync::Lazy; +use reqwest::Url; +use scraper::{Html, Selector}; + +use crate::{ilias::Object, process_gracefully, queue::spawn, util::file_escape, ILIAS_URL}; + +use super::{ILIAS, URL}; + +static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); +static A_TARGET_BLANK: Lazy = Lazy::new(|| Selector::parse(r#"a[target="_blank"]"#).unwrap()); +static VIDEO_ROWS: Lazy = Lazy::new(|| Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap()); +static TABLE_CELLS: Lazy = Lazy::new(|| Selector::parse("td").unwrap()); + +const NO_ENTRIES: &str = "Keine Einträge"; + +pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { + if ilias.opt.no_videos { + return Ok(()); + } + let full_url = { + // first find the link to full video list + let list_url = format!("{}ilias.php?ref_id={}&cmdClass=xocteventgui&cmdNode=nc:n4:14u&baseClass=ilObjPluginDispatchGUI&lang=de&limit=20&cmd=asyncGetTableGUI&cmdMode=asynch", ILIAS_URL, url.ref_id); + log!(1, "Loading {}", list_url); + let data = ilias.download(&list_url).await?; + let html = data.text().await?; + let html = Html::parse_fragment(&html); + html.select(&LINKS) + .filter_map(|link| link.value().attr("href")) + .filter(|href| href.contains("trows=800")) + .map(|x| x.to_string()) + .next() + .context("video list link not found")? + }; + log!(1, "Rewriting {}", full_url); + let mut full_url = Url::parse(&format!("{}{}", ILIAS_URL, full_url))?; + let mut query_parameters = full_url + .query_pairs() + .map(|(x, y)| (x.into_owned(), y.into_owned())) + .collect::>(); + for (key, value) in &mut query_parameters { + match key.as_ref() { + "cmd" => *value = "asyncGetTableGUI".into(), + "cmdClass" => *value = "xocteventgui".into(), + _ => {}, + } + } + query_parameters.push(("cmdMode".into(), "asynch".into())); + full_url + .query_pairs_mut() + .clear() + .extend_pairs(&query_parameters) + .finish(); + log!(1, "Loading {}", full_url); + let data = ilias.download(full_url.as_str()).await?; + let html = data.text().await?; + let html = Html::parse_fragment(&html); + for row in html.select(&VIDEO_ROWS) { + let link = row.select(&A_TARGET_BLANK).next(); + if link.is_none() { + if !row.text().any(|x| x == NO_ENTRIES) { + warning!(format => "table row without link in {}", url.url); + } + continue; + } + let link = link.unwrap(); + let mut cells = row.select(&TABLE_CELLS); + if let Some(title) = cells.nth(2) { + let title = title.text().collect::(); + let title = title.trim(); + if title.starts_with(" = Lazy::new(|| Selector::parse("a").unwrap()); +static IMAGES: Lazy = Lazy::new(|| Selector::parse("img").unwrap()); +static TABLES: Lazy = Lazy::new(|| Selector::parse("table").unwrap()); +static LINK_IN_TABLE: Lazy = Lazy::new(|| Selector::parse("tbody tr td a").unwrap()); +static POST_ROW: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostRow").unwrap()); +static POST_TITLE: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostTitle").unwrap()); +static POST_CONTAINER: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostContentContainer").unwrap()); +static POST_ATTACHMENTS: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostAttachmentsContainer").unwrap()); +static SPAN_SMALL: Lazy = Lazy::new(|| Selector::parse("span.small").unwrap()); +static IMAGE_SRC_REGEX: Lazy = Lazy::new(|| Regex::new(r#"\./data/produktiv/mobs/mm_(\d+)/([^?]+).+"#).unwrap()); + +pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: &URL) -> Result<()> { + if !ilias.opt.forum { + return Ok(()); + } + let mut all_images = Vec::new(); + let mut attachments = Vec::new(); + { + let html = ilias.get_html(&url.url).await?; + for post in html.select(&POST_ROW) { + let title = post + .select(&POST_TITLE) + .next() + .context("post title not found")? + .text() + .collect::(); + let author = post.select(&SPAN_SMALL).next().context("post author not found")?; + let author = author.text().collect::(); + let author = author.trim().split('|').collect::>(); + let author = if author.len() == 2 { + author[0] // pseudonymous forum + } else if author.len() == 3 { + if author[1] != "Pseudonym" { + author[1] + } else { + author[0] + } + } else { + return Err(anyhow!("author data in unknown format")); + } + .trim(); + let container = post + .select(&POST_CONTAINER) + .next() + .context("post container not found")?; + let link = container.select(&LINKS).next().context("post link not found")?; + let id = link.value().attr("id").context("no id in thread link")?.to_owned(); + let name = format!("{}_{}_{}.html", id, author, title.trim()); + let data = container.inner_html(); + let path = path.join(file_escape(&name)); + let relative_path = relative_path.join(file_escape(&name)); + spawn(handle_gracefully(async move { + log!(0, "Writing {}", relative_path.display()); + write_file_data(&path, &mut data.as_bytes()) + .await + .context("failed to write forum post") + })); + let images = container + .select(&IMAGES) + .map(|x| x.value().attr("src").map(|x| x.to_owned())); + for image in images { + let image = image.context("no src on image")?; + all_images.push((id.clone(), image)); + } + if let Some(container) = container.select(&POST_ATTACHMENTS).next() { + for attachment in container.select(&LINKS) { + attachments.push(( + id.clone(), + attachment.text().collect::(), + attachment.value().attr("href").map(|x| x.to_owned()), + )); + } + } + } + // pagination + if let Some(pages) = html.select(&TABLES).next() { + if let Some(last) = pages.select(&LINK_IN_TABLE).last() { + let text = last.text().collect::(); + if text.trim() == ">>" { + // not last page yet + let ilias = Arc::clone(&ilias); + let next_page = Object::Thread { + url: URL::from_href(last.value().attr("href").context("page link not found")?)?, + }; + spawn(process_gracefully(ilias, path.to_owned(), next_page)); + } + } else { + log!( + 0, + "Warning: {} {}", + "unable to find pagination links in".bright_yellow(), + url.url.to_string().bright_yellow() + ); + } + } + } + for (id, image) in all_images { + let src = URL::from_href(&image)?; + let dl = ilias.download(&src.url).await?; + let mut path = path.to_owned(); + if let Some(m) = IMAGE_SRC_REGEX.captures(&image) { + // image uploaded to ILIAS + let (media_id, filename) = (m.get(1).unwrap().as_str(), m.get(2).unwrap().as_str()); + path.push(file_escape(&format!("{}_{}_{}", id, media_id, filename))); + } else { + // external image + path.push(file_escape(&format!("{}_{}", id, image))); + } + spawn(handle_gracefully(async move { + let bytes = dl.bytes().await?; + write_file_data(&path, &mut &*bytes) + .await + .context("failed to write forum post image attachment") + })); + } + for (id, name, url) in attachments { + let url = url.context("attachment without href")?; + let src = URL::from_href(&url)?; + let dl = ilias.download(&src.url).await?; + let mut path = path.to_owned(); + path.push(file_escape(&format!("{}_{}", id, name))); + spawn(handle_gracefully(async move { + let bytes = dl.bytes().await?; + write_file_data(&path, &mut &*bytes) + .await + .context("failed to write forum post file attachment") + })); + } + Ok(()) +} diff --git a/src/ilias/video.rs b/src/ilias/video.rs new file mode 100644 index 0000000..e322544 --- /dev/null +++ b/src/ilias/video.rs @@ -0,0 +1,57 @@ +use std::{path::Path, sync::Arc}; + +use anyhow::{Context, Result}; +use once_cell::sync::Lazy; +use regex::Regex; +use tokio::fs; + +use crate::{util::write_stream_to_file, ILIAS_URL}; + +use super::{ILIAS, URL}; + +static XOCT_REGEX: Lazy = + Lazy::new(|| Regex::new(r#"(?m)"#).unwrap()); + +pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: &URL) -> Result<()> { + if ilias.opt.no_videos { + return Ok(()); + } + if fs::metadata(&path).await.is_ok() && !(ilias.opt.force || ilias.opt.check_videos) { + log!(2, "Skipping download, file exists already"); + return Ok(()); + } + let url = format!("{}{}", ILIAS_URL, url.url); + let data = ilias.download(&url); + let html = data.await?.text().await?; + log!(2, "{}", html); + let json: serde_json::Value = { + let mut json_capture = XOCT_REGEX.captures_iter(&html); + let json = &json_capture.next().context("xoct player json not found")?[1]; + log!(2, "{}", json); + let json = json.split(",\n").next().context("invalid xoct player json")?; + serde_json::from_str(&json.trim())? + }; + log!(2, "{}", json); + let url = json + .pointer("/streams/0/sources/mp4/0/src") + .context("video src not found")? + .as_str() + .context("video src not string")?; + let meta = fs::metadata(&path).await; + if !ilias.opt.force && meta.is_ok() && ilias.opt.check_videos { + let head = ilias.head(url).await.context("HEAD request failed")?; + if let Some(len) = head.headers().get("content-length") { + if meta?.len() != len.to_str()?.parse::()? { + warning!( + relative_path.to_string_lossy(), + "was updated, consider moving the outdated file" + ); + } + } + } else { + let resp = ilias.download(&url).await?; + log!(0, "Writing {}", relative_path.to_string_lossy()); + write_stream_to_file(&path, resp.bytes_stream()).await?; + } + Ok(()) +} diff --git a/src/ilias/weblink.rs b/src/ilias/weblink.rs new file mode 100644 index 0000000..72e7763 --- /dev/null +++ b/src/ilias/weblink.rs @@ -0,0 +1,70 @@ +use std::{path::Path, sync::Arc}; + +use anyhow::{Context, Result}; +use once_cell::sync::Lazy; +use scraper::Selector; +use tokio::fs; + +use crate::{ + util::{create_dir, file_escape, write_file_data}, + ILIAS_URL, +}; + +use super::{ILIAS, URL}; + +static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); + +pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: &URL) -> Result<()> { + if !ilias.opt.force && fs::metadata(&path).await.is_ok() { + log!(2, "Skipping download, link exists already"); + return Ok(()); + } + let head_req_result = ilias.head(&url.url).await; + let url = match &head_req_result { + Err(e) => e.url().context("HEAD request failed")?.as_str(), + Ok(head) => head.url().as_str(), + }; + if url.starts_with(ILIAS_URL) { + // is a link list + if fs::metadata(&path).await.is_err() { + create_dir(&path).await?; + log!(0, "Writing {}", relative_path.to_string_lossy()); + } + + let urls = { + let html = ilias.get_html(url).await?; + html.select(&LINKS) + .filter_map(|x| x.value().attr("href").map(|y| (y, x.text().collect::()))) + .map(|(x, y)| { + URL::from_href(x) + .map(|z| (z, y.trim().to_owned())) + .context("parsing weblink") + }) + .collect::>>() + }?; + + for (url, name) in urls { + if url.cmd.as_deref().unwrap_or("") != "callLink" { + continue; + } + + let head = ilias + .head(url.url.as_str()) + .await + .context("HEAD request to web link failed"); + if let Some(err) = head.as_ref().err() { + warning!(err); + continue; + } + let head = head.unwrap(); + let url = head.url().as_str(); + write_file_data(path.join(file_escape(&name)), &mut url.as_bytes()).await?; + } + } else { + log!(0, "Writing {}", relative_path.to_string_lossy()); + write_file_data(&path, &mut url.as_bytes()) + .await + .context("failed to save weblink URL")?; + } + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 9b29d9d..197e931 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,26 +1,14 @@ // SPDX-License-Identifier: GPL-3.0-or-later -#![allow(clippy::upper_case_acronyms)] - use anyhow::{anyhow, Context, Result}; -use colored::Colorize; use futures::future::{self, Either}; -use futures_channel::mpsc::UnboundedSender; -use futures_util::stream::TryStreamExt; -use futures_util::StreamExt; +use futures::StreamExt; use ignore::gitignore::Gitignore; use indicatif::{ProgressDrawTarget, ProgressStyle}; -use once_cell::sync::{Lazy, OnceCell}; -use scraper::Html; use structopt::StructOpt; -use tokio::task::{self, JoinHandle}; -use tokio::{fs, sync::Semaphore, time}; -use tokio_util::io::StreamReader; -use url::Url; +use tokio::fs; -use std::collections::HashSet; use std::future::Future; -use std::io; use std::io::BufReader; use std::path::PathBuf; use std::sync::atomic::Ordering; @@ -29,7 +17,8 @@ use std::time::SystemTime; static ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; /// main personal desktop -static DEFAULT_SYNC_URL: &str = "https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems"; +static DEFAULT_SYNC_URL: &str = + "https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems"; #[macro_use] mod cli; @@ -37,35 +26,13 @@ use cli::*; mod ilias; use ilias::*; use Object::*; +mod queue; mod util; use util::*; -/// Global job queue -static TASKS: OnceCell>> = OnceCell::new(); -static TASKS_RUNNING: Lazy = Lazy::new(|| Semaphore::new(0)); -static REQUEST_TICKETS: Lazy = Lazy::new(|| Semaphore::new(0)); - -pub async fn get_request_ticket() { - REQUEST_TICKETS.acquire().await.unwrap().forget(); -} - -macro_rules! spawn { - ($e:expr) => { - TASKS.get().unwrap().unbounded_send(task::spawn($e)).unwrap(); - }; -} - #[tokio::main] async fn main() { let opt = Opt::from_args(); - let rate = opt.rate; - task::spawn(async move { - let mut interval = time::interval(time::Duration::from_secs_f64(60.0 / rate as f64)); - loop { - interval.tick().await; - REQUEST_TICKETS.add_permits(1); - } - }); if let Err(e) = real_main(opt).await { error!(e); } @@ -105,7 +72,7 @@ async fn login(opt: Opt, ignore: Gitignore) -> Result { error!(e) } else { success!("Session still active!"); - return Ok(ilias) + return Ok(ilias); } }, Err(e) => warning!(e), @@ -141,9 +108,13 @@ async fn real_main(mut opt: Opt) -> Result<()> { #[cfg(windows)] let _ = colored::control::set_virtual_terminal(true); - create_dir(&opt.output).await.context("failed to create output directory")?; + create_dir(&opt.output) + .await + .context("failed to create output directory")?; // use UNC paths on Windows (to avoid the default max. path length of 255) - opt.output = fs::canonicalize(opt.output).await.context("failed to canonicalize output directory")?; + opt.output = fs::canonicalize(opt.output) + .await + .context("failed to canonicalize output directory")?; // load .iliasignore file let (ignore, error) = Gitignore::new(opt.output.join(".iliasignore")); @@ -151,6 +122,8 @@ async fn real_main(mut opt: Opt) -> Result<()> { warning!(err); } + queue::set_download_rate(opt.rate); + let ilias = login(opt, ignore).await?; if ilias.opt.content_tree { @@ -162,9 +135,7 @@ async fn real_main(mut opt: Opt) -> Result<()> { } } let ilias = Arc::new(ilias); - let (tx, mut rx) = futures_channel::mpsc::unbounded::>(); - TASKS.get_or_init(|| tx.clone()); - TASKS_RUNNING.add_permits(ilias.opt.jobs); + let mut rx = queue::set_parallel_jobs(ilias.opt.jobs); PROGRESS_BAR_ENABLED.store(atty::is(atty::Stream::Stdout), Ordering::SeqCst); if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { PROGRESS_BAR.set_draw_target(ProgressDrawTarget::stderr_nohz()); @@ -173,8 +144,13 @@ async fn real_main(mut opt: Opt) -> Result<()> { } let sync_url = ilias.opt.sync_url.as_deref().unwrap_or(DEFAULT_SYNC_URL); - let obj = Object::from_url(URL::from_href(sync_url).context("invalid sync URL")?, String::new(), None).context("invalid sync object")?; // name can be empty for first element - spawn!(process_gracefully(ilias.clone(), ilias.opt.output.clone(), obj)); + let obj = Object::from_url( + URL::from_href(sync_url).context("invalid sync URL")?, + String::new(), + None, + ) + .context("invalid sync object")?; + queue::spawn(process_gracefully(ilias.clone(), ilias.opt.output.clone(), obj)); while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await { if let Some(task) = task { @@ -208,11 +184,11 @@ async fn real_main(mut opt: Opt) -> Result<()> { // https://github.com/rust-lang/rust/issues/53690#issuecomment-418911229 #[allow(clippy::manual_async_fn)] fn process_gracefully(ilias: Arc, path: PathBuf, obj: Object) -> impl Future + Send { + if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { + PROGRESS_BAR.inc_length(1); + } async move { - if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { - PROGRESS_BAR.inc_length(1); - } - let permit = TASKS_RUNNING.acquire().await.unwrap(); + let permit = queue::get_ticket(); let path_text = path.to_string_lossy().into_owned(); if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { error!("Syncing {}", path_text; e); @@ -227,46 +203,9 @@ async fn handle_gracefully(fut: impl Future>) { } } -#[allow(non_upper_case_globals)] -mod selectors { - use once_cell::sync::Lazy; - use regex::Regex; - use scraper::Selector; - // construct CSS selectors once - pub static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); - pub static a_target_blank: Lazy = Lazy::new(|| Selector::parse(r#"a[target="_blank"]"#).unwrap()); - pub static IMAGES: Lazy = Lazy::new(|| Selector::parse("img").unwrap()); - pub static TABLES: Lazy = Lazy::new(|| Selector::parse("table").unwrap()); - pub static VIDEO_ROWS: Lazy = Lazy::new(|| Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap()); - pub static links_in_table: Lazy = Lazy::new(|| Selector::parse("tbody tr td a").unwrap()); - pub static th: Lazy = Lazy::new(|| Selector::parse("th").unwrap()); - pub static td: Lazy = Lazy::new(|| Selector::parse("td").unwrap()); - pub static tr: Lazy = Lazy::new(|| Selector::parse("tr").unwrap()); - pub static post_row: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostRow").unwrap()); - pub static post_title: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostTitle").unwrap()); - pub static post_container: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostContentContainer").unwrap()); - pub static post_attachments: Lazy = Lazy::new(|| Selector::parse(".ilFrmPostAttachmentsContainer").unwrap()); - pub static span_small: Lazy = Lazy::new(|| Selector::parse("span.small").unwrap()); - pub static forum_pages: Lazy = Lazy::new(|| Selector::parse("div.ilTableNav > table > tbody > tr > td > a").unwrap()); - pub static alert_danger: Lazy = Lazy::new(|| Selector::parse("div.alert-danger").unwrap()); - pub static form_group: Lazy = Lazy::new(|| Selector::parse(".form-group").unwrap()); - pub static form_name: Lazy = Lazy::new(|| Selector::parse(".il_InfoScreenProperty").unwrap()); - pub static cmd_node_regex: Lazy = Lazy::new(|| Regex::new(r#"cmdNode=uf:\w\w"#).unwrap()); - pub static image_src_regex: Lazy = Lazy::new(|| Regex::new(r#"\./data/produktiv/mobs/mm_(\d+)/([^?]+).+"#).unwrap()); - pub static XOCT_REGEX: Lazy = Lazy::new(|| Regex::new(r#"(?m)"#).unwrap()); - pub static il_content_container: Lazy = Lazy::new(|| Selector::parse("#il_center_col").unwrap()); - pub static item_prop: Lazy = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap()); - pub static container_items: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem").unwrap()); - pub static container_item_title: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle").unwrap()); -} -use crate::selectors::*; - -const NO_ENTRIES: &str = "Keine Einträge"; - async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { let relative_path = path.strip_prefix(&ilias.opt.output).unwrap(); if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { - PROGRESS_BAR.inc(1); let path = relative_path.display().to_string(); if !path.is_empty() { PROGRESS_BAR.set_message(path); @@ -284,447 +223,31 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { } match &obj { Course { url, name } => { - let content = if ilias.opt.content_tree { - let html = ilias.download(&url.url).await?.text().await?; - let cmd_node = cmd_node_regex.find(&html).context("can't find cmdNode")?.as_str()[8..].to_owned(); - let content_tree = ilias.get_course_content_tree(&url.ref_id, &cmd_node).await; - match content_tree { - Ok(tree) => (tree.into_iter().map(Result::Ok).collect(), None), - Err(e) => { - // some folders are hidden on the course page and can only be found via the RSS feed / recent activity / content tree sidebar - // TODO: this is probably never the case for folders? - if html.contains(r#"input[name="cmd[join]""#) { - return Ok(()); // ignore groups we are not in - } - warning!(name, "falling back to incomplete course content extractor!", e); - ilias.get_course_content(&url).await? // TODO: perhaps don't download almost the same content 3x - }, - } - } else { - ilias.get_course_content(&url).await? - }; - if let Some(s) = content.1.as_ref() { - let path = path.join("course.html"); - write_file_data(&path, &mut s.as_bytes()) - .await - .context("failed to write course page html")?; - } - for item in content.0 { - let item = item?; - let path = path.join(file_escape(item.name())); - let ilias = Arc::clone(&ilias); - spawn!(process_gracefully(ilias, path, item)); - } + ilias::course::download(path, ilias, url, name).await?; }, Folder { url, .. } | PersonalDesktop { url } => { - let content = ilias.get_course_content(&url).await?; - if let Some(s) = content.1.as_ref() { - let path = path.join("folder.html"); - write_file_data(&path, &mut s.as_bytes()) - .await - .context("failed to write folder page html")?; - } - for item in content.0 { - let item = item?; - let path = path.join(file_escape(item.name())); - let ilias = Arc::clone(&ilias); - spawn!(process_gracefully(ilias, path, item)); - } + ilias::folder::download(&path, ilias, url).await?; }, File { url, .. } => { - if ilias.opt.skip_files { - return Ok(()); - } - if !ilias.opt.force && fs::metadata(&path).await.is_ok() { - log!(2, "Skipping download, file exists already"); - return Ok(()); - } - let data = ilias.download(&url.url).await?; - let mut reader = StreamReader::new(data.bytes_stream().map_err(|x| io::Error::new(io::ErrorKind::Other, x))); - log!(0, "Writing {}", relative_path.to_string_lossy()); - write_file_data(&path, &mut reader).await?; + ilias::file::download(&path, relative_path, ilias, url).await?; }, PluginDispatch { url, .. } => { - if ilias.opt.no_videos { - return Ok(()); - } - let full_url = { - // first find the link to full video list - let list_url = format!("{}ilias.php?ref_id={}&cmdClass=xocteventgui&cmdNode=nc:n4:14u&baseClass=ilObjPluginDispatchGUI&lang=de&limit=20&cmd=asyncGetTableGUI&cmdMode=asynch", ILIAS_URL, url.ref_id); - log!(1, "Loading {}", list_url); - let data = ilias.download(&list_url).await?; - let html = data.text().await?; - let html = Html::parse_fragment(&html); - html.select(&LINKS) - .filter_map(|link| link.value().attr("href")) - .filter(|href| href.contains("trows=800")) - .map(|x| x.to_string()) - .next() - .context("video list link not found")? - }; - log!(1, "Rewriting {}", full_url); - let mut full_url = Url::parse(&format!("{}{}", ILIAS_URL, full_url))?; - let mut query_parameters = full_url.query_pairs().map(|(x, y)| (x.into_owned(), y.into_owned())).collect::>(); - for (key, value) in &mut query_parameters { - match key.as_ref() { - "cmd" => *value = "asyncGetTableGUI".into(), - "cmdClass" => *value = "xocteventgui".into(), - _ => {}, - } - } - query_parameters.push(("cmdMode".into(), "asynch".into())); - full_url.query_pairs_mut().clear().extend_pairs(&query_parameters).finish(); - log!(1, "Loading {}", full_url); - let data = ilias.download(full_url.as_str()).await?; - let html = data.text().await?; - let html = Html::parse_fragment(&html); - for row in html.select(&VIDEO_ROWS) { - let link = row.select(&a_target_blank).next(); - if link.is_none() { - if !row.text().any(|x| x == NO_ENTRIES) { - warning!(format => "table row without link in {}", url.url); - } - continue; - } - let link = link.unwrap(); - let mut cells = row.select(&td); - if let Some(title) = cells.nth(2) { - let title = title.text().collect::(); - let title = title.trim(); - if title.starts_with(" { - if ilias.opt.no_videos { - return Ok(()); - } - if fs::metadata(&path).await.is_ok() && !(ilias.opt.force || ilias.opt.check_videos) { - log!(2, "Skipping download, file exists already"); - return Ok(()); - } - let url = format!("{}{}", ILIAS_URL, url.url); - let data = ilias.download(&url); - let html = data.await?.text().await?; - log!(2, "{}", html); - let json: serde_json::Value = { - let mut json_capture = XOCT_REGEX.captures_iter(&html); - let json = &json_capture.next().context("xoct player json not found")?[1]; - log!(2, "{}", json); - let json = json.split(",\n").next().context("invalid xoct player json")?; - serde_json::from_str(&json.trim())? - }; - log!(2, "{}", json); - let url = json - .pointer("/streams/0/sources/mp4/0/src") - .context("video src not found")? - .as_str() - .context("video src not string")?; - let meta = fs::metadata(&path).await; - if !ilias.opt.force && meta.is_ok() && ilias.opt.check_videos { - let head = ilias.head(url).await.context("HEAD request failed")?; - if let Some(len) = head.headers().get("content-length") { - if meta?.len() != len.to_str()?.parse::()? { - warning!(relative_path.to_string_lossy(), "was updated, consider moving the outdated file"); - } - } - } else { - let resp = ilias.download(&url).await?; - let mut reader = StreamReader::new(resp.bytes_stream().map_err(|x| io::Error::new(io::ErrorKind::Other, x))); - log!(0, "Writing {}", relative_path.to_string_lossy()); - write_file_data(&path, &mut reader).await?; - } + ilias::video::download(&path, relative_path, ilias, url).await?; }, Forum { url, .. } => { - if !ilias.opt.forum { - return Ok(()); - } - let url = &url.url; - let html = { - let data = ilias.download(url); - let html_text = data.await?.text().await?; - let url = { - let html = Html::parse_document(&html_text); - let thread_count_selector = html.select(&LINKS).flat_map(|x| x.value().attr("href")).find(|x| x.contains("trows=800")); - if thread_count_selector.is_none() { - if let Some(cell) = html.select(&td).next() { - if cell.text().any(|x| x == NO_ENTRIES) { - return Ok(()); // empty forum - } - } - } - thread_count_selector - .context("can't find forum thread count selector (empty forum?)")? - .to_owned() - }; - let data = ilias.download(&url); - let html = data.await?.text().await?; - Html::parse_document(&html) - }; - for row in html.select(&tr) { - if row.value().attr("class") == Some("hidden-print") { - continue; // thread count - } - if row.select(&th).next().is_some() { - continue; // table header - } - let cells = row.select(&td).collect::>(); - if cells.len() != 6 { - warning!(format => - "Warning: {}{} {} {}", - "unusual table row (", cells.len(), "cells) in", url.to_string() - ); - continue; - } - let link = cells[1].select(&LINKS).next().context("thread link not found")?; - let object = Object::from_link(link, link)?; - let mut path = path.clone(); - let name = format!( - "{}_{}", - object.url().thr_pk.as_ref().context("thr_pk not found for thread")?, - link.text().collect::().trim() - ); - path.push(file_escape(&name)); - // TODO: set modification date? - let saved_posts = { - match std::fs::read_dir(&path) { - // TODO: make this async - Ok(stream) => stream.count(), - Err(_) => 0, - } - }; - let available_posts = cells[3] - .text() - .next() - .unwrap_or_default() - .trim() - .parse::() - .context("parsing post count failed")?; - if available_posts <= saved_posts && !ilias.opt.force { - continue; - } - let ilias = Arc::clone(&ilias); - spawn!(process_gracefully(ilias, path, object)); - } - if html.select(&forum_pages).count() > 0 { - log!(0, "Ignoring older threads in {:?}..", path); - } + ilias::forum::download(&path, ilias, url).await?; }, Thread { url } => { - if !ilias.opt.forum { - return Ok(()); - } - let mut all_images = Vec::new(); - let mut attachments = Vec::new(); - { - let html = ilias.get_html(&url.url).await?; - for post in html.select(&post_row) { - let title = post - .select(&post_title) - .next() - .context("post title not found")? - .text() - .collect::(); - let author = post.select(&span_small).next().context("post author not found")?; - let author = author.text().collect::(); - let author = author.trim().split('|').collect::>(); - let author = if author.len() == 2 { - author[0] // pseudonymous forum - } else if author.len() == 3 { - if author[1] != "Pseudonym" { - author[1] - } else { - author[0] - } - } else { - return Err(anyhow!("author data in unknown format")); - } - .trim(); - let container = post.select(&post_container).next().context("post container not found")?; - let link = container.select(&LINKS).next().context("post link not found")?; - let id = link.value().attr("id").context("no id in thread link")?.to_owned(); - let name = format!("{}_{}_{}.html", id, author, title.trim()); - let data = container.inner_html(); - let path = path.join(file_escape(&name)); - let relative_path = relative_path.join(file_escape(&name)); - spawn!(handle_gracefully(async move { - log!(0, "Writing {}", relative_path.display()); - write_file_data(&path, &mut data.as_bytes()).await.context("failed to write forum post") - })); - let images = container.select(&IMAGES).map(|x| x.value().attr("src").map(|x| x.to_owned())); - for image in images { - let image = image.context("no src on image")?; - all_images.push((id.clone(), image)); - } - if let Some(container) = container.select(&post_attachments).next() { - for attachment in container.select(&LINKS) { - attachments.push(( - id.clone(), - attachment.text().collect::(), - attachment.value().attr("href").map(|x| x.to_owned()), - )); - } - } - } - // pagination - if let Some(pages) = html.select(&TABLES).next() { - if let Some(last) = pages.select(&links_in_table).last() { - let text = last.text().collect::(); - if text.trim() == ">>" { - // not last page yet - let ilias = Arc::clone(&ilias); - let next_page = Thread { - url: URL::from_href(last.value().attr("href").context("page link not found")?)?, - }; - spawn!(process_gracefully(ilias, path.clone(), next_page)); - } - } else { - log!( - 0, - "Warning: {} {}", - "unable to find pagination links in".bright_yellow(), - url.url.to_string().bright_yellow() - ); - } - } - } - for (id, image) in all_images { - let src = URL::from_href(&image)?; - let dl = ilias.download(&src.url).await?; - let mut path = path.clone(); - if let Some(m) = image_src_regex.captures(&image) { - // image uploaded to ILIAS - let (media_id, filename) = (m.get(1).unwrap().as_str(), m.get(2).unwrap().as_str()); - path.push(file_escape(&format!("{}_{}_{}", id, media_id, filename))); - } else { - // external image - path.push(file_escape(&format!("{}_{}", id, image))); - } - spawn!(handle_gracefully(async move { - let bytes = dl.bytes().await?; - write_file_data(&path, &mut &*bytes) - .await - .context("failed to write forum post image attachment") - })); - } - for (id, name, url) in attachments { - let url = url.context("attachment without href")?; - let src = URL::from_href(&url)?; - let dl = ilias.download(&src.url).await?; - let mut path = path.clone(); - path.push(file_escape(&format!("{}_{}", id, name))); - spawn!(handle_gracefully(async move { - let bytes = dl.bytes().await?; - write_file_data(&path, &mut &*bytes) - .await - .context("failed to write forum post file attachment") - })); - } + ilias::thread::download(&path, relative_path, ilias, url).await?; }, ExerciseHandler { url, .. } => { - let html = ilias.get_html(&url.url).await?; - let mut filenames = HashSet::new(); - for row in html.select(&form_group) { - let link = row.select(&LINKS).next(); - if link.is_none() { - continue; - } - let link = link.unwrap(); - let href = link.value().attr("href"); - if href.is_none() { - continue; - } - let href = href.unwrap(); - let url = URL::from_href(href)?; - let cmd = url.cmd.as_deref().unwrap_or(""); - if cmd != "downloadFile" && cmd != "downloadGlobalFeedbackFile" && cmd != "downloadFeedbackFile" { - continue; - } - // link is definitely just a download link to the exercise or the solution - let name = row - .select(&form_name) - .next() - .context("link without file name")? - .text() - .collect::() - .trim() - .to_owned(); - let item = File { url, name }; - let mut path = path.clone(); - // handle files with the same name - let filename = file_escape(item.name()); - let mut parts = filename.rsplitn(2, '.'); - let extension = parts.next().unwrap_or(&filename); - let name = parts.next().unwrap_or(""); - let mut unique_filename = filename.clone(); - let mut i = 1; - while filenames.contains(&unique_filename) { - i += 1; - if name.is_empty() { - unique_filename = format!("{}{}", extension, i); - } else { - unique_filename = format!("{}{}.{}", name, i, extension); - } - } - filenames.insert(unique_filename.clone()); - path.push(unique_filename); - let ilias = Arc::clone(&ilias); - spawn!(process_gracefully(ilias, path, item)); - } + ilias::exercise::download(&path, ilias, url).await?; }, Weblink { url, .. } => { - if !ilias.opt.force && fs::metadata(&path).await.is_ok() { - log!(2, "Skipping download, link exists already"); - return Ok(()); - } - let head_req_result = ilias.head(&url.url).await; - let url = match &head_req_result { - Err(e) => e.url().context("HEAD request failed")?.as_str(), - Ok(head) => head.url().as_str(), - }; - if url.starts_with(ILIAS_URL) { - // is a link list - if fs::metadata(&path).await.is_err() { - create_dir(&path).await?; - log!(0, "Writing {}", relative_path.to_string_lossy()); - } - - let urls = { - let html = ilias.get_html(url).await?; - html.select(&LINKS) - .filter_map(|x| x.value().attr("href").map(|y| (y, x.text().collect::()))) - .map(|(x, y)| URL::from_href(x).map(|z| (z, y.trim().to_owned())).context("parsing weblink")) - .collect::>>() - }?; - - for (url, name) in urls { - if url.cmd.as_deref().unwrap_or("") != "callLink" { - continue; - } - - let head = ilias.head(url.url.as_str()).await.context("HEAD request to web link failed"); - if let Some(err) = head.as_ref().err() { - warning!(err); - continue; - } - let head = head.unwrap(); - let url = head.url().as_str(); - write_file_data(path.join(file_escape(&name)), &mut url.as_bytes()).await?; - } - } else { - log!(0, "Writing {}", relative_path.to_string_lossy()); - write_file_data(&path, &mut url.as_bytes()).await.context("failed to save weblink URL")?; - } + ilias::weblink::download(&path, relative_path, ilias, url).await?; }, Wiki { .. } => { log!(1, "Ignored wiki!"); @@ -733,11 +256,17 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { log!(1, "Ignored survey!"); }, Presentation { .. } => { - log!(1, "Ignored interactive presentation! (visit it yourself, it's probably interesting)"); + log!( + 1, + "Ignored interactive presentation! (visit it yourself, it's probably interesting)" + ); }, Generic { .. } => { log!(1, "Ignored generic {:?}", obj) }, } + if PROGRESS_BAR_ENABLED.load(Ordering::SeqCst) { + PROGRESS_BAR.inc(1); + } Ok(()) } diff --git a/src/queue.rs b/src/queue.rs new file mode 100644 index 0000000..50cd2ad --- /dev/null +++ b/src/queue.rs @@ -0,0 +1,50 @@ +use futures::Future; +use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender}; +use once_cell::sync::{Lazy, OnceCell}; +use tokio::{ + sync::{Semaphore, SemaphorePermit}, + task::{self, JoinHandle}, + time, +}; + +/// Global job queue +static TASKS: OnceCell>> = OnceCell::new(); +static TASKS_RUNNING: Lazy = Lazy::new(|| Semaphore::new(0)); +static REQUEST_TICKETS: Lazy = Lazy::new(|| Semaphore::new(0)); + +pub async fn get_request_ticket() { + REQUEST_TICKETS.acquire().await.unwrap().forget(); +} + +pub async fn get_ticket() -> SemaphorePermit<'static> { + TASKS_RUNNING.acquire().await.unwrap() +} + +pub fn spawn(e: impl Future + Send + 'static) { + TASKS.get().unwrap().unbounded_send(task::spawn(e)).unwrap(); +} + +pub fn set_download_rate(rate: usize) { + task::spawn(async move { + let mut interval = time::interval(time::Duration::from_secs_f64(60.0 / rate as f64)); + loop { + interval.tick().await; + log!( + 0, + "interval ticked @ {}", + std::time::SystemTime::now() + .duration_since(std::time::SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs() + ); + REQUEST_TICKETS.add_permits(1); + } + }); +} + +pub fn set_parallel_jobs(jobs: usize) -> UnboundedReceiver> { + let (tx, rx) = futures_channel::mpsc::unbounded::>(); + TASKS.get_or_init(|| tx.clone()); + TASKS_RUNNING.add_permits(jobs); + rx +} diff --git a/src/util.rs b/src/util.rs index 17f4082..4554aab 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,21 +1,38 @@ // SPDX-License-Identifier: GPL-3.0-or-later use anyhow::Context; +use bytes::Bytes; +use futures::TryStreamExt; use tokio::fs::File as AsyncFile; use tokio::io::{AsyncRead, BufWriter}; +use tokio_util::io::StreamReader; +use std::io; use std::path::Path; use crate::Result; +pub async fn write_stream_to_file( + path: &Path, + stream: impl futures::Stream> + Unpin, +) -> Result<()> { + let mut reader = StreamReader::new(stream.map_err(|x| io::Error::new(io::ErrorKind::Other, x))); + write_file_data(&path, &mut reader).await?; + Ok(()) +} + /// Write all data to the specified path. Will overwrite previous file data. pub async fn write_file_data(path: impl AsRef, data: &mut R) -> Result<()> where R: AsyncRead + Unpin, { - let file = AsyncFile::create(path.as_ref()).await.context("failed to create file")?; + let file = AsyncFile::create(path.as_ref()) + .await + .context("failed to create file")?; let mut file = BufWriter::new(file); - tokio::io::copy(data, &mut file).await.context("failed to write to file")?; + tokio::io::copy(data, &mut file) + .await + .context("failed to write to file")?; Ok(()) } From 1459ff5ae451c42001a86849a3dbdf586929044d Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 2 Jun 2021 11:53:50 +0200 Subject: [PATCH 067/103] Add missing await --- src/main.rs | 2 +- src/queue.rs | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 197e931..ca57d6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -188,7 +188,7 @@ fn process_gracefully(ilias: Arc, path: PathBuf, obj: Object) -> impl Fut PROGRESS_BAR.inc_length(1); } async move { - let permit = queue::get_ticket(); + let permit = queue::get_ticket().await; let path_text = path.to_string_lossy().into_owned(); if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") { error!("Syncing {}", path_text; e); diff --git a/src/queue.rs b/src/queue.rs index 50cd2ad..de9619a 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -29,14 +29,6 @@ pub fn set_download_rate(rate: usize) { let mut interval = time::interval(time::Duration::from_secs_f64(60.0 / rate as f64)); loop { interval.tick().await; - log!( - 0, - "interval ticked @ {}", - std::time::SystemTime::now() - .duration_since(std::time::SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs() - ); REQUEST_TICKETS.add_permits(1); } }); From 9c9885be78c0b2bab4fc5d6e1713ac88f0032232 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 2 Jun 2021 12:06:19 +0200 Subject: [PATCH 068/103] Switch to upstream keyring crate --- Cargo.lock | 3 ++- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22f2023..67e666b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -894,7 +894,8 @@ dependencies = [ [[package]] name = "keyring" version = "0.10.1" -source = "git+https://github.com/FliegendeWurst/keyring-rs?branch=application-name#292611fb9c64cb715d9a2e2b8f0f35edfeb7ea0a" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bcd64f48199f69993c705fd2f76882e53969db93bc6345021bc8bb6462a9ffa" dependencies = [ "byteorder", "secret-service", diff --git a/Cargo.toml b/Cargo.toml index 6df67db..56b187b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ rprompt = "1.0.5" ignore = "0.4.14" anyhow = "1.0.28" colored = "2.0.0" -keyring = { git = "https://github.com/FliegendeWurst/keyring-rs", branch = "application-name", optional = true } +keyring = { version = "0.10.1", optional = true } cfg-if = "1.0.0" indicatif = "0.16.0" once_cell = "1.7.2" From f59633fe0452a5699c0c723dc5845ab72c91a53c Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 2 Jun 2021 12:24:40 +0200 Subject: [PATCH 069/103] Version 0.2.22 --- CHANGELOG.md | 10 ++++++---- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5852800..0a53c7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project loosely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] + +## [0.2.22] - 2021-06-02 ### Added -- `--sync-url` can now download all courses (unless specified otherwise in the `.iliasignore`) +- `--sync-url` can now download more "personal desktop" pages - `--keep-session` flag to save and restore session cookies ## [0.2.21] - 2021-05-18 @@ -133,7 +134,8 @@ and this project loosely adheres to [Semantic Versioning](https://semver.org/spe [@Craeckie]: https://github.com/Craeckie [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 -[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.21...HEAD +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.22...HEAD +[0.2.22]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.21...v0.2.22 [0.2.21]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.20...v0.2.21 [0.2.20]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.19...v0.2.20 [0.2.19]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.18...v0.2.19 diff --git a/Cargo.lock b/Cargo.lock index 67e666b..318fd04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.21" +version = "0.2.22" dependencies = [ "anyhow", "atty", diff --git a/Cargo.toml b/Cargo.toml index 56b187b..6c2074c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.21" +version = "0.2.22" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-3.0-or-later" edition = "2018" From 75a22fd275eafb1e77e4b23f3aab22d6ad1b25ba Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Wed, 2 Jun 2021 12:30:14 +0200 Subject: [PATCH 070/103] Install from stable branch --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 725fdae..90d7384 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Download content from ILIAS. That includes: **Windows/Linux users**: go to the [releases](../../releases) and download the executable for your operating system. **macOS users**: [Install Rust](https://www.rust-lang.org/tools/install) and compile from source: ``` -$ cargo install --all-features --git 'https://github.com/FliegendeWurst/KIT-ILIAS-downloader' +$ cargo install --all-features --git 'https://github.com/FliegendeWurst/KIT-ILIAS-downloader' --branch stable ``` ## Usage @@ -36,7 +36,7 @@ $ KIT-ILIAS-downloader -o ./ILIAS/WS2021-HM1 --sync-url 'https://ilias.studium.k ``` $ KIT-ILIAS-downloader --help -KIT-ILIAS-downloader 0.2.21 +KIT-ILIAS-downloader 0.2.22 USAGE: KIT-ILIAS-downloader [FLAGS] [OPTIONS] --output @@ -47,6 +47,7 @@ FLAGS: -f Re-download already present files -t, --forum Download forum content -h, --help Prints help information + --keep-session Attempt to re-use session cookies --keyring Use the system keyring -n, --no-videos Do not download Opencast videos -s, --skip-files Do not download files From 4967e8afba792f70e33d47c16d69d5dca49b1688 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 4 Jun 2021 10:12:28 +0200 Subject: [PATCH 071/103] Specify link base in saved HTML pages --- src/ilias.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ilias.rs b/src/ilias.rs index ec497d9..f29131a 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -260,7 +260,10 @@ impl ILIAS { && el.inner_html().len() > 40 { // ^ minimum length of useful content? - Some(el.inner_html()) + // specify a base URL for relative links + let mut link_base = format!(r#""#, ILIAS_URL); + link_base += &el.inner_html(); + Some(link_base) } else { // first element is the content overview => no custom text (?) None From 1ff1f1417a0362f7a556fba84f61ec0080cf6c68 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 4 Jun 2021 10:13:33 +0200 Subject: [PATCH 072/103] build script: require up to date lock file --- build.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index c17f08b..8c4e3cb 100755 --- a/build.sh +++ b/build.sh @@ -1,10 +1,8 @@ #!/bin/sh rustup target add x86_64-unknown-linux-musl -cargo build --release --target x86_64-unknown-linux-musl -strip target/release/KIT-ILIAS-downloader +cargo build --locked --release --target x86_64-unknown-linux-musl rustup target add x86_64-pc-windows-gnu # if on Debian or similar sudo apt install mingw-w64 -cargo build --release --all-features --target x86_64-pc-windows-gnu -strip target/x86_64-pc-windows-gnu/release/KIT-ILIAS-downloader.exe +cargo build --locked --release --all-features --target x86_64-pc-windows-gnu From 1a95ad6f5900da458b73a20aa16c230a4d36fb46 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 7 Jun 2021 12:30:57 +0200 Subject: [PATCH 073/103] Always save page HTML --- src/ilias.rs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/ilias.rs b/src/ilias.rs index f29131a..8102ff7 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -251,23 +251,8 @@ impl ILIAS { let html = self.get_html(&url.url).await?; let main_text = if let Some(el) = html.select(&IL_CONTENT_CONTAINER).next() { - if !el - .children() - .flat_map(|x| x.value().as_element()) - .next() - .map(|x| x.attr("class").unwrap_or_default().contains("ilContainerBlock")) - .unwrap_or(false) - && el.inner_html().len() > 40 - { - // ^ minimum length of useful content? - // specify a base URL for relative links - let mut link_base = format!(r#""#, ILIAS_URL); - link_base += &el.inner_html(); - Some(link_base) - } else { - // first element is the content overview => no custom text (?) - None - } + // specify a base URL for relative links + Some(format!(r#"{}"#, ILIAS_URL, el.inner_html())) } else { None }; From e4015e723df28cb64e108fbce0a107824f73fd24 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 11 Jun 2021 15:01:09 +0200 Subject: [PATCH 074/103] Output saved attachments --- src/ilias/thread.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ilias/thread.rs b/src/ilias/thread.rs index 430a812..b09cd45 100644 --- a/src/ilias/thread.rs +++ b/src/ilias/thread.rs @@ -113,16 +113,19 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: let src = URL::from_href(&image)?; let dl = ilias.download(&src.url).await?; let mut path = path.to_owned(); - if let Some(m) = IMAGE_SRC_REGEX.captures(&image) { + let file_name = if let Some(m) = IMAGE_SRC_REGEX.captures(&image) { // image uploaded to ILIAS let (media_id, filename) = (m.get(1).unwrap().as_str(), m.get(2).unwrap().as_str()); - path.push(file_escape(&format!("{}_{}_{}", id, media_id, filename))); + file_escape(&format!("{}_{}_{}", id, media_id, filename)) } else { // external image - path.push(file_escape(&format!("{}_{}", id, image))); - } + file_escape(&format!("{}_{}", id, image)) + }; + path.push(&file_name); + let relative_path = relative_path.join(file_name); spawn(handle_gracefully(async move { let bytes = dl.bytes().await?; + log!(0, "Writing {}", relative_path.display()); write_file_data(&path, &mut &*bytes) .await .context("failed to write forum post image attachment") @@ -133,9 +136,12 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: let src = URL::from_href(&url)?; let dl = ilias.download(&src.url).await?; let mut path = path.to_owned(); - path.push(file_escape(&format!("{}_{}", id, name))); + let file_name = file_escape(&format!("{}_{}", id, name)); + path.push(&file_name); + let relative_path = relative_path.join(file_name); spawn(handle_gracefully(async move { let bytes = dl.bytes().await?; + log!(0, "Writing {}", relative_path.display()); write_file_data(&path, &mut &*bytes) .await .context("failed to write forum post file attachment") From d5cc512a7e8eddcd0de3e45df44f40dcdd0bb90a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 11 Jun 2021 15:06:16 +0200 Subject: [PATCH 075/103] Skip downloading zip of forum post attachments --- src/ilias/thread.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ilias/thread.rs b/src/ilias/thread.rs index b09cd45..bc48381 100644 --- a/src/ilias/thread.rs +++ b/src/ilias/thread.rs @@ -79,10 +79,15 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: } if let Some(container) = container.select(&POST_ATTACHMENTS).next() { for attachment in container.select(&LINKS) { + let href = attachment.value().attr("href").map(|x| x.to_owned()) + .context("attachment link without href")?; + if href.contains("cmd=deliverZipFile") { + continue; // skip downloading all attachments as zip + } attachments.push(( id.clone(), attachment.text().collect::(), - attachment.value().attr("href").map(|x| x.to_owned()), + href, )); } } @@ -132,7 +137,6 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: })); } for (id, name, url) in attachments { - let url = url.context("attachment without href")?; let src = URL::from_href(&url)?; let dl = ilias.download(&src.url).await?; let mut path = path.to_owned(); From b4861a5e3fe0ffea2d067d078a99d2a2923ca1a5 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 11 Jun 2021 15:20:47 +0200 Subject: [PATCH 076/103] Add doctype and base href to forum post HTML --- src/ilias.rs | 5 ++--- src/ilias/thread.rs | 15 +++++++-------- src/util.rs | 7 ++++++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/ilias.rs b/src/ilias.rs index 8102ff7..92993a5 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -11,7 +11,7 @@ use reqwest_cookie_store::CookieStoreMutex; use scraper::{ElementRef, Html, Selector}; use serde_json::json; -use crate::{cli::Opt, queue, ILIAS_URL}; +use crate::{cli::Opt, queue, util::wrap_html, ILIAS_URL}; pub mod course; pub mod exercise; @@ -251,8 +251,7 @@ impl ILIAS { let html = self.get_html(&url.url).await?; let main_text = if let Some(el) = html.select(&IL_CONTENT_CONTAINER).next() { - // specify a base URL for relative links - Some(format!(r#"{}"#, ILIAS_URL, el.inner_html())) + Some(wrap_html(&el.inner_html())) } else { None }; diff --git a/src/ilias/thread.rs b/src/ilias/thread.rs index bc48381..8e8988a 100644 --- a/src/ilias/thread.rs +++ b/src/ilias/thread.rs @@ -8,7 +8,7 @@ use scraper::Selector; use crate::{ handle_gracefully, process_gracefully, queue::spawn, - util::{file_escape, write_file_data}, + util::{file_escape, wrap_html, write_file_data}, }; use super::{Object, ILIAS, URL}; @@ -61,7 +61,7 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: let link = container.select(&LINKS).next().context("post link not found")?; let id = link.value().attr("id").context("no id in thread link")?.to_owned(); let name = format!("{}_{}_{}.html", id, author, title.trim()); - let data = container.inner_html(); + let data = wrap_html(&container.inner_html()); let path = path.join(file_escape(&name)); let relative_path = relative_path.join(file_escape(&name)); spawn(handle_gracefully(async move { @@ -79,16 +79,15 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: } if let Some(container) = container.select(&POST_ATTACHMENTS).next() { for attachment in container.select(&LINKS) { - let href = attachment.value().attr("href").map(|x| x.to_owned()) + let href = attachment + .value() + .attr("href") + .map(|x| x.to_owned()) .context("attachment link without href")?; if href.contains("cmd=deliverZipFile") { continue; // skip downloading all attachments as zip } - attachments.push(( - id.clone(), - attachment.text().collect::(), - href, - )); + attachments.push((id.clone(), attachment.text().collect::(), href)); } } } diff --git a/src/util.rs b/src/util.rs index 4554aab..7904af1 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,7 +10,12 @@ use tokio_util::io::StreamReader; use std::io; use std::path::Path; -use crate::Result; +use crate::{Result, ILIAS_URL}; + +/// Prepends a doctype and a base URL to the HTML fragment. +pub fn wrap_html(html_fragment: &str) -> String { + format!(r#"\n{}"#, ILIAS_URL, html_fragment) +} pub async fn write_stream_to_file( path: &Path, From cfd0e5d0828507e795ed86b969d1b8d005940940 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 11 Jun 2021 15:21:52 +0200 Subject: [PATCH 077/103] Update dependencies --- Cargo.lock | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 318fd04..1eac9ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,9 +90,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" +checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61" [[package]] name = "async-compression" @@ -696,9 +696,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] @@ -782,9 +782,9 @@ checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" [[package]] name = "hyper" -version = "0.14.8" +version = "0.14.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3f71a7eea53a3f8257a7b4795373ff886397178cd634430ea94e12d7fe4fe34" +checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83" dependencies = [ "bytes", "futures-channel", @@ -796,7 +796,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project", + "pin-project-lite", "socket2", "tokio", "tower-service", @@ -911,9 +911,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.95" +version = "0.2.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "5600b4e6efc5421841a2138a6b082e07fe12f9aaa12783d50e5d13325b26b4fc" [[package]] name = "log" @@ -1179,26 +1179,6 @@ dependencies = [ "siphasher", ] -[[package]] -name = "pin-project" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "pin-project-lite" version = "0.2.6" @@ -1829,9 +1809,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", @@ -2069,9 +2049,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33717dca7ac877f497014e10d73f3acf948c342bee31b5ca7892faf94ccc6b49" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" dependencies = [ "tinyvec", ] From ff5bdb8d7a0e7c68a0cd28020b50677de0033b52 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 14 Jun 2021 16:06:21 +0200 Subject: [PATCH 078/103] Version 0.2.23 --- CHANGELOG.md | 14 +++++++++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a53c7f..f0e2c20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## [0.2.23] - 2021-06-14 +### Added +- Logging output of saved forum post attachments + +### Changed +- ILIAS folder/course pages are now always saved + +### Fixed +- Links in saved ILIAS pages now work (see [``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base)) +- ZIP of multiple forum post attachments is no longer downloaded + ## [0.2.22] - 2021-06-02 ### Added - `--sync-url` can now download more "personal desktop" pages @@ -134,7 +145,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [@Craeckie]: https://github.com/Craeckie [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 -[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.22...HEAD +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.23...HEAD +[0.2.22]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.22...v0.2.23 [0.2.22]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.21...v0.2.22 [0.2.21]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.20...v0.2.21 [0.2.20]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.19...v0.2.20 diff --git a/Cargo.lock b/Cargo.lock index 1eac9ce..191d0fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.22" +version = "0.2.23" dependencies = [ "anyhow", "atty", diff --git a/Cargo.toml b/Cargo.toml index 6c2074c..40ab847 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.22" +version = "0.2.23" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-3.0-or-later" edition = "2018" diff --git a/README.md b/README.md index 90d7384..0ad339a 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ $ KIT-ILIAS-downloader -o ./ILIAS/WS2021-HM1 --sync-url 'https://ilias.studium.k ``` $ KIT-ILIAS-downloader --help -KIT-ILIAS-downloader 0.2.22 +KIT-ILIAS-downloader 0.2.23 USAGE: KIT-ILIAS-downloader [FLAGS] [OPTIONS] --output From 92f93117dda3e7ca997d5045c7f86e0c83aebe9c Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 14 Jun 2021 16:24:47 +0200 Subject: [PATCH 079/103] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0e2c20..01ad8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -146,7 +146,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 [Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.23...HEAD -[0.2.22]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.22...v0.2.23 +[0.2.23]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.22...v0.2.23 [0.2.22]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.21...v0.2.22 [0.2.21]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.20...v0.2.21 [0.2.20]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.19...v0.2.20 From 0a1c8696b49283f2225f9c2529e882e29958f608 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 28 Jun 2021 18:42:50 +0200 Subject: [PATCH 080/103] Typo fix --- src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 7904af1..57a06f4 100644 --- a/src/util.rs +++ b/src/util.rs @@ -14,7 +14,7 @@ use crate::{Result, ILIAS_URL}; /// Prepends a doctype and a base URL to the HTML fragment. pub fn wrap_html(html_fragment: &str) -> String { - format!(r#"\n{}"#, ILIAS_URL, html_fragment) + format!("\n{}", ILIAS_URL, html_fragment) } pub async fn write_stream_to_file( From 1e3a241baf74620c8a4f6f8be7aa60a11ee4c571 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 8 Jul 2021 19:42:14 +0200 Subject: [PATCH 081/103] Update dependencies --- Cargo.lock | 148 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 191d0fd..b7bb486 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -338,9 +338,9 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "cpufeatures" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" dependencies = [ "libc", ] @@ -412,13 +412,14 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.14" +version = "0.99.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320" +checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" dependencies = [ "convert_case", "proc-macro2", "quote", + "rustc_version 0.3.3", "syn", ] @@ -652,9 +653,9 @@ dependencies = [ [[package]] name = "globset" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" +checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" dependencies = [ "aho-corasick", "bstr", @@ -682,12 +683,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - [[package]] name = "hashbrown" version = "0.11.2" @@ -705,9 +700,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -782,9 +777,9 @@ checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" [[package]] name = "hyper" -version = "0.14.9" +version = "0.14.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83" +checksum = "7728a72c4c7d72665fde02204bcbd93b247721025b222ef78606f14513e0fd03" dependencies = [ "bytes", "futures-channel", @@ -832,9 +827,9 @@ dependencies = [ [[package]] name = "ignore" -version = "0.4.17" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b287fb45c60bb826a0dc68ff08742b9d88a2fea13d6e0c286b3172065aaf878c" +checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" dependencies = [ "crossbeam-utils", "globset", @@ -850,12 +845,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg", - "hashbrown 0.9.1", + "hashbrown", ] [[package]] @@ -872,9 +867,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" +checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" [[package]] name = "itoa" @@ -911,9 +906,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.96" +version = "0.2.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5600b4e6efc5421841a2138a6b082e07fe12f9aaa12783d50e5d13325b26b4fc" +checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" [[package]] name = "log" @@ -974,9 +969,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.11" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", "log", @@ -1109,9 +1104,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "opaque-debug" @@ -1125,6 +1120,15 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + [[package]] name = "phf" version = "0.8.0" @@ -1181,9 +1185,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -1271,7 +1275,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ac055aef7cc7a1caefbc65144be879e862467dcd9b8a8d57b64a13e7dce15d" dependencies = [ "byteorder", - "hashbrown 0.11.2", + "hashbrown", "idna", "psl-types", ] @@ -1355,9 +1359,9 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "reqwest" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" +checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" dependencies = [ "async-compression", "base64", @@ -1445,7 +1449,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", ] [[package]] @@ -1567,7 +1580,16 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser 0.10.2", ] [[package]] @@ -1576,6 +1598,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "serde" version = "1.0.126" @@ -1704,7 +1735,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" dependencies = [ "discard", - "rustc_version", + "rustc_version 0.2.3", "stdweb-derive", "stdweb-internal-macros", "stdweb-internal-runtime", @@ -1779,9 +1810,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.21" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +checksum = "69b041cdcb67226aca307e6e7be44c8806423d83e018bd662360a93dabce4d71" dependencies = [ "clap", "lazy_static", @@ -1790,9 +1821,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +checksum = "7813934aecf5f51a54775e00068c237de98489463968231a51746bbbc03f9c10" dependencies = [ "heck", "proc-macro-error", @@ -1856,18 +1887,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" +checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" +checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745" dependencies = [ "proc-macro2", "quote", @@ -1885,9 +1916,9 @@ dependencies = [ [[package]] name = "time" -version = "0.2.26" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08a8cbfbf47955132d0202d1662f49b2423ae35862aee471f3ba4b133358f372" +checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" dependencies = [ "const_fn", "libc", @@ -1910,9 +1941,9 @@ dependencies = [ [[package]] name = "time-macros-impl" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" +checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -1938,9 +1969,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.6.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975" +checksum = "98c8b05dc14c75ea83d63dd391100353789f5f24b8b3866542a5e85c8be8e985" dependencies = [ "autocfg", "bytes", @@ -1950,13 +1981,14 @@ dependencies = [ "num_cpus", "pin-project-lite", "tokio-macros", + "winapi", ] [[package]] name = "tokio-macros" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" +checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" dependencies = [ "proc-macro2", "quote", @@ -2038,6 +2070,12 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + [[package]] name = "unicode-bidi" version = "0.3.5" @@ -2058,9 +2096,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" From 2483ee19064d4ad6dad38db6584aeca4751f27c4 Mon Sep 17 00:00:00 2001 From: lukasprobst Date: Thu, 30 Sep 2021 16:58:42 +0200 Subject: [PATCH 082/103] Add an option to rename course names with a .toml file --- Cargo.lock | 133 ++++++++++++++++++-------------------------- Cargo.toml | 1 + src/ilias.rs | 9 ++- src/ilias/folder.rs | 2 +- src/main.rs | 28 +++++++--- 5 files changed, 82 insertions(+), 91 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7bb486..63eddfd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,6 +30,7 @@ dependencies = [ "structopt", "tokio", "tokio-util", + "toml", "url", ] @@ -338,9 +339,9 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "cpufeatures" -version = "0.1.5" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8" dependencies = [ "libc", ] @@ -412,14 +413,13 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.16" +version = "0.99.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" +checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320" dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.3.3", "syn", ] @@ -653,9 +653,9 @@ dependencies = [ [[package]] name = "globset" -version = "0.4.8" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" +checksum = "f0fc1b9fa0e64ffb1aa5b95daa0f0f167734fd528b7c02eabc581d9d843649b1" dependencies = [ "aho-corasick", "bstr", @@ -683,6 +683,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + [[package]] name = "hashbrown" version = "0.11.2" @@ -700,9 +706,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] @@ -777,9 +783,9 @@ checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" [[package]] name = "hyper" -version = "0.14.10" +version = "0.14.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7728a72c4c7d72665fde02204bcbd93b247721025b222ef78606f14513e0fd03" +checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83" dependencies = [ "bytes", "futures-channel", @@ -845,12 +851,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.7.0" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.9.1", ] [[package]] @@ -906,9 +912,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.98" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "log" @@ -1120,15 +1126,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - [[package]] name = "phf" version = "0.8.0" @@ -1185,9 +1182,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.7" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -1275,7 +1272,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ac055aef7cc7a1caefbc65144be879e862467dcd9b8a8d57b64a13e7dce15d" dependencies = [ "byteorder", - "hashbrown", + "hashbrown 0.11.2", "idna", "psl-types", ] @@ -1359,9 +1356,9 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "reqwest" -version = "0.11.4" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" +checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" dependencies = [ "async-compression", "base64", @@ -1449,16 +1446,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver 0.9.0", -] - -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", + "semver", ] [[package]] @@ -1580,16 +1568,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0", -] - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser 0.10.2", + "semver-parser", ] [[package]] @@ -1598,15 +1577,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" version = "1.0.126" @@ -1735,7 +1705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" dependencies = [ "discard", - "rustc_version 0.2.3", + "rustc_version", "stdweb-derive", "stdweb-internal-macros", "stdweb-internal-runtime", @@ -1810,9 +1780,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.22" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69b041cdcb67226aca307e6e7be44c8806423d83e018bd662360a93dabce4d71" +checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" dependencies = [ "clap", "lazy_static", @@ -1821,9 +1791,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.15" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7813934aecf5f51a54775e00068c237de98489463968231a51746bbbc03f9c10" +checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" dependencies = [ "heck", "proc-macro-error", @@ -1887,18 +1857,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.26" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2" +checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.26" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745" +checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" dependencies = [ "proc-macro2", "quote", @@ -1969,9 +1939,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.8.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c8b05dc14c75ea83d63dd391100353789f5f24b8b3866542a5e85c8be8e985" +checksum = "c79ba603c337335df6ba6dd6afc38c38a7d5e1b0c871678439ea973cd62a118e" dependencies = [ "autocfg", "bytes", @@ -1986,9 +1956,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.3.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" +checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" dependencies = [ "proc-macro2", "quote", @@ -2032,6 +2002,15 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + [[package]] name = "tower-service" version = "0.3.1" @@ -2070,12 +2049,6 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - [[package]] name = "unicode-bidi" version = "0.3.5" @@ -2096,9 +2069,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.8.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-width" diff --git a/Cargo.toml b/Cargo.toml index 40ab847..9673ffc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ h2 = "0.3.3" cookie_store = "0.14.0" reqwest_cookie_store = "0.1.5" bytes = "1.0.1" +toml = "0.5.8" [features] default = [] diff --git a/src/ilias.rs b/src/ilias.rs index 92993a5..88264e0 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later -use std::{error::Error as _, io::Write, sync::Arc}; +use std::{collections::HashMap, error::Error as _, io::Write, sync::Arc}; use anyhow::{anyhow, Context, Result}; use cookie_store::CookieStore; @@ -35,6 +35,7 @@ pub struct ILIAS { pub ignore: Gitignore, client: Client, cookies: Arc, + pub course_names: HashMap, } /// Returns true if the error is caused by: @@ -54,7 +55,7 @@ fn error_is_http2(error: &reqwest::Error) -> bool { impl ILIAS { // TODO: de-duplicate the logic below - pub async fn with_session(opt: Opt, session: Arc, ignore: Gitignore) -> Result { + pub async fn with_session(opt: Opt, session: Arc, ignore: Gitignore, course_names: HashMap) -> Result { let mut builder = Client::builder() .cookie_provider(Arc::clone(&session)) .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); @@ -71,10 +72,11 @@ impl ILIAS { ignore, client, cookies: session, + course_names, }) } - pub async fn login(opt: Opt, user: &str, pass: &str, ignore: Gitignore) -> Result { + pub async fn login(opt: Opt, user: &str, pass: &str, ignore: Gitignore, course_names: HashMap) -> Result { let cookie_store = CookieStore::default(); let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(cookie_store); let cookie_store = std::sync::Arc::new(cookie_store); @@ -93,6 +95,7 @@ impl ILIAS { ignore, client, cookies: cookie_store, + course_names, }; info!("Logging into ILIAS using KIT account.."); let session_establishment = this diff --git a/src/ilias/folder.rs b/src/ilias/folder.rs index 2948c18..9e96f94 100644 --- a/src/ilias/folder.rs +++ b/src/ilias/folder.rs @@ -20,7 +20,7 @@ pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { } for item in content.0 { let item = item?; - let path = path.join(file_escape(item.name())); + let path = path.join(file_escape(ilias.course_names.get(item.name()).map(|x| &**x).unwrap_or(item.name()))); let ilias = Arc::clone(&ilias); spawn(process_gracefully(ilias, path, item)); } diff --git a/src/main.rs b/src/main.rs index ca57d6b..35df4f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use indicatif::{ProgressDrawTarget, ProgressStyle}; use structopt::StructOpt; use tokio::fs; +use std::collections::HashMap; use std::future::Future; use std::io::BufReader; use std::path::PathBuf; @@ -38,7 +39,7 @@ async fn main() { } } -async fn try_to_load_session(opt: Opt, ignore: Gitignore) -> Result { +async fn try_to_load_session(opt: Opt, ignore: Gitignore, course_names: HashMap) -> Result { let session_path = opt.output.join(".iliassession"); let meta = tokio::fs::metadata(&session_path).await?; let modified = meta.modified()?; @@ -52,16 +53,16 @@ async fn try_to_load_session(opt: Opt, ignore: Gitignore) -> Result { .context("failed to load session cookies")?; let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(cookies); let cookie_store = std::sync::Arc::new(cookie_store); - Ok(ILIAS::with_session(opt, cookie_store, ignore).await?) + Ok(ILIAS::with_session(opt, cookie_store, ignore, course_names).await?) } else { Err(anyhow!("session data too old")) } } -async fn login(opt: Opt, ignore: Gitignore) -> Result { +async fn login(opt: Opt, ignore: Gitignore, course_names: HashMap) -> Result { // load .iliassession file if opt.keep_session { - match try_to_load_session(opt.clone(), ignore.clone()) + match try_to_load_session(opt.clone(), ignore.clone(), course_names.clone()) .await .context("failed to load previous session") { @@ -79,7 +80,7 @@ async fn login(opt: Opt, ignore: Gitignore) -> Result { } } - // loac .iliaslogin file + // load .iliaslogin file let iliaslogin = opt.output.join(".iliaslogin"); let login = std::fs::read_to_string(&iliaslogin); let (user, pass) = if let Ok(login) = login { @@ -93,7 +94,7 @@ async fn login(opt: Opt, ignore: Gitignore) -> Result { ask_user_pass(&opt).context("credentials input failed")? }; - let ilias = match ILIAS::login(opt, &user, &pass, ignore).await { + let ilias = match ILIAS::login(opt, &user, &pass, ignore, course_names).await { Ok(ilias) => ilias, Err(e) => { error!(e); @@ -118,13 +119,26 @@ async fn real_main(mut opt: Opt) -> Result<()> { // load .iliasignore file let (ignore, error) = Gitignore::new(opt.output.join(".iliasignore")); + + // Load course_names.toml file + let course_names_path = opt.output.join("course_names.toml"); + let course_names: HashMap; + + if fs::metadata(&course_names_path).await.is_ok() { + fs::read_to_string(&course_names_path).await.context("reading course_names.toml")?; + course_names = toml::from_str(&fs::read_to_string(course_names_path).await?).unwrap(); + } else { + // If file doesn't exist, initialise course_names with empty HashMap + course_names = HashMap::new(); + } + if let Some(err) = error { warning!(err); } queue::set_download_rate(opt.rate); - let ilias = login(opt, ignore).await?; + let ilias = login(opt, ignore, course_names).await?; if ilias.opt.content_tree { if let Err(e) = ilias From 7cb8ca65fcc8312ae51ce32909cbe39446516a68 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 1 Oct 2021 09:16:46 +0200 Subject: [PATCH 083/103] Revert dependency downgrades --- Cargo.lock | 346 +++++++++++++++++++++++++++++------------------------ 1 file changed, 190 insertions(+), 156 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 63eddfd..8f2af5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -91,9 +91,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.41" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61" +checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" [[package]] name = "async-compression" @@ -139,9 +139,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" @@ -170,18 +170,18 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "bstr" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "memchr", ] [[package]] name = "bumpalo" -version = "3.7.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" +checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" [[package]] name = "byteorder" @@ -191,15 +191,15 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cc" -version = "1.0.68" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" +checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" [[package]] name = "cfg-if" @@ -280,9 +280,9 @@ dependencies = [ [[package]] name = "cookie" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf8865bac3d9a3bde5bde9088ca431b11f5d37c7a578b8086af77248b76627" +checksum = "d5f1c7727e460397e56abc4bddc1d49e07a1ad78fc98eb2e1c8f032a58a2f80d" dependencies = [ "percent-encoding", "time", @@ -311,10 +311,10 @@ version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ba4e410d33a326cee69c778c761b6a822469ed7c6b82aa7802bef6e12716060" dependencies = [ - "cookie 0.15.0", + "cookie 0.15.1", "idna", "log", - "publicsuffix 2.1.0", + "publicsuffix 2.1.1", "serde", "serde_json", "time", @@ -339,9 +339,9 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "cpufeatures" -version = "0.1.4" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" dependencies = [ "libc", ] @@ -367,9 +367,9 @@ dependencies = [ [[package]] name = "crypto-mac" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" +checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a" dependencies = [ "generic-array", "subtle", @@ -413,13 +413,14 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.14" +version = "0.99.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320" +checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" dependencies = [ "convert_case", "proc-macro2", "quote", + "rustc_version 0.3.3", "syn", ] @@ -482,9 +483,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" +checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" dependencies = [ "cfg-if", "crc32fast", @@ -520,9 +521,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" +checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" dependencies = [ "futures-channel", "futures-core", @@ -535,9 +536,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" dependencies = [ "futures-core", "futures-sink", @@ -545,15 +546,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" [[package]] name = "futures-executor" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" +checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" dependencies = [ "futures-core", "futures-task", @@ -562,15 +563,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" [[package]] name = "futures-macro" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" +checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" dependencies = [ "autocfg", "proc-macro-hack", @@ -581,21 +582,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" [[package]] name = "futures-task" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" [[package]] name = "futures-util" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" dependencies = [ "autocfg", "futures-channel", @@ -653,9 +654,9 @@ dependencies = [ [[package]] name = "globset" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0fc1b9fa0e64ffb1aa5b95daa0f0f167734fd528b7c02eabc581d9d843649b1" +checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" dependencies = [ "aho-corasick", "bstr", @@ -666,9 +667,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.3" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" +checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964" dependencies = [ "bytes", "fnv", @@ -683,12 +684,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - [[package]] name = "hashbrown" version = "0.11.2" @@ -706,9 +701,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -749,9 +744,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" dependencies = [ "bytes", "fnv", @@ -760,9 +755,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" dependencies = [ "bytes", "http", @@ -771,9 +766,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.4.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" [[package]] name = "httpdate" @@ -783,9 +778,9 @@ checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" [[package]] name = "hyper" -version = "0.14.9" +version = "0.14.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83" +checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" dependencies = [ "bytes", "futures-channel", @@ -851,12 +846,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg", - "hashbrown 0.9.1", + "hashbrown", ] [[package]] @@ -879,15 +874,15 @@ checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" [[package]] name = "itoa" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "js-sys" -version = "0.3.51" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" dependencies = [ "wasm-bindgen", ] @@ -912,9 +907,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.97" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" [[package]] name = "log" @@ -947,15 +942,15 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "memchr" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "mime" @@ -1032,9 +1027,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d0a3d5e207573f948a9e5376662aa743a2ea13f7c50a554d7af443a73fbfeba" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" dependencies = [ "autocfg", "num-integer", @@ -1126,6 +1121,15 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + [[package]] name = "phf" version = "0.8.0" @@ -1182,9 +1186,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -1242,9 +1246,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.27" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" dependencies = [ "unicode-xid", ] @@ -1267,12 +1271,12 @@ dependencies = [ [[package]] name = "publicsuffix" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3ac055aef7cc7a1caefbc65144be879e862467dcd9b8a8d57b64a13e7dce15d" +checksum = "292972edad6bbecc137ab84c5e36421a4a6c979ea31d3cc73540dd04315b33e1" dependencies = [ "byteorder", - "hashbrown 0.11.2", + "hashbrown", "idna", "psl-types", ] @@ -1356,9 +1360,9 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "reqwest" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" +checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" dependencies = [ "async-compression", "base64", @@ -1403,7 +1407,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a81253b4f49eba884e5b555d08617d2b59be9478fcb53875ded9825d957af4a" dependencies = [ "bytes", - "cookie 0.15.0", + "cookie 0.15.1", "cookie_store 0.14.1", "reqwest", "url", @@ -1446,7 +1450,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", ] [[package]] @@ -1568,7 +1581,16 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser 0.10.2", ] [[package]] @@ -1578,19 +1600,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] -name = "serde" -version = "1.0.126" +name = "semver-parser" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.126" +version = "1.0.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" dependencies = [ "proc-macro2", "quote", @@ -1599,9 +1630,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.64" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" dependencies = [ "itoa", "ryu", @@ -1638,9 +1669,9 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" [[package]] name = "sha2" -version = "0.9.5" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" +checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer", "cfg-if", @@ -1651,27 +1682,27 @@ dependencies = [ [[package]] name = "siphasher" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbce6d4507c7e4a3962091436e56e95290cb71fa302d0d270e32130b75fbff27" +checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b" [[package]] name = "slab" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" +checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" [[package]] name = "smallvec" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "socket2" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" dependencies = [ "libc", "winapi", @@ -1705,7 +1736,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" dependencies = [ "discard", - "rustc_version", + "rustc_version 0.2.3", "stdweb-derive", "stdweb-internal-macros", "stdweb-internal-runtime", @@ -1780,9 +1811,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa" dependencies = [ "clap", "lazy_static", @@ -1791,9 +1822,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.14" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba" dependencies = [ "heck", "proc-macro-error", @@ -1804,15 +1835,15 @@ dependencies = [ [[package]] name = "subtle" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.73" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" +checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0" dependencies = [ "proc-macro2", "quote", @@ -1857,18 +1888,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.25" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" +checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.25" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" +checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c" dependencies = [ "proc-macro2", "quote", @@ -1924,9 +1955,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.2.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" dependencies = [ "tinyvec_macros", ] @@ -1939,9 +1970,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.7.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79ba603c337335df6ba6dd6afc38c38a7d5e1b0c871678439ea973cd62a118e" +checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" dependencies = [ "autocfg", "bytes", @@ -1956,9 +1987,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" +checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb" dependencies = [ "proc-macro2", "quote", @@ -1990,9 +2021,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" +checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" dependencies = [ "bytes", "futures-core", @@ -2019,9 +2050,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.26" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" +checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" dependencies = [ "cfg-if", "pin-project-lite", @@ -2030,9 +2061,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.18" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" +checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf" dependencies = [ "lazy_static", ] @@ -2045,18 +2076,21 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" +checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "unicode-bidi" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" -dependencies = [ - "matches", -] +checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" [[package]] name = "unicode-normalization" @@ -2069,15 +2103,15 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" @@ -2150,9 +2184,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ "cfg-if", "serde", @@ -2162,9 +2196,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" dependencies = [ "bumpalo", "lazy_static", @@ -2177,9 +2211,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.24" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fba7978c679d53ce2d0ac80c8c175840feb849a161664365d1287b41f2e67f1" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" dependencies = [ "cfg-if", "js-sys", @@ -2189,9 +2223,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2199,9 +2233,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ "proc-macro2", "quote", @@ -2212,15 +2246,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" [[package]] name = "web-sys" -version = "0.3.51" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" dependencies = [ "js-sys", "wasm-bindgen", From bcf3c3f9efdf1b1cb7a64ee7067ffae51b4eec6d Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 1 Oct 2021 09:19:53 +0200 Subject: [PATCH 084/103] Minor code style improvements --- src/main.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 35df4f2..f79fa2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,15 +122,13 @@ async fn real_main(mut opt: Opt) -> Result<()> { // Load course_names.toml file let course_names_path = opt.output.join("course_names.toml"); - let course_names: HashMap; - - if fs::metadata(&course_names_path).await.is_ok() { - fs::read_to_string(&course_names_path).await.context("reading course_names.toml")?; - course_names = toml::from_str(&fs::read_to_string(course_names_path).await?).unwrap(); + let course_names = if fs::metadata(&course_names_path).await.is_ok() { + // file exists, try to read it + toml::from_str(&fs::read_to_string(course_names_path).await.context("accessing course_names.toml")?).context("processing course_names.toml")? } else { // If file doesn't exist, initialise course_names with empty HashMap - course_names = HashMap::new(); - } + HashMap::new() + }; if let Some(err) = error { warning!(err); From 2d596f8e08eda84fd7da37d33597ed08c3d8be11 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 1 Oct 2021 10:41:22 +0200 Subject: [PATCH 085/103] Document new course renaming feature --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 0ad339a..b2913c3 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,13 @@ username password ``` +### Renaming course names (0.2.24+) +If you'd like to avoid unwieldy course names (e.g. "24030 – Programmierparadigmen"), you can create a `course_names.toml` file in the output directory. It should contain the desired mapping of course names to folder names, e.g.: +``` +"24030 – Programmierparadigmen" = "Propa" +"Numerische Mathematik für die Fachrichtungen Informatik und Ingenieurwesen" = "Numerik" +``` + ## Similar programs - https://github.com/brantsch/kit-ilias-fuse/ From 1c41c957737bb83aad8f8b4507e80299e6fd3567 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 1 Nov 2021 17:36:25 +0100 Subject: [PATCH 086/103] Download/combine multiple video streams (fix #24) --- Cargo.lock | 123 +++++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 3 +- src/cli.rs | 4 ++ src/ilias/video.rs | 75 ++++++++++++++++++++++++--- 4 files changed, 186 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f2af5c..21d7e04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,7 @@ dependencies = [ "scraper", "serde_json", "structopt", + "tempfile", "tokio", "tokio-util", "toml", @@ -649,7 +650,18 @@ checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -1158,7 +1170,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" dependencies = [ "phf_shared", - "rand", + "rand 0.7.3", ] [[package]] @@ -1296,14 +1308,26 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", "libc", - "rand_chacha", - "rand_core", - "rand_hc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", "rand_pcg", ] +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.3", + "rand_hc 0.3.1", +] + [[package]] name = "rand_chacha" version = "0.2.2" @@ -1311,7 +1335,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.3", ] [[package]] @@ -1320,7 +1354,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom 0.2.3", ] [[package]] @@ -1329,7 +1372,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core 0.6.3", ] [[package]] @@ -1338,7 +1390,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" dependencies = [ - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", ] [[package]] @@ -1358,6 +1419,15 @@ version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + [[package]] name = "reqwest" version = "0.11.4" @@ -1528,7 +1598,7 @@ dependencies = [ "hkdf", "lazy_static", "num", - "rand", + "rand 0.7.3", "sha2", ] @@ -1680,6 +1750,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + [[package]] name = "siphasher" version = "0.3.7" @@ -1850,6 +1929,20 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if", + "libc", + "rand 0.8.4", + "redox_syscall", + "remove_dir_all", + "winapi", +] + [[package]] name = "tendril" version = "0.4.2" @@ -1980,7 +2073,9 @@ dependencies = [ "memchr", "mio", "num_cpus", + "once_cell", "pin-project-lite", + "signal-hook-registry", "tokio-macros", "winapi", ] @@ -2182,6 +2277,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "wasm-bindgen" version = "0.2.78" diff --git a/Cargo.toml b/Cargo.toml index 9673ffc..6fb97bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] reqwest = { version = "0.11.0", default-features = false, features = ["cookies", "gzip", "json", "rustls-tls", "stream", "socks"] } -tokio = { version = "1.0.2", features = ["fs", "macros", "net", "rt-multi-thread"] } +tokio = { version = "1.0.2", features = ["fs", "macros", "net", "rt-multi-thread", "process"] } tokio-util = { version = "0.6.1", features = ["io"] } serde_json = "1.0.51" scraper = "0.12.0" @@ -34,6 +34,7 @@ cookie_store = "0.14.0" reqwest_cookie_store = "0.1.5" bytes = "1.0.1" toml = "0.5.8" +tempfile = "3.2.0" [features] default = [] diff --git a/src/cli.rs b/src/cli.rs index faf4f5a..3d43518 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -37,6 +37,10 @@ pub struct Opt { #[structopt(long)] pub check_videos: bool, + /// Combine videos if there is more than one stream (requires ffmpeg) + #[structopt(long)] + pub combine_videos: bool, + /// Verbose logging #[structopt(short, multiple = true, parse(from_occurrences))] pub verbose: usize, diff --git a/src/ilias/video.rs b/src/ilias/video.rs index e322544..12bd4b5 100644 --- a/src/ilias/video.rs +++ b/src/ilias/video.rs @@ -1,9 +1,10 @@ -use std::{path::Path, sync::Arc}; +use std::{path::{Path, PathBuf}, process::{ExitStatus, Stdio}, sync::Arc}; use anyhow::{Context, Result}; use once_cell::sync::Lazy; use regex::Regex; -use tokio::fs; +use tempfile::tempdir; +use tokio::{fs, process::Command}; use crate::{util::write_stream_to_file, ILIAS_URL}; @@ -32,11 +33,71 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: serde_json::from_str(&json.trim())? }; log!(2, "{}", json); - let url = json - .pointer("/streams/0/sources/mp4/0/src") - .context("video src not found")? - .as_str() - .context("video src not string")?; + let streams = json + .get("streams") + .context("video streams not found")? + .as_array() + .context("video streams not an array")?; + if streams.len() == 1 { + let url = streams[0] + .pointer("/sources/mp4/0/src") + .context("video src not found")? + .as_str() + .context("video src not string")?; + download_to_path(&ilias, path, relative_path, url).await?; + } else { + if !ilias.opt.combine_videos { + fs::create_dir(path).await.context("failed to create video directory")?; + download_all(path, streams, ilias, relative_path).await?; + } else { + let dir = tempdir()?; + // construct ffmpeg command to combine all files + let mut arguments = vec![]; + for file in download_all(dir.path(), streams, ilias, relative_path).await? { + arguments.push("-i".to_owned()); + arguments.push(file.to_str().context("invalid UTF8")?.into()); + } + arguments.push("-c".into()); + arguments.push("copy".into()); + for i in 0..(arguments.len() / 2)-1 { + arguments.push("-map".into()); + arguments.push(format!("{}", i)); + } + arguments.push(path.to_str().context("invalid UTF8 in path")?.into()); + let status = Command::new("ffmpeg") + .args(&arguments) + .stderr(Stdio::null()) + .stdout(Stdio::null()) + .spawn() + .context("failed to start ffmpeg")? + .wait().await + .context("failed to wait for ffmpeg")?; + if !status.success() { + error!(format!("ffmpeg failed to merge video files into {}", path.display())); + error!(format!("check this directory: {}", dir.into_path().display())); + error!(format!("ffmpeg command: {}", arguments.join(" "))); + } + }; + } + Ok(()) +} + +async fn download_all(path: &Path, streams: &Vec, ilias: Arc, relative_path: &Path) -> Result> { + let mut paths = Vec::new(); + for (i, stream) in streams.into_iter().enumerate() { + let url = stream + .pointer("/sources/mp4/0/src") + .context("video src not found")? + .as_str() + .context("video src not string")?; + let new_path = path.join(format!("Stream{}.mp4", i + 1)); + download_to_path(&ilias, &new_path, &relative_path.join(format!("Stream{}.mp4", i + 1)), url).await?; + paths.push(new_path); + } + Ok(paths) +} + +async fn download_to_path(ilias: &ILIAS, path: &Path, relative_path: &Path, url: &str) -> Result<()> { let meta = fs::metadata(&path).await; if !ilias.opt.force && meta.is_ok() && ilias.opt.check_videos { let head = ilias.head(url).await.context("HEAD request failed")?; From 3e0a2bf154837f3a9da07dad4cd5209d6b77f04a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 1 Nov 2021 17:40:11 +0100 Subject: [PATCH 087/103] Add option to save ILIAS pages (fix #22) --- src/cli.rs | 4 ++++ src/ilias/course.rs | 12 +++++++----- src/ilias/folder.rs | 12 +++++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 3d43518..11821c5 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -41,6 +41,10 @@ pub struct Opt { #[structopt(long)] pub combine_videos: bool, + /// Save overview pages of ILIAS courses and folders + #[structopt(long)] + pub save_ilias_pages: bool, + /// Verbose logging #[structopt(short, multiple = true, parse(from_occurrences))] pub verbose: usize, diff --git a/src/ilias/course.rs b/src/ilias/course.rs index 211b365..03d2298 100644 --- a/src/ilias/course.rs +++ b/src/ilias/course.rs @@ -34,11 +34,13 @@ pub async fn download(path: PathBuf, ilias: Arc, url: &URL, name: &str) - } else { ilias.get_course_content(&url).await? }; - if let Some(s) = content.1.as_ref() { - let path = path.join("course.html"); - write_file_data(&path, &mut s.as_bytes()) - .await - .context("failed to write course page html")?; + if ilias.opt.save_ilias_pages { + if let Some(s) = content.1.as_ref() { + let path = path.join("course.html"); + write_file_data(&path, &mut s.as_bytes()) + .await + .context("failed to write course page html")?; + } } for item in content.0 { let item = item?; diff --git a/src/ilias/folder.rs b/src/ilias/folder.rs index 9e96f94..3f2e9f2 100644 --- a/src/ilias/folder.rs +++ b/src/ilias/folder.rs @@ -12,11 +12,13 @@ use super::{ILIAS, URL}; pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { let content = ilias.get_course_content(&url).await?; - if let Some(s) = content.1.as_ref() { - let path = path.join("folder.html"); - write_file_data(&path, &mut s.as_bytes()) - .await - .context("failed to write folder page html")?; + if ilias.opt.save_ilias_pages { + if let Some(s) = content.1.as_ref() { + let path = path.join("folder.html"); + write_file_data(&path, &mut s.as_bytes()) + .await + .context("failed to write folder page html")?; + } } for item in content.0 { let item = item?; From a6c0e97755f7dfb5141162fee2d58e19af530eb7 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 1 Nov 2021 17:43:37 +0100 Subject: [PATCH 088/103] Don't create folders for ignored items (fix #21) --- src/ilias.rs | 21 +++++++++++++++++++-- src/ilias/folder.rs | 4 +++- src/ilias/video.rs | 26 +++++++++++++++++++++----- src/main.rs | 12 ++++++++++-- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/ilias.rs b/src/ilias.rs index 88264e0..0d4eb47 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -55,7 +55,12 @@ fn error_is_http2(error: &reqwest::Error) -> bool { impl ILIAS { // TODO: de-duplicate the logic below - pub async fn with_session(opt: Opt, session: Arc, ignore: Gitignore, course_names: HashMap) -> Result { + pub async fn with_session( + opt: Opt, + session: Arc, + ignore: Gitignore, + course_names: HashMap, + ) -> Result { let mut builder = Client::builder() .cookie_provider(Arc::clone(&session)) .user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"))); @@ -76,7 +81,13 @@ impl ILIAS { }) } - pub async fn login(opt: Opt, user: &str, pass: &str, ignore: Gitignore, course_names: HashMap) -> Result { + pub async fn login( + opt: Opt, + user: &str, + pass: &str, + ignore: Gitignore, + course_names: HashMap, + ) -> Result { let cookie_store = CookieStore::default(); let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(cookie_store); let cookie_store = std::sync::Arc::new(cookie_store); @@ -464,6 +475,12 @@ impl Object { _ => Generic { name, url }, }) } + + pub(crate) fn is_ignored_by_option(&self, opt: &Opt) -> bool { + (matches!(self, Object::Forum { .. }) && !opt.forum) + || (matches!(self, Object::Video { .. }) && opt.no_videos) + || (matches!(self, Object::File { .. }) && opt.skip_files) + } } #[allow(non_snake_case)] diff --git a/src/ilias/folder.rs b/src/ilias/folder.rs index 3f2e9f2..962192a 100644 --- a/src/ilias/folder.rs +++ b/src/ilias/folder.rs @@ -22,7 +22,9 @@ pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { } for item in content.0 { let item = item?; - let path = path.join(file_escape(ilias.course_names.get(item.name()).map(|x| &**x).unwrap_or(item.name()))); + let path = path.join(file_escape( + ilias.course_names.get(item.name()).map(|x| &**x).unwrap_or(item.name()), + )); let ilias = Arc::clone(&ilias); spawn(process_gracefully(ilias, path, item)); } diff --git a/src/ilias/video.rs b/src/ilias/video.rs index 12bd4b5..ca604a1 100644 --- a/src/ilias/video.rs +++ b/src/ilias/video.rs @@ -1,4 +1,8 @@ -use std::{path::{Path, PathBuf}, process::{ExitStatus, Stdio}, sync::Arc}; +use std::{ + path::{Path, PathBuf}, + process::{ExitStatus, Stdio}, + sync::Arc, +}; use anyhow::{Context, Result}; use once_cell::sync::Lazy; @@ -59,7 +63,7 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: } arguments.push("-c".into()); arguments.push("copy".into()); - for i in 0..(arguments.len() / 2)-1 { + for i in 0..(arguments.len() / 2) - 1 { arguments.push("-map".into()); arguments.push(format!("{}", i)); } @@ -70,7 +74,8 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: .stdout(Stdio::null()) .spawn() .context("failed to start ffmpeg")? - .wait().await + .wait() + .await .context("failed to wait for ffmpeg")?; if !status.success() { error!(format!("ffmpeg failed to merge video files into {}", path.display())); @@ -82,7 +87,12 @@ pub async fn download(path: &Path, relative_path: &Path, ilias: Arc, url: Ok(()) } -async fn download_all(path: &Path, streams: &Vec, ilias: Arc, relative_path: &Path) -> Result> { +async fn download_all( + path: &Path, + streams: &Vec, + ilias: Arc, + relative_path: &Path, +) -> Result> { let mut paths = Vec::new(); for (i, stream) in streams.into_iter().enumerate() { let url = stream @@ -91,7 +101,13 @@ async fn download_all(path: &Path, streams: &Vec, ilias: Arc< .as_str() .context("video src not string")?; let new_path = path.join(format!("Stream{}.mp4", i + 1)); - download_to_path(&ilias, &new_path, &relative_path.join(format!("Stream{}.mp4", i + 1)), url).await?; + download_to_path( + &ilias, + &new_path, + &relative_path.join(format!("Stream{}.mp4", i + 1)), + url, + ) + .await?; paths.push(new_path); } Ok(paths) diff --git a/src/main.rs b/src/main.rs index f79fa2b..262d57b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,12 +124,17 @@ async fn real_main(mut opt: Opt) -> Result<()> { let course_names_path = opt.output.join("course_names.toml"); let course_names = if fs::metadata(&course_names_path).await.is_ok() { // file exists, try to read it - toml::from_str(&fs::read_to_string(course_names_path).await.context("accessing course_names.toml")?).context("processing course_names.toml")? + toml::from_str( + &fs::read_to_string(course_names_path) + .await + .context("accessing course_names.toml")?, + ) + .context("processing course_names.toml")? } else { // If file doesn't exist, initialise course_names with empty HashMap HashMap::new() }; - + if let Some(err) = error { warning!(err); } @@ -230,6 +235,9 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { } log!(1, "Syncing {} {}", obj.kind(), relative_path.to_string_lossy()); log!(2, " URL: {}", obj.url().url); + if obj.is_ignored_by_option(&ilias.opt) { + return Ok(()); + } if obj.is_dir() { create_dir(&path).await?; } From e207eb3f06d8d48afcbeb27a7621d4ac9a7af8c0 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 1 Nov 2021 17:46:12 +0100 Subject: [PATCH 089/103] Version 0.2.24 --- CHANGELOG.md | 11 ++++++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- src/ilias/video.rs | 2 +- src/main.rs | 4 ++-- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01ad8c4..21dd360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## [0.2.24] - 2021-11-01 +### Added +- `--combine-videos` option to merge multiple video streams of the same lecture +- `--save-ilias-pages` option to also save the ILIAS overview pages of courses/folders + +### Fixed +- Downloading of lectures that consist of multiple streams + ## [0.2.23] - 2021-06-14 ### Added - Logging output of saved forum post attachments @@ -145,7 +153,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [@Craeckie]: https://github.com/Craeckie [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 -[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.23...HEAD +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.24...HEAD +[0.2.23]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.23...v0.2.24 [0.2.23]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.22...v0.2.23 [0.2.22]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.21...v0.2.22 [0.2.21]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.20...v0.2.21 diff --git a/Cargo.lock b/Cargo.lock index 21d7e04..1a5949e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.23" +version = "0.2.24" dependencies = [ "anyhow", "atty", diff --git a/Cargo.toml b/Cargo.toml index 6fb97bd..39ee808 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.23" +version = "0.2.24" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-3.0-or-later" edition = "2018" diff --git a/src/ilias/video.rs b/src/ilias/video.rs index ca604a1..2437ddc 100644 --- a/src/ilias/video.rs +++ b/src/ilias/video.rs @@ -1,6 +1,6 @@ use std::{ path::{Path, PathBuf}, - process::{ExitStatus, Stdio}, + process::Stdio, sync::Arc, }; diff --git a/src/main.rs b/src/main.rs index 262d57b..1504428 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,7 +70,7 @@ async fn login(opt: Opt, ignore: Gitignore, course_names: HashMap Result<()> { while let Either::Left((task, _)) = future::select(rx.next(), future::ready(())).await { if let Some(task) = task { if let Err(e) = task.await { - error!(e) + error!(e); } } else { break; // channel is empty => all tasks are completed From ed82d357ed4634fba772cf90d65a28afe89d02c9 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 1 Nov 2021 17:56:11 +0100 Subject: [PATCH 090/103] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21dd360..c03cb84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - `--combine-videos` option to merge multiple video streams of the same lecture - `--save-ilias-pages` option to also save the ILIAS overview pages of courses/folders +- Configuration file to change course names (PR [#19] by [@thelukasprobst]) ### Fixed - Downloading of lectures that consist of multiple streams @@ -136,6 +137,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.1.0] - 2020-04-21 (undocumented) +[#19]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/19 [#15]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/15 [#14]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/14 [#13]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/13 From 6f8eb5000073ad2821bc3825ea0a67ca5b11dbbf Mon Sep 17 00:00:00 2001 From: lukasprobst Date: Sun, 7 Nov 2021 00:08:32 +0100 Subject: [PATCH 091/103] Update README --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b2913c3..7bc4850 100644 --- a/README.md +++ b/README.md @@ -36,23 +36,25 @@ $ KIT-ILIAS-downloader -o ./ILIAS/WS2021-HM1 --sync-url 'https://ilias.studium.k ``` $ KIT-ILIAS-downloader --help -KIT-ILIAS-downloader 0.2.23 +KIT-ILIAS-downloader 0.2.24 USAGE: KIT-ILIAS-downloader [FLAGS] [OPTIONS] --output FLAGS: - --check-videos Re-check OpenCast lectures (slow) - --content-tree Use content tree (experimental) - -f Re-download already present files - -t, --forum Download forum content - -h, --help Prints help information - --keep-session Attempt to re-use session cookies - --keyring Use the system keyring - -n, --no-videos Do not download Opencast videos - -s, --skip-files Do not download files - -V, --version Prints version information - -v Verbose logging + --check-videos Re-check OpenCast lectures (slow) + --combine-videos Combine videos if there is more than one stream (requires ffmpeg) + --content-tree Use content tree (experimental) + -f Re-download already present files + -t, --forum Download forum content + -h, --help Prints help information + --keep-session Attempt to re-use session cookies + --keyring Use the system keyring + -n, --no-videos Do not download Opencast videos + --save-ilias-pages Save overview pages of ILIAS courses and folders + -s, --skip-files Do not download files + -V, --version Prints version information + -v Verbose logging OPTIONS: -j, --jobs Parallel download jobs [default: 1] @@ -93,7 +95,7 @@ password ### Renaming course names (0.2.24+) If you'd like to avoid unwieldy course names (e.g. "24030 – Programmierparadigmen"), you can create a `course_names.toml` file in the output directory. It should contain the desired mapping of course names to folder names, e.g.: ``` -"24030 – Programmierparadigmen" = "Propa" +"24030 – Programmierparadigmen" = "ProPa" "Numerische Mathematik für die Fachrichtungen Informatik und Ingenieurwesen" = "Numerik" ``` From 6dd16deb40b866faba031b916950213eef512827 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 15:37:57 +0100 Subject: [PATCH 092/103] Replace personal desktop with dashboard downloader ILIAS 7 update, see #27 --- src/ilias.rs | 20 +++++++++++++------- src/main.rs | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ilias.rs b/src/ilias.rs index 0d4eb47..d7df898 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -26,6 +26,7 @@ pub mod weblink; static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); static ALERT_DANGER: Lazy = Lazy::new(|| Selector::parse("div.alert-danger").unwrap()); static IL_CONTENT_CONTAINER: Lazy = Lazy::new(|| Selector::parse("#il_center_col").unwrap()); +static BLOCK_FAVORITES: Lazy = Lazy::new(|| Selector::parse("#block_pditems_0").unwrap()); static ITEM_PROP: Lazy = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap()); static CONTAINER_ITEMS: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem").unwrap()); static CONTAINER_ITEM_TITLE: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle").unwrap()); @@ -265,7 +266,12 @@ impl ILIAS { let html = self.get_html(&url.url).await?; let main_text = if let Some(el) = html.select(&IL_CONTENT_CONTAINER).next() { - Some(wrap_html(&el.inner_html())) + // if we are currently extracting the dashboard, only select the favorites + if let Some(el) = el.select(&BLOCK_FAVORITES).next() { + Some(wrap_html(&el.inner_html())) + } else { + Some(wrap_html(&el.inner_html())) + } } else { None }; @@ -298,7 +304,7 @@ trait IliasObject { pub enum Object { Course { name: String, url: URL }, Folder { name: String, url: URL }, - PersonalDesktop { url: URL }, + Dashboard { url: URL }, File { name: String, url: URL }, Forum { name: String, url: URL }, Thread { url: URL }, @@ -330,7 +336,7 @@ impl Object { | Generic { name, .. } => &name, Thread { url } => &url.thr_pk.as_ref().unwrap(), Video { url } => &url.url, - PersonalDesktop { .. } => panic!("name of personal desktop requested (this should never happen)"), + Dashboard { url } => &url.url } } @@ -338,7 +344,7 @@ impl Object { match self { Course { url, .. } | Folder { url, .. } - | PersonalDesktop { url } + | Dashboard { url } | File { url, .. } | Forum { url, .. } | Thread { url } @@ -357,7 +363,7 @@ impl Object { match self { Course { .. } => "course", Folder { .. } => "folder", - PersonalDesktop { .. } => "personal desktop", + Dashboard { .. } => "dashboard", File { .. } => "file", Forum { .. } => "forum", Thread { .. } => "thread", @@ -376,7 +382,7 @@ impl Object { matches!( self, Course { .. } - | Folder { .. } | PersonalDesktop { .. } + | Folder { .. } | Dashboard { .. } | Forum { .. } | Thread { .. } | Wiki { .. } | ExerciseHandler { .. } | PluginDispatch { .. } @@ -471,7 +477,7 @@ impl Object { None => Course { name, url }, }, "ilobjplugindispatchgui" => PluginDispatch { name, url }, - "ilpersonaldesktopgui" => PersonalDesktop { url }, + "ildashboardgui" => Dashboard { url }, _ => Generic { name, url }, }) } diff --git a/src/main.rs b/src/main.rs index 1504428..3ebc493 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ use std::time::SystemTime; static ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; /// main personal desktop static DEFAULT_SYNC_URL: &str = - "https://ilias.studium.kit.edu/ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems"; + "https://ilias.studium.kit.edu/ilias.php?baseClass=ilDashboardGUI&cmd=jumpToMemberships"; #[macro_use] mod cli; @@ -245,7 +245,7 @@ async fn process(ilias: Arc, path: PathBuf, obj: Object) -> Result<()> { Course { url, name } => { ilias::course::download(path, ilias, url, name).await?; }, - Folder { url, .. } | PersonalDesktop { url } => { + Folder { url, .. } | Dashboard { url } => { ilias::folder::download(&path, ilias, url).await?; }, File { url, .. } => { From bd9a777bb95861fc7d7000428d253cab49cbc51e Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 15:49:54 +0100 Subject: [PATCH 093/103] Fix video downloading (ILIAS 7 update) see #27 --- src/ilias/plugin_dispatch.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ilias/plugin_dispatch.rs b/src/ilias/plugin_dispatch.rs index f5bdaa2..23fc45e 100644 --- a/src/ilias/plugin_dispatch.rs +++ b/src/ilias/plugin_dispatch.rs @@ -2,6 +2,7 @@ use std::{path::Path, sync::Arc}; use anyhow::{Context, Result}; use once_cell::sync::Lazy; +use regex::Regex; use reqwest::Url; use scraper::{Html, Selector}; @@ -13,6 +14,7 @@ static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); static A_TARGET_BLANK: Lazy = Lazy::new(|| Selector::parse(r#"a[target="_blank"]"#).unwrap()); static VIDEO_ROWS: Lazy = Lazy::new(|| Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap()); static TABLE_CELLS: Lazy = Lazy::new(|| Selector::parse("td").unwrap()); +static LIST_URL: Lazy = Lazy::new(|| Regex::new("ilias\\.php\\?ref_id=\\d+&cmdClass=xocteventgui&cmdNode=.{8}q&baseClass=ilObjPluginDispatchGUI&lang=.{2}&limit=20&cmd=asyncGetTableGUI&cmdMode=asynch").unwrap()); const NO_ENTRIES: &str = "Keine Einträge"; @@ -21,10 +23,13 @@ pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { return Ok(()); } let full_url = { + let html = ilias.download(&url.url).await?.text().await?; + let list_url = LIST_URL.find(&html).context("failed to find xoct event link")?.as_str(); + let full_list_url = format!("{}{}", ILIAS_URL, list_url); + // first find the link to full video list - let list_url = format!("{}ilias.php?ref_id={}&cmdClass=xocteventgui&cmdNode=nc:n4:14u&baseClass=ilObjPluginDispatchGUI&lang=de&limit=20&cmd=asyncGetTableGUI&cmdMode=asynch", ILIAS_URL, url.ref_id); - log!(1, "Loading {}", list_url); - let data = ilias.download(&list_url).await?; + log!(1, "Loading {}", full_list_url); + let data = ilias.download(&full_list_url).await?; let html = data.text().await?; let html = Html::parse_fragment(&html); html.select(&LINKS) From 126f8500e431bbe44c7461c8dd96eb951f6e143b Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 15:57:50 +0100 Subject: [PATCH 094/103] Make keyring support non-optional Now that the dbus library isn't needed.. --- Cargo.lock | 772 +++++++++++++++++++++++++++++++++++------------------ Cargo.toml | 12 +- src/cli.rs | 49 ++-- 3 files changed, 527 insertions(+), 306 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a5949e..1e63117 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,14 +4,14 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.2.24" +version = "0.3.0" dependencies = [ "anyhow", "atty", "bytes", - "cfg-if", + "cfg-if 1.0.0", "colored", - "cookie_store 0.14.1", + "cookie_store", "futures", "futures-channel", "futures-util", @@ -83,18 +83,18 @@ dependencies = [ [[package]] name = "ansi_term" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ "winapi", ] [[package]] name = "anyhow" -version = "1.0.44" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" +checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3" [[package]] name = "async-compression" @@ -109,6 +109,25 @@ dependencies = [ "tokio", ] +[[package]] +name = "async-io" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" +dependencies = [ + "concurrent-queue", + "futures-lite", + "libc", + "log", + "once_cell", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "winapi", +] + [[package]] name = "atty" version = "0.2.14" @@ -180,9 +199,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.7.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" +checksum = "fe438c9d2f2b0fb88a112154ed81e30b0a491c29322afe1db3b6eec5811f5ba0" [[package]] name = "byteorder" @@ -197,10 +216,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] -name = "cc" -version = "1.0.70" +name = "cache-padded" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + +[[package]] +name = "cc" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" @@ -219,9 +250,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.3" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "ansi_term", "atty", @@ -244,23 +275,32 @@ dependencies = [ ] [[package]] -name = "console" -version = "0.14.1" +name = "concurrent-queue" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + +[[package]] +name = "console" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31" dependencies = [ "encode_unicode", - "lazy_static", "libc", + "once_cell", "terminal_size", "winapi", ] [[package]] name = "const_fn" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" +checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" [[package]] name = "convert_case" @@ -268,17 +308,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "cookie" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" -dependencies = [ - "percent-encoding", - "time", - "version_check", -] - [[package]] name = "cookie" version = "0.15.1" @@ -292,30 +321,14 @@ dependencies = [ [[package]] name = "cookie_store" -version = "0.12.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3818dfca4b0cb5211a659bbcbb94225b7127407b2b135e650d717bfb78ab10d3" +checksum = "b3f7034c0932dc36f5bd8ec37368d971346809435824f277cb3b8299fc56167c" dependencies = [ - "cookie 0.14.4", + "cookie", "idna", "log", - "publicsuffix 1.5.6", - "serde", - "serde_json", - "time", - "url", -] - -[[package]] -name = "cookie_store" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba4e410d33a326cee69c778c761b6a822469ed7c6b82aa7802bef6e12716060" -dependencies = [ - "cookie 0.15.1", - "idna", - "log", - "publicsuffix 2.1.1", + "publicsuffix", "serde", "serde_json", "time", @@ -324,9 +337,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.7.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" dependencies = [ "core-foundation-sys", "libc", @@ -334,9 +347,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.7.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" @@ -349,11 +362,11 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -362,7 +375,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "lazy_static", ] @@ -384,7 +397,7 @@ checksum = "754b69d351cdc2d8ee09ae203db831e005560fc6030da058f86ad60c92a9cb0a" dependencies = [ "cssparser-macros", "dtoa-short", - "itoa", + "itoa 0.4.8", "matches", "phf", "proc-macro2", @@ -404,24 +417,26 @@ dependencies = [ ] [[package]] -name = "dbus" -version = "0.2.3" +name = "derivative" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4a0c10ea61042b7555729ab0608727bbbb06ce709c11e6047cfa4e10f6d052d" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "libc", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "derive_more" -version = "0.99.16" +version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.3.3", + "rustc_version 0.4.0", "syn", ] @@ -475,11 +490,41 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "encoding_rs" -version = "0.8.28" +version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", +] + +[[package]] +name = "enumflags2" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83c8d82922337cd23a15f88b70d8e4ef5f11da38dd7cdb55e84dd5de99695da0" +dependencies = [ + "enumflags2_derive", + "serde", +] + +[[package]] +name = "enumflags2_derive" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "946ee94e3dbf58fdd324f9ce245c7b238d46a66f00e86a020b71996349e46cce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "fastrand" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "779d043b6a0b90cc4c0ed7ee380a6504394cee7efd7db050e3774eee387324b2" +dependencies = [ + "instant", ] [[package]] @@ -488,7 +533,7 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crc32fast", "libc", "miniz_oxide", @@ -522,9 +567,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" +checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4" dependencies = [ "futures-channel", "futures-core", @@ -537,9 +582,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" dependencies = [ "futures-core", "futures-sink", @@ -547,15 +592,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" +checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" [[package]] name = "futures-executor" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" +checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" dependencies = [ "futures-core", "futures-task", @@ -564,18 +609,31 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" +checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" + +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] [[package]] name = "futures-macro" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" dependencies = [ - "autocfg", - "proc-macro-hack", "proc-macro2", "quote", "syn", @@ -583,23 +641,22 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" +checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" [[package]] name = "futures-task" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" +checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" [[package]] name = "futures-util" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" dependencies = [ - "autocfg", "futures-channel", "futures-core", "futures-io", @@ -609,8 +666,6 @@ dependencies = [ "memchr", "pin-project-lite", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] @@ -625,9 +680,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.4" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" dependencies = [ "typenum", "version_check", @@ -648,7 +703,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -659,7 +714,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi 0.10.2+wasi-snapshot-preview1", ] @@ -679,9 +734,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.6" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964" +checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd" dependencies = [ "bytes", "fnv", @@ -756,20 +811,20 @@ dependencies = [ [[package]] name = "http" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" dependencies = [ "bytes", "fnv", - "itoa", + "itoa 1.0.1", ] [[package]] name = "http-body" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" dependencies = [ "bytes", "http", @@ -784,15 +839,15 @@ checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" [[package]] name = "httpdate" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.13" +version = "0.14.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" dependencies = [ "bytes", "futures-channel", @@ -803,7 +858,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa", + "itoa 0.4.8", "pin-project-lite", "socket2", "tokio", @@ -814,17 +869,15 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.22.1" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" +checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac" dependencies = [ - "futures-util", + "http", "hyper", - "log", "rustls", "tokio", "tokio-rustls", - "webpki", ] [[package]] @@ -878,6 +931,15 @@ dependencies = [ "regex", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "ipnet" version = "2.3.1" @@ -890,6 +952,12 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + [[package]] name = "js-sys" version = "0.3.55" @@ -901,9 +969,9 @@ dependencies = [ [[package]] name = "keyring" -version = "0.10.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bcd64f48199f69993c705fd2f76882e53969db93bc6345021bc8bb6462a9ffa" +checksum = "4dadaf714ce3f9d7e1c8c05aa8d070eb6e9ddd40cd7be3aca2f21fa372405104" dependencies = [ "byteorder", "secret-service", @@ -919,9 +987,18 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.103" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" + +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] [[package]] name = "log" @@ -929,7 +1006,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -982,9 +1059,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" dependencies = [ "libc", "log", @@ -1002,12 +1079,35 @@ dependencies = [ "winapi", ] +[[package]] +name = "nb-connect" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1bb540dc6ef51cfe1916ec038ce7a620daf3a111e2502d745197cd53d6bca15" +dependencies = [ + "libc", + "socket2", +] + [[package]] name = "new_debug_unreachable" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "nix" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" +dependencies = [ + "bitflags", + "cc", + "cfg-if 0.1.10", + "libc", + "void", +] + [[package]] name = "nodrop" version = "0.1.14" @@ -1101,9 +1201,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ "hermit-abi", "libc", @@ -1117,9 +1217,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "opaque-debug" @@ -1127,21 +1227,43 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + [[package]] name = "percent-encoding" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - [[package]] name = "phf" version = "0.8.0" @@ -1198,9 +1320,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" [[package]] name = "pin-utils" @@ -1209,10 +1331,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "ppv-lite86" -version = "0.2.10" +name = "polling" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "log", + "wepoll-ffi", + "winapi", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "precomputed-hash" @@ -1220,6 +1355,25 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + +[[package]] +name = "proc-macro-crate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +dependencies = [ + "thiserror", + "toml", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -1250,36 +1404,20 @@ version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" -version = "1.0.29" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ "unicode-xid", ] [[package]] name = "psl-types" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66b398073e7cdd6f05934389a8f5961e3aabfa66675b6f440df4e2c793d51a4f" - -[[package]] -name = "publicsuffix" -version = "1.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b4ce31ff0a27d93c8de1849cf58162283752f065a90d508f1105fa6c9a213f" -dependencies = [ - "idna", - "url", -] +checksum = "e8eda7c62d9ecaafdf8b62374c006de0adf61666ae96a96ba74a37134aa4e470" [[package]] name = "publicsuffix" @@ -1295,9 +1433,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.9" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" dependencies = [ "proc-macro2", ] @@ -1430,15 +1568,15 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.4" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" +checksum = "7c4e0a76dc12a116108933f6301b95e83634e0c47b0afbed6abbaa0601e99258" dependencies = [ "async-compression", "base64", "bytes", - "cookie 0.14.4", - "cookie_store 0.12.0", + "cookie", + "cookie_store", "encoding_rs", "futures-core", "futures-util", @@ -1453,11 +1591,12 @@ dependencies = [ "mime", "percent-encoding", "pin-project-lite", + "proc-macro-hack", "rustls", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", - "time", "tokio", "tokio-rustls", "tokio-socks", @@ -1472,13 +1611,13 @@ dependencies = [ [[package]] name = "reqwest_cookie_store" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a81253b4f49eba884e5b555d08617d2b59be9478fcb53875ded9825d957af4a" +checksum = "48cbf3a2aeeeaa6d10a76db86068c3560320f6265c3a0e2642e0538e11c2d143" dependencies = [ "bytes", - "cookie 0.15.1", - "cookie_store 0.14.1", + "cookie", + "cookie_store", "reqwest", "url", ] @@ -1525,20 +1664,19 @@ dependencies = [ [[package]] name = "rustc_version" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 0.11.0", + "semver 1.0.4", ] [[package]] name = "rustls" -version = "0.19.1" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84" dependencies = [ - "base64", "log", "ring", "sct", @@ -1546,10 +1684,19 @@ dependencies = [ ] [[package]] -name = "ryu" -version = "1.0.5" +name = "rustls-pemfile" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" +dependencies = [ + "base64", +] + +[[package]] +name = "ryu" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] name = "same-file" @@ -1560,6 +1707,18 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "scraper" version = "0.12.0" @@ -1578,9 +1737,9 @@ dependencies = [ [[package]] name = "sct" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" dependencies = [ "ring", "untrusted", @@ -1588,25 +1747,29 @@ dependencies = [ [[package]] name = "secret-service" -version = "1.1.3" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d752040301c251d653aa740dec847e95767ce312cfc469bee85eb13cbf81d8a" +checksum = "2400fb1bf2a87b303ada204946294f932ade4929477e9e2bf66d7b49a66656ec" dependencies = [ "aes", "block-modes", - "dbus", "hkdf", "lazy_static", "num", - "rand 0.7.3", + "rand 0.8.4", + "serde", "sha2", + "zbus", + "zbus_macros", + "zvariant", + "zvariant_derive", ] [[package]] name = "security-framework" -version = "0.4.4" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" +checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" dependencies = [ "bitflags", "core-foundation", @@ -1617,9 +1780,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "0.4.3" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" +checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" dependencies = [ "core-foundation-sys", "libc", @@ -1651,17 +1814,14 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0", + "semver-parser", ] [[package]] name = "semver" -version = "0.11.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser 0.10.2", -] +checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" [[package]] name = "semver-parser" @@ -1669,29 +1829,20 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" dependencies = [ "proc-macro2", "quote", @@ -1700,15 +1851,26 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.68" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ - "itoa", + "itoa 1.0.1", "ryu", "serde", ] +[[package]] +name = "serde_repr" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98d0516900518c29efa217c298fa1f4e6c6ffc85ae29fd7f4ee48f176e1a9ed5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_urlencoded" version = "0.7.0" @@ -1716,7 +1878,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" dependencies = [ "form_urlencoded", - "itoa", + "itoa 0.4.8", "ryu", "serde", ] @@ -1744,7 +1906,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer", - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest", "opaque-debug", @@ -1767,9 +1929,9 @@ checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b" [[package]] name = "slab" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" [[package]] name = "smallvec" @@ -1808,6 +1970,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "stdweb" version = "0.4.20" @@ -1859,12 +2027,13 @@ checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" [[package]] name = "string_cache" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ddb1139b5353f96e429e1a5e19fbaf663bddedaa06d1dbd49f82e352601209a" +checksum = "923f0f39b6267d37d23ce71ae7235602134b250ace715dd2c90421998ddac0c6" dependencies = [ "lazy_static", "new_debug_unreachable", + "parking_lot", "phf_shared", "precomputed-hash", "serde", @@ -1890,9 +2059,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.23" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa" +checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" dependencies = [ "clap", "lazy_static", @@ -1901,9 +2070,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.16" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck", "proc-macro-error", @@ -1920,9 +2089,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.77" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" dependencies = [ "proc-macro2", "quote", @@ -1935,7 +2104,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "rand 0.8.4", "redox_syscall", @@ -1981,18 +2150,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ "proc-macro2", "quote", @@ -2048,9 +2217,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" dependencies = [ "tinyvec_macros", ] @@ -2063,11 +2232,10 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.12.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" +checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838" dependencies = [ - "autocfg", "bytes", "libc", "memchr", @@ -2082,9 +2250,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.4.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ "proc-macro2", "quote", @@ -2093,9 +2261,9 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.22.0" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" +checksum = "a27d5f2b839802bd8267fa19b0530f5a08b9c08cd417976be2a65d130fe1c11b" dependencies = [ "rustls", "tokio", @@ -2116,9 +2284,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" +checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" dependencies = [ "bytes", "futures-core", @@ -2145,20 +2313,20 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" dependencies = [ "lazy_static", ] @@ -2171,21 +2339,15 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" - -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-bidi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" [[package]] name = "unicode-normalization" @@ -2246,9 +2408,21 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" [[package]] name = "walkdir" @@ -2289,9 +2463,7 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ - "cfg-if", - "serde", - "serde_json", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] @@ -2316,7 +2488,7 @@ version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -2363,9 +2535,9 @@ dependencies = [ [[package]] name = "webpki" -version = "0.21.4" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" dependencies = [ "ring", "untrusted", @@ -2373,13 +2545,22 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.21.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" +checksum = "552ceb903e957524388c4d3475725ff2c8b7960922063af6ce53c9a43da07449" dependencies = [ "webpki", ] +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2419,3 +2600,64 @@ checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ "winapi", ] + +[[package]] +name = "zbus" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2326acc379a3ac4e34b794089f5bdb17086bf29a5fdf619b7b4cc772dc2e9dad" +dependencies = [ + "async-io", + "byteorder", + "derivative", + "enumflags2", + "fastrand", + "futures", + "nb-connect", + "nix", + "once_cell", + "polling", + "scoped-tls", + "serde", + "serde_repr", + "zbus_macros", + "zvariant", +] + +[[package]] +name = "zbus_macros" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a482c56029e48681b89b92b5db3c446db0915e8dd1052c0328a574eda38d5f93" +dependencies = [ + "proc-macro-crate 0.1.5", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zvariant" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68c7b55f2074489b7e8e07d2d0a6ee6b4f233867a653c664d8020ba53692525" +dependencies = [ + "byteorder", + "enumflags2", + "libc", + "serde", + "static_assertions", + "zvariant_derive", +] + +[[package]] +name = "zvariant_derive" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ca5e22593eb4212382d60d26350065bf2a02c34b85bc850474a74b589a3de9" +dependencies = [ + "proc-macro-crate 1.1.0", + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 39ee808..a1c2f34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.2.24" +version = "0.3.0" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-3.0-or-later" edition = "2018" @@ -24,18 +24,14 @@ rprompt = "1.0.5" ignore = "0.4.14" anyhow = "1.0.28" colored = "2.0.0" -keyring = { version = "0.10.1", optional = true } +keyring = "1.0.0" cfg-if = "1.0.0" indicatif = "0.16.0" once_cell = "1.7.2" atty = "0.2.14" h2 = "0.3.3" -cookie_store = "0.14.0" -reqwest_cookie_store = "0.1.5" +cookie_store = "0.15.1" +reqwest_cookie_store = "0.2.0" bytes = "1.0.1" toml = "0.5.8" tempfile = "3.2.0" - -[features] -default = [] -keyring-auth = ["keyring"] diff --git a/src/cli.rs b/src/cli.rs index 11821c5..ed6e282 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,7 +3,6 @@ use std::path::PathBuf; use std::sync::atomic::{AtomicBool, AtomicUsize}; -#[cfg(feature = "keyring-auth")] use anyhow::anyhow; use anyhow::{Context, Result}; use indicatif::ProgressBar; @@ -63,7 +62,6 @@ pub struct Opt { /// Use the system keyring #[structopt(long)] - #[cfg(feature = "keyring-auth")] pub keyring: bool, /// KIT account username @@ -151,42 +149,27 @@ pub fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { } else { rprompt::prompt_reply_stdout("Username: ").context("username prompt")? }; - #[cfg(feature = "keyring-auth")] let (pass, should_store); - #[cfg(feature = "keyring-auth")] - let keyring = Lazy::new(|| keyring::Keyring::new(env!("CARGO_PKG_NAME"), &user)); - #[cfg(not(feature = "keyring-auth"))] - let pass; - cfg_if::cfg_if! { // TODO: deduplicate the logic below - if #[cfg(feature = "keyring-auth")] { - if let Some(password) = opt.password.as_ref() { - pass = password.clone(); - should_store = true; - } else if opt.keyring { - match keyring.get_password() { - Ok(password) => { - pass = password; - should_store = false; - }, - Err(e) => { - error!(e); - pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; - should_store = true; - } - } - } else { + let keyring = Lazy::new(|| keyring::Entry::new(env!("CARGO_PKG_NAME"), &user)); + if let Some(password) = opt.password.as_ref() { + pass = password.clone(); + should_store = true; + } else if opt.keyring { + match keyring.get_password() { + Ok(password) => { + pass = password; + should_store = false; + }, + Err(e) => { + error!(e); pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; should_store = true; } - } else { - if let Some(password) = opt.password.as_ref() { - pass = password.clone(); - } else { - pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; - } } - }; - #[cfg(feature = "keyring-auth")] + } else { + pass = rpassword::read_password_from_tty(Some("Password: ")).context("password prompt")?; + should_store = true; + } if should_store && opt.keyring { keyring.set_password(&pass).map_err(|x| anyhow!(x.to_string()))?; } From 8849c8dddf8f0eb0824cadd7b7c6f587af7b1749 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 16:00:50 +0100 Subject: [PATCH 095/103] Remove duplicate CI run --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c80f07d..bd3f57a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - features: ["", "--all-features"] + features: ["--all-features"] steps: - uses: actions/checkout@v2 From 2894ab8bc9ce25f18f807c64f29fd195a9704690 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 16:01:47 +0100 Subject: [PATCH 096/103] CI: Remove unneeded dbus installation --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd3f57a..f4ee728 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,9 +41,6 @@ jobs: with: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} - - name: Install dbus - run: sudo apt-get install -y libdbus-1-dev - if: runner.os == 'Linux' - name: Build run: cargo build --release ${{ matrix.features }} --verbose - name: Archive artifacts From cf28db189ffd81ac6519843deb9d5a01260f8912 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 16:03:32 +0100 Subject: [PATCH 097/103] Update CHANGELOG.md --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c03cb84..1f6765c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## [0.3.0] - 2022-01-06 +### Fixed +- ILIAS 7 update ([#27]) + ## [0.2.24] - 2021-11-01 ### Added - `--combine-videos` option to merge multiple video streams of the same lecture @@ -137,6 +141,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.1.0] - 2020-04-21 (undocumented) +[#27]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/27 [#19]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/19 [#15]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/15 [#14]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/14 @@ -155,7 +160,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [@Craeckie]: https://github.com/Craeckie [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 -[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.24...HEAD +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.3.0...HEAD +[0.3.0]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.24...v0.3.0 +[0.2.24]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.23...v0.2.24 [0.2.23]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.23...v0.2.24 [0.2.23]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.22...v0.2.23 [0.2.22]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.21...v0.2.22 From 4a97f0a6597779de06a6367d5e7b7e15232658e2 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 16:41:04 +0100 Subject: [PATCH 098/103] Properly extract dashboard items --- Cargo.lock | 1 + Cargo.toml | 1 + src/ilias.rs | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1e63117..679b6fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,6 +12,7 @@ dependencies = [ "cfg-if 1.0.0", "colored", "cookie_store", + "ego-tree", "futures", "futures-channel", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index a1c2f34..c51a35c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,3 +35,4 @@ reqwest_cookie_store = "0.2.0" bytes = "1.0.1" toml = "0.5.8" tempfile = "3.2.0" +ego-tree = "0.6.2" diff --git a/src/ilias.rs b/src/ilias.rs index d7df898..eb1fbaf 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -28,8 +28,9 @@ static ALERT_DANGER: Lazy = Lazy::new(|| Selector::parse("div.alert-da static IL_CONTENT_CONTAINER: Lazy = Lazy::new(|| Selector::parse("#il_center_col").unwrap()); static BLOCK_FAVORITES: Lazy = Lazy::new(|| Selector::parse("#block_pditems_0").unwrap()); static ITEM_PROP: Lazy = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap()); -static CONTAINER_ITEMS: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem").unwrap()); +static CONTAINER_ITEMS: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem, .il-std-item").unwrap()); static CONTAINER_ITEM_TITLE: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle").unwrap()); +static CONTAINER_ITEM_TITLE_ALTERNATIVE: Lazy = Lazy::new(|| Selector::parse(".il-item-title > a").unwrap()); pub struct ILIAS { pub opt: Opt, @@ -251,10 +252,16 @@ impl ILIAS { } pub fn get_items(html: &Html) -> Vec> { + let html = if let Some(favorites) = html.select(&BLOCK_FAVORITES).next() { + favorites + } else { + html.root_element() + }; html.select(&CONTAINER_ITEMS) .flat_map(|item| { item.select(&CONTAINER_ITEM_TITLE) .next() + .or_else(|| item.select(&CONTAINER_ITEM_TITLE_ALTERNATIVE).next()) .map(|link| Object::from_link(item, link)) // items without links are ignored }) From 38ee7ed31e9de6c93c6a0d7f4e40d72f14452b3d Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Thu, 6 Jan 2022 16:41:14 +0100 Subject: [PATCH 099/103] Remove dead code --- src/ilias.rs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/ilias.rs b/src/ilias.rs index eb1fbaf..2a01f52 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -501,15 +501,10 @@ impl Object { pub struct URL { pub url: String, baseClass: String, - cmdClass: Option, - cmdNode: Option, pub cmd: Option, - forwardCmd: Option, pub thr_pk: Option, - pos_pk: Option, pub ref_id: String, target: Option, - file: Option, } #[allow(non_snake_case)] @@ -518,15 +513,10 @@ impl URL { URL { url, baseClass: String::new(), - cmdClass: None, - cmdNode: None, cmd: None, - forwardCmd: None, thr_pk: None, - pos_pk: None, ref_id: String::new(), target: None, - file: None, } } @@ -537,42 +527,27 @@ impl URL { Url::parse(href)? }; let mut baseClass = String::new(); - let mut cmdClass = None; - let mut cmdNode = None; let mut cmd = None; - let mut forwardCmd = None; let mut thr_pk = None; - let mut pos_pk = None; let mut ref_id = String::new(); let mut target = None; - let mut file = None; for (k, v) in url.query_pairs() { match &*k { "baseClass" => baseClass = v.into_owned(), - "cmdClass" => cmdClass = Some(v.into_owned()), - "cmdNode" => cmdNode = Some(v.into_owned()), "cmd" => cmd = Some(v.into_owned()), - "forwardCmd" => forwardCmd = Some(v.into_owned()), "thr_pk" => thr_pk = Some(v.into_owned()), - "pos_pk" => pos_pk = Some(v.into_owned()), "ref_id" => ref_id = v.into_owned(), "target" => target = Some(v.into_owned()), - "file" => file = Some(v.into_owned()), _ => {}, } } Ok(URL { url: url.into(), baseClass, - cmdClass, - cmdNode, cmd, - forwardCmd, thr_pk, - pos_pk, ref_id, target, - file, }) } } From b44c31d8d49a24e256fbb741bb17aceda80e92c1 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 Jan 2022 12:19:39 +0100 Subject: [PATCH 100/103] Simplify link extractor --- src/ilias.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ilias.rs b/src/ilias.rs index 2a01f52..11b0f37 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -29,8 +29,7 @@ static IL_CONTENT_CONTAINER: Lazy = Lazy::new(|| Selector::parse("#il_ static BLOCK_FAVORITES: Lazy = Lazy::new(|| Selector::parse("#block_pditems_0").unwrap()); static ITEM_PROP: Lazy = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap()); static CONTAINER_ITEMS: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem, .il-std-item").unwrap()); -static CONTAINER_ITEM_TITLE: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle").unwrap()); -static CONTAINER_ITEM_TITLE_ALTERNATIVE: Lazy = Lazy::new(|| Selector::parse(".il-item-title > a").unwrap()); +static CONTAINER_ITEM_TITLE: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle, .il-item-title > a").unwrap()); pub struct ILIAS { pub opt: Opt, @@ -261,7 +260,6 @@ impl ILIAS { .flat_map(|item| { item.select(&CONTAINER_ITEM_TITLE) .next() - .or_else(|| item.select(&CONTAINER_ITEM_TITLE_ALTERNATIVE).next()) .map(|link| Object::from_link(item, link)) // items without links are ignored }) From 7d641d5329f1eb6c9d796cf3162f6135ccf9dc98 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 Jan 2022 12:21:40 +0100 Subject: [PATCH 101/103] Support downloading every course --- src/ilias.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ilias.rs b/src/ilias.rs index 11b0f37..049184c 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -482,7 +482,8 @@ impl Object { None => Course { name, url }, }, "ilobjplugindispatchgui" => PluginDispatch { name, url }, - "ildashboardgui" => Dashboard { url }, + // both the dashboard and the membership overview page work the same + "ildashboardgui" | "ilmembershipoverviewgui" => Dashboard { url }, _ => Generic { name, url }, }) } From 536941dde1d85720d8bee942419508668f093e6a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 Jan 2022 12:29:34 +0100 Subject: [PATCH 102/103] Version 0.3.1 --- CHANGELOG.md | 4 ++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f6765c..8de9b06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## [0.3.1] - 2022-01-07 +### Fixed +- `--sync-url` can now be used to download the [course memberships](https://ilias.studium.kit.edu/ilias.php?cmdClass=ilmembershipoverviewgui&cmdNode=iy&baseClass=ilmembershipoverviewgui) + ## [0.3.0] - 2022-01-06 ### Fixed - ILIAS 7 update ([#27]) diff --git a/Cargo.lock b/Cargo.lock index 679b6fd..f120662 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "KIT-ILIAS-downloader" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "atty", diff --git a/Cargo.toml b/Cargo.toml index c51a35c..b8d1c91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "KIT-ILIAS-downloader" -version = "0.3.0" +version = "0.3.1" authors = ["FliegendeWurst <2012gdwu@posteo.de>"] license = "GPL-3.0-or-later" edition = "2018" From 75f003408c2e745bf4aa30d9aad19ac201658ae6 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 7 Jan 2022 12:31:29 +0100 Subject: [PATCH 103/103] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8de9b06..0613ae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,7 +164,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [@Craeckie]: https://github.com/Craeckie [@funnym0nk3y]: https://github.com/funnym0nk3y [@Ma27]: https://github.com/Ma27 -[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.3.0...HEAD +[Unreleased]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.3.1...HEAD +[0.3.1]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.3.0...v0.3.1 [0.3.0]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.24...v0.3.0 [0.2.24]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.23...v0.2.24 [0.2.23]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/compare/v0.2.23...v0.2.24