062fd87bf5
This is mainly used for Imgur.
30 lines
667 B
OCaml
30 lines
667 B
OCaml
open Str
|
|
|
|
|
|
let is_url url =
|
|
let regexp = regexp "\\(https?\\://\\)?\\(www\\.\\)?.+\\..+" in
|
|
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
|
|
|
|
|
|
let remove_spaces str =
|
|
match str with
|
|
| Some s ->
|
|
let spaces = regexp "\\( *\\\n\\)+ *" in
|
|
Some (global_replace spaces "" s)
|
|
| None -> None
|
|
|
|
|
|
|
|
(* 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 ->
|
|
SimpleHttp.get_http_title (SimpleHttp.get_body str) |> remove_spaces
|
|
| _ -> None
|