diff --git a/src/common/console.rs b/src/common/console.rs index f2c5580..3757aee 100644 --- a/src/common/console.rs +++ b/src/common/console.rs @@ -26,18 +26,20 @@ pub fn parsetitle(s: String) -> String { } out.push_str(w); }); - out + + format!("{}{}{}", + "[".bright_black().bold(), + out.bright_cyan().bold(), + "]".bright_black().bold() + ) } -pub fn parsehit(sc: u16, url: String, title: String) -> String { +pub fn parsehit(sc: u16, url: String) -> String { format!( - "{} {} {} {}{}{}", + "{} {} {}", fmtcode(sc), "|".bright_black().bold(), url.white().underline(), - "[".bright_black().bold(), - parsetitle(title).bright_cyan().bold(), - "]".bright_black().bold() ) } diff --git a/src/common/exec.rs b/src/common/exec.rs index 63a3953..182f4de 100644 --- a/src/common/exec.rs +++ b/src/common/exec.rs @@ -30,6 +30,7 @@ pub async fn takeoff(args: Config, params: Params) { .trim(), scodes, params.exclude, + args.pulltitles ) .await; } diff --git a/src/common/mod.rs b/src/common/mod.rs index 46af148..693179a 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -2,3 +2,4 @@ pub mod conf; pub mod console; pub mod exec; pub mod net; +pub mod modules; diff --git a/src/common/modules.rs b/src/common/modules.rs new file mode 100644 index 0000000..144710f --- /dev/null +++ b/src/common/modules.rs @@ -0,0 +1,15 @@ +use select::{document::Document, predicate::Name}; + +use super::console::parsetitle; + +pub fn get_title(body: &String) -> String { + let document = Document::from(body.as_str()); + + let title = document + .find(Name("title")) + .next() + .map(|n| n.text()) + .unwrap_or_else(|| "".to_string()); + + parsetitle(title) +} \ No newline at end of file diff --git a/src/common/net.rs b/src/common/net.rs index a249411..b2cf913 100644 --- a/src/common/net.rs +++ b/src/common/net.rs @@ -1,8 +1,8 @@ use reqwest::{redirect::Policy, Client}; -use select::{document::Document, predicate::Name}; use std::time::Duration; -use super::console::parsehit; +use super::console::{parsehit, parsetitle}; +use super::modules::*; pub fn mkclient(redir: bool) -> Result { let rpolicy: Policy = if redir { @@ -29,6 +29,7 @@ pub async fn query( url: &str, codes: Vec, exclude: bool, + titles: bool, ) -> Result<(), reqwest::Error> { let response: reqwest::Response; if let Ok(res) = sendreq(&c, true, url).await { @@ -53,15 +54,13 @@ pub async fn query( let url: String = response.url().to_string(); let body = response.text().await?; - let document = Document::from(body.as_str()); + let mut out = parsehit(sc, url); - let title = document - .find(Name("title")) - .next() - .map(|n| n.text()) - .unwrap_or_else(|| "".to_string()); + if titles { + out = format!("{} {}", out, get_title(&body)); + } - println!("{}", parsehit(sc, url, title)); + println!("{}", out); Ok(()) }