diff options
Diffstat (limited to 'src/plugins/url.rs')
| -rw-r--r-- | src/plugins/url.rs | 21 |
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()) } } |
