Clean module opening.

master
Fabien Freling 2014-03-01 22:32:28 +01:00
parent ff69981a5c
commit 35cf4a46a8
2 changed files with 14 additions and 36 deletions

View File

@ -1,32 +1,14 @@
open Str
open String
open Printf
(*open SimpleHttp*)
open Ssl
open Http_client.Convenience
open Https_client
open Nethtml
open Netchannels;;
Ssl.init();
Http_client.Convenience.configure_pipeline
(fun p ->
let ctx = Ssl.create_context Ssl.TLSv1 Ssl.Client_context in
let tct = Https_client.https_transport_channel_type ctx in
p # configure_transport Http_client.https_cb_id tct
)
let is_url url =
let regexp = Str.regexp "\\(https?\\://\\)?www\\..+\\..+" in
Str.string_match regexp url 0
let regexp = regexp "\\(https?\\://\\)?www\\..+\\..+" in
string_match regexp url 0
let is_youtube_url url =
let regexp = Str.regexp "\\(https?\\://\\)?\\(www\\.\\)?\\(youtube\\.com\\)\\|\\(youtu\\.be\\)/.+" in
Str.string_match regexp url 0
let regexp = regexp "\\(https?\\://\\)?\\(www\\.\\)?\\(youtube\\.com\\)\\|\\(youtu\\.be\\)/.+" in
string_match regexp url 0
(* Maybe have a list of functions and

View File

@ -1,31 +1,27 @@
open Str
open String
open Printf
open Ssl
open Http_client.Convenience
open Http_client
open Https_client
open Nethtml
open Netchannels;;
open Nethtml;;
Ssl.init();
Http_client.Convenience.configure_pipeline
Convenience.configure_pipeline
(fun p ->
let ctx = Ssl.create_context Ssl.TLSv1 Ssl.Client_context in
let tct = Https_client.https_transport_channel_type ctx in
p # configure_transport Http_client.https_cb_id tct
let tct = https_transport_channel_type ctx in
p # configure_transport https_cb_id tct
)
let extract_string_value document =
match document with
| Nethtml.Data(s) -> s
| Data(s) -> s
| _ -> ""
let rec get_title_element document =
match document with
| Nethtml.Element(e, args, sub) -> Printf.printf "%s: %s" "Element\n" e
| Nethtml.Data(s) -> Printf.printf "%s: %s" "Data\n" s
| Element(e, args, sub) -> printf "%s: %s" "Element\n" e
| Data(s) -> printf "%s: %s" "Data\n" s
let get_http_title body =
@ -36,6 +32,6 @@ let get_http_title body =
(* TODO: Log errors *)
let get_body url =
try Http_client.Convenience.http_get url with
| Http_client.Http_error e -> "http error /o\\"
try Convenience.http_get url with
| Http_error e -> "http error /o\\"
| Failure f -> "http fail lol"