2014-03-09 16:02:18 +01:00
|
|
|
open Str
|
|
|
|
|
|
|
|
|
|
|
|
let is_url url =
|
2014-12-07 23:14:24 +01:00
|
|
|
let regexp = regexp "\\(https?\\://\\)?\\(www\\.\\)?.+\\..+" in
|
2014-03-09 16:02:18 +01:00
|
|
|
string_match regexp url 0
|
|
|
|
|
|
|
|
|
|
|
|
let is_youtube_url url =
|
|
|
|
let regexp = regexp "\\(https?\\://\\)?\\(www\\.\\)?\\(youtube\\.com\\)\\|\\(youtu\\.be\\)/.+" in
|
|
|
|
string_match regexp url 0
|
|
|
|
|
|
|
|
|
2014-12-12 23:20:51 +01:00
|
|
|
let remove_spaces str =
|
|
|
|
match str with
|
|
|
|
| Some s ->
|
|
|
|
let spaces = regexp "\\( *\\\n\\)+ *" in
|
|
|
|
Some (global_replace spaces "" s)
|
|
|
|
| None -> None
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-09 16:02:18 +01:00
|
|
|
(* Maybe have a list of functions and
|
|
|
|
* iter on all the items in the list *)
|
|
|
|
let evaluate str =
|
|
|
|
match str with
|
|
|
|
| str when is_url str ->
|
2014-12-12 23:25:41 +01:00
|
|
|
let title = SimpleHttp.get_http_title (SimpleHttp.get_body str) |> remove_spaces in
|
|
|
|
match title with
|
|
|
|
| Some t -> Some ("[ " ^ t ^ " ]")
|
|
|
|
| None -> None
|
2014-03-09 16:02:18 +01:00
|
|
|
| _ -> None
|