-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_check.fsx
43 lines (35 loc) · 1.44 KB
/
stream_check.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#r "packages/FSharp.Data/lib/net40/FSharp.Data.dll"
open FSharp.Data
open FSharp.Data.JsonExtensions
// Patterns http://regexr.com/3c936
type MovieSearch = JsonProvider<"samples/search.json">
type MovieDetails = JsonProvider<"samples/details.json">
let httpHeaders = [HttpRequestHeaders.UserAgent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36"]
let searchApiUrl = "http://www.canistream.it/services/search"
let queryApiUrl = "http://www.canistream.it/services/query"
// Search for the movie by name.
let searchMovie movie =
Http.RequestString (searchApiUrl,
query = ["movieName", movie; ],
headers = httpHeaders ) |>
MovieSearch.Parse
// get movie MovieDetails
let getMovieDetails movieId =
Http.RequestString(queryApiUrl,
query = ["movieId", movieId; "attributes", "1"; "mediaType", "streaming"],
headers = httpHeaders) |>
MovieDetails.Parse
let streamble (movie:MovieDetails.Root) =
match movie.JsonValue.Properties with
| x when Array.isEmpty x -> printfn "no streams found"
| x ->
Array.iter (fun (name, value) ->
let friendlyName = value?friendlyName.AsString()
printfn "Stream: %s" friendlyName
) x
let canistream moviename =
searchMovie(moviename)
|> Array.tryHead
|> function
| Some x -> streamble(getMovieDetails(x.Id))
| None -> printfn "not found"