2014-03-01 21:50:46 +01:00
|
|
|
open Str
|
|
|
|
|
|
|
|
|
|
|
|
let is_url url =
|
2014-03-01 22:32:28 +01:00
|
|
|
let regexp = regexp "\\(https?\\://\\)?www\\..+\\..+" in
|
|
|
|
string_match regexp url 0
|
2014-03-01 21:50:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
let is_youtube_url url =
|
2014-03-01 22:32:28 +01:00
|
|
|
let regexp = regexp "\\(https?\\://\\)?\\(www\\.\\)?\\(youtube\\.com\\)\\|\\(youtu\\.be\\)/.+" in
|
|
|
|
string_match regexp url 0
|
2014-03-01 21:50:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
(* Maybe have a list of functions and
|
|
|
|
* iter on all the items in the list *)
|
|
|
|
let evaluate str =
|
|
|
|
match str with
|
2014-03-03 23:33:21 +01:00
|
|
|
| str when is_youtube_url str ->
|
|
|
|
(
|
|
|
|
let title = SimpleHttp.get_http_title (SimpleHttp.get_body str) in
|
|
|
|
match title with
|
|
|
|
| Some s -> s
|
|
|
|
| None -> ""
|
|
|
|
)
|
|
|
|
| str when is_url str -> str
|
|
|
|
| _ -> ""
|
2014-03-01 21:50:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
let () =
|
|
|
|
try
|
|
|
|
while true do
|
|
|
|
print_string "> ";
|
|
|
|
let line = read_line () in
|
|
|
|
let answer = evaluate line in
|
|
|
|
print_endline answer
|
|
|
|
done
|
|
|
|
with
|
|
|
|
End_of_file -> print_endline "Bye!";;
|