summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-08 16:53:11 +0100
committerJokler <jokler.contact@gmail.com>2018-03-08 16:56:29 +0100
commit2208ada6677b8aa4a5651fb21021049c1e59a1d4 (patch)
treecf93bc68e96a7ca5ee68fd09f61275861eac18d8 /src
parent1bb6e307f1011456b28bb6eb27abc80e71ef187d (diff)
downloadfrippy-2208ada6677b8aa4a5651fb21021049c1e59a1d4.tar.gz
frippy-2208ada6677b8aa4a5651fb21021049c1e59a1d4.zip
Use a naive search for html titles to speed it up
Diffstat (limited to 'src')
-rw-r--r--src/plugins/url.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/plugins/url.rs b/src/plugins/url.rs
index fa4c6f4..4c33cba 100644
--- a/src/plugins/url.rs
+++ b/src/plugins/url.rs
@@ -1,13 +1,9 @@
extern crate regex;
-extern crate select;
use irc::client::prelude::*;
use self::regex::Regex;
-use self::select::document::Document;
-use self::select::predicate::Name;
-
use plugin::*;
use utils;
@@ -39,22 +35,23 @@ impl Url {
Some(captures.get(2)?.as_str().to_owned())
}
- fn get_title(&self, body: &str) -> Option<String> {
- let doc = Document::from(body.as_ref());
- let title = doc.find(Name("title")).next()?;
- let title = title.children().next()?;
- let title_text = title.as_text()?.trim().replace("\n", "|");
+ fn get_title<'a>(&self, body: &'a str) -> Option<&'a str> {
+ let title = body.find("<title>")
+ .map(|start| body.find("</title>").map(|end| &body[start + 7..end]))
+ .and_then(|s| s);
+
debug!("Title: {:?}", title);
- debug!("Text: {:?}", title_text);
- Some(title_text)
+ title
}
fn url(&self, text: &str) -> Result<String, UrlError> {
let url = self.grep_url(text).ok_or(ErrorKind::MissingUrl)?;
let body = utils::download(&url, Some(self.max_kib)).context(ErrorKind::Download)?;
- Ok(self.get_title(&body).ok_or(ErrorKind::MissingTitle)?)
+ let title = self.get_title(&body).ok_or(ErrorKind::MissingTitle)?;
+
+ Ok(title.to_owned())
}
}