From 3e451322936e9a87d8bf8ee8da56f64e3ee14303 Mon Sep 17 00:00:00 2001 From: Zastian Pretorius Date: Fri, 10 Jun 2022 19:11:38 +0100 Subject: [PATCH] initial commit --- .gitignore | 1 + Cargo.lock | 683 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 11 + src/main.rs | 266 ++++++++++++++++++++ 4 files changed, 961 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e6f9a74 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,683 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "async-channel" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + +[[package]] +name = "castaway" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2698f953def977c68f935bb0dfa959375ad4638570e969e2f1e9f433cbf1af6" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[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 = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "curl" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d855aeef205b43f65a5001e0997d81f8efca7badad4fad7d897aa7f0d0651f" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi", +] + +[[package]] +name = "curl-sys" +version = "0.4.55+curl-7.83.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23734ec77368ec583c2e61dd3f0b0e5c98b93abe6d2a004ca06b91dd7e3e2762" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi", +] + +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "event-listener" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" + +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures-core" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" + +[[package]] +name = "futures-io" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" + +[[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 = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "isahc" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "334e04b4d781f436dc315cb1e7515bd96826426345d498149e4bde36b67f8ee9" +dependencies = [ + "async-channel", + "castaway", + "crossbeam-utils", + "curl", + "curl-sys", + "encoding_rs", + "event-listener", + "futures-lite", + "http", + "log", + "mime", + "once_cell", + "polling", + "slab", + "sluice", + "tracing", + "tracing-futures", + "url", + "waker-fn", +] + +[[package]] +name = "itoa" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "libnghttp2-sys" +version = "0.1.7+1.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57ed28aba195b38d5ff02b9170cbff627e336a20925e43b4945390401c5dc93f" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "libz-sys" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "log_e" +version = "0.1.0" +dependencies = [ + "colored", + "isahc", + "regex", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "once_cell" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835363342df5fba8354c5b453325b110ffd54044e588c539cf2f20a8014e4cb1" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pkg-config" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + +[[package]] +name = "polling" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +dependencies = [ + "cfg-if", + "libc", + "log", + "wepoll-ffi", + "winapi", +] + +[[package]] +name = "proc-macro2" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" + +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys", +] + +[[package]] +name = "slab" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" + +[[package]] +name = "sluice" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7400c0eff44aa2fcb5e31a5f24ba9716ed90138769e4977a2ba6014ae63eb5" +dependencies = [ + "async-channel", + "futures-core", + "futures-io", +] + +[[package]] +name = "socket2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tracing" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" +dependencies = [ + "cfg-if", + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..23e22e4 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "log_e" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +regex = "1.5.6" +colored = "2.0.0" +isahc = "1.7.2" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..24dc8ff --- /dev/null +++ b/src/main.rs @@ -0,0 +1,266 @@ +use regex::Regex; +use std::vec::Vec; +use std::fs::File; +use std::io::prelude::*; +use colored::Colorize; +use isahc::prelude::*; +use std::process::{Command, ExitStatus}; +use std::io::Result; +fn main() { + let mut search_path = String::new(); + println!("What ln do you want to read?"); + std::io::stdin().read_line(&mut search_path).expect("Failed to read line"); + let search_path = search_path.replace(" ", "+"); + let url = "https://readlightnovels.net/?s=".to_string(); + let url = format!("{}{}", url, search_path.trim()).trim().to_string(); + let html = get_html(&url).trim().to_string(); + let ln_list = get_ln_list(&html); + //remove first element of ln_list + let ln_list = ln_list.iter().skip(1).map(|x| x.to_string()).collect::>(); + let ln_titles = get_ln_titles(&ln_list); + let ln_urls = get_ln_urls(&ln_list); + let mut count = 0; + for ln in ln_titles { + if count % 2 == 0 { + println!("({})\t{}",count, format!("{}", ln.blue())); + } else { + println!("({})\t{}",count, format!("{}", ln.yellow())); + } + count += 1; + } + println!("Which ln do you want to read?"); + let mut ln_number = String::new(); + std::io::stdin().read_line(&mut ln_number).expect("Failed to read line"); + let ln_number = ln_number.trim().to_string(); + let ln_number = ln_number.parse::().unwrap(); + let ln_url = &ln_urls[ln_number]; + let ln_url = ln_url.trim().to_string(); + let ln_html = get_html(&ln_url); + let ln_id = get_ln_id(&ln_html); + let ln_last_page = get_ln_last_page(&ln_html); + let ln_page_html = page_selector(&ln_last_page, &ln_id); + let ln_chapters = get_ln_chapters(&ln_page_html); + let ln_chapters_urls = get_ln_chapters_urls(&ln_page_html); + count = 0; + for chaprer in ln_chapters { + if count % 2 == 0 { + println!("({})\t{}",count, format!("{}", chaprer.blue())); + } else { + println!("({})\t{}",count, format!("{}", chaprer.yellow())); + } + count += 1; + } + println!("Which chapter do you want to read?"); + let mut chaprer_number = String::new(); + std::io::stdin().read_line(&mut chaprer_number).expect("Failed to read line"); + let chaprer_number = chaprer_number.trim().to_string(); + let chaprer_number = chaprer_number.parse::().unwrap(); + let chaprer_url = &ln_chapters_urls[chaprer_number]; + let chaprer_url = chaprer_url.trim().to_string(); + let ln_text = get_ln_text(&chaprer_url); + let mut full_text: String = String::new(); + for line in ln_text { + let text = format!("{}\n\n", line); + full_text.push_str(&text); + } + //write full_text to file called temp.txt + let mut file = File::create("/tmp/log_e").expect("Unable to create file"); + file.write_all(full_text.as_bytes()).expect("Unable to write to file"); + //close file + file.sync_all().expect("Unable to sync file"); + //open temp.txt in cat for user to read + let _com = open_bat(); + +} + +pub fn open_bat() -> Result { + Command::new("bat").arg("-p").arg("/tmp/log_e").spawn()?.wait() +} + +//gets the full html of the page +fn get_html(url: &str) -> String { + let mut resp = isahc::get(url).unwrap(); + let html = resp.text().unwrap(); + html +} +//gets the list of ln's from the html and returns it as a vector of the ln's name and href +fn get_ln_list(html: &str) -> Vec { + let re = Regex::new(r#"(?m)^\s*( = Vec::new(); + for cap in re.captures_iter(html) { + ln_list.push(cap.get(1).unwrap().as_str().trim().to_string()); + } + ln_list +} +//gets the titles of the ln's from the html and returns it as a vector of the ln's name +fn get_ln_titles(ln_list: &Vec) -> Vec { + let re = Regex::new(r#"(?m)^\s* = Vec::new(); + for ln in ln_list { + for cap in re.captures_iter(ln) { + ln_title.push(cap.get(1).unwrap().as_str().to_string()); + } + } + ln_title +} + +//gets the urls of the ln's from the html and returns it as a vector of the ln's href +fn get_ln_urls(ln_list: &Vec) -> Vec { + let re = Regex::new(r#"(?m)^\s* = Vec::new(); + for ln in ln_list { + for cap in re.captures_iter(ln) { + ln_url.push(cap.get(1).unwrap().as_str().to_string()); + } + } + ln_url +} + +//gets the chapter titles from the html and returns it as a vector of the chapter's name +fn get_ln_chapters(html: &str) -> Vec { + let re = Regex::new(r#"title=(.*?)>"#).unwrap(); + let mut ln_list:Vec = Vec::new(); + for cap in re.captures_iter(html) { + ln_list.push(cap.get(1).unwrap().as_str().trim().to_string()); + } + ln_list = remove_after_dash(&ln_list); + ln_list +} + + +//function that takes a vector called ln_chapters of strings and removes everyting after the first occurence of "-" and all \ and " +fn remove_after_dash(ln_chapters: &Vec) -> Vec { + let mut ln_chapters_new:Vec = Vec::new(); + let re = Regex::new(r#"\\"(.*?) -"#).unwrap(); + for ln in ln_chapters { + for cap in re.captures_iter(ln) { + ln_chapters_new.push(cap.get(1).unwrap().as_str().trim().to_string()); + } + } + ln_chapters_new = replace_unicode(&ln_chapters_new); + ln_chapters_new +} + +//function that takes a vector called ln_chapters and looks for unicode characters and replaces them with the ascii version +fn replace_unicode(ln_chapters: &Vec) -> Vec { + let mut ln_chapters_new:Vec = Vec::new(); + for ln in ln_chapters { + //make regex to find all \uxxxx and save it in to a vector + let re = Regex::new(r#"(\\u[0-9a-fA-F]{4})"#).unwrap(); + let mut vec_unicode:Vec = Vec::new(); + for cap in re.captures_iter(ln) { + vec_unicode.push(cap.get(1).unwrap().as_str().to_string()); + } + let mut ln_new :String = String::new(); + if vec_unicode.len() > 0 { + //loop through the vector and replace the unicode characters with the ascii version + for unicode in vec_unicode { + //convert the unicode to char + let unicode_char = char::from_u32(u32::from_str_radix(&unicode[2..6], 16).unwrap()).unwrap(); + let unicode_str = unicode_char as char; + ln_new = ln.replace(&unicode, &unicode_str.to_string()); + } + } + else { + ln_new = ln.to_string(); + } + ln_chapters_new.push(ln_new); + } + ln_chapters_new +} + +fn fix_html_encoding(ln_text: &Vec) -> Vec{ + let mut ln_text_new:Vec = Vec::new(); + for ln in ln_text{ + let ln = ln.replace("―", "--"); + let ln = ln.replace("‖", "--"); + let ln = ln.replace("‘", "'"); + let ln = ln.replace("’", "'"); + let ln = ln.replace("“", "\""); + let ln = ln.replace("”", "\""); + let ln = ln.replace("…", "..."); + let ln = ln.replace("′", "'"); + let ln = ln.replace("″", "\""); + let ln = ln.replace("⁄", "--"); + let ln = ln.replace("—", "--"); + ln_text_new.push(ln); + + } + ln_text_new +} +//gets the chapter urls from the html and returns it as a vector of the chapter's href +fn get_ln_chapters_urls(html: &str) -> Vec { + let re = Regex::new(r#"href=\\"(h.*?)""#).unwrap(); + let mut ln_list:Vec = Vec::new(); + for cap in re.captures_iter(html) { + ln_list.push(cap.get(1).unwrap().as_str().trim().to_string()); + } + ln_list = url_clean(&ln_list); + ln_list +}// take a vector of srings called ln_chapters_url and remove all the \ +fn url_clean(ln_chapters_url: &Vec) -> Vec { + let mut ln_chapters_url_new:Vec = Vec::new(); + for ln in ln_chapters_url { + let ln = ln.replace("\\", ""); + ln_chapters_url_new.push(ln); + } + ln_chapters_url_new +} + +//take a html string and return the ln id +fn get_ln_last_page(html: &str) -> String { + let re = Regex::new(r#"(?m)Last"#).unwrap(); + let mut ln_last_page:String = String::new(); + for cap in re.captures_iter(html) { + ln_last_page = cap.get(1).unwrap().as_str().to_string(); + } + ln_last_page +} + +//take a html string and return the ln id +fn get_ln_id(html: &str) -> String { + let re = Regex::new(r#"(?m)^\s*"#).unwrap(); + let mut ln_id:String = String::new(); + for cap in re.captures_iter(html) { + ln_id = cap.get(1).unwrap().as_str().to_string(); + } + ln_id +} + +//using isahc::prelude::* make a php reqest to get the next page of the ln +fn get_ln_next_page(ln_id: &str, page: &str) -> String { + let url = "https://readlightnovels.net/wp-admin/admin-ajax.php".to_string(); + let form = format!("action=tw_ajax&type=pagination&id={}.html&page={}", ln_id, page); + let mut resp = isahc::post(url,form).unwrap(); + let html = resp.text().unwrap(); + html +} + +fn page_selector(max_page: &str, ln_id: &str) -> String { + println!("Please select a page go to"); + println!("1..{}", max_page); + let mut page_select = String::new(); + std::io::stdin().read_line(&mut page_select).unwrap(); + let page_select: u32 = page_select.trim().parse().unwrap(); + while page_select > max_page.parse::().unwrap() { + println!("Please select a page go to"); + println!("1..{}", max_page); + let mut page_select = String::new(); + std::io::stdin().read_line(&mut page_select).unwrap(); + } + get_ln_next_page(&ln_id, &page_select.to_string()) +} + +fn get_ln_text(chapter_url: &str) -> Vec { + let mut resp = isahc::get(chapter_url).unwrap(); + let html = String::from(resp.text().unwrap()); + let re = Regex::new(r#"(?m)

(.*?)

"#).unwrap(); + let mut ln_text:Vec = Vec::new(); + for cap in re.captures_iter(&html) { + ln_text.push(cap.get(1).unwrap().as_str().trim().to_string()); + } + // remove last 3 indexes of ln_text + ln_text.truncate(ln_text.len() - 3); + let ln_text = fix_html_encoding(&ln_text); + ln_text +}