Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module TheMovieDB =
open Model
let key = "YOUR_KEY"
let baseUrl = "http://api.themoviedb.org/3"
let baseImageUrl = "https://image.tmdb.org/t/p/w185/"
let [<Literal>] discoverUrl = """{ "page": 1, "results": [{ "adult": false, "backdrop_path": "/dkMD5qlogeRMiEixC4YNPUvax2T.jpg", "genre_ids": [28,12,878, 53 ],"id": 135397,"original_language": "en", "original_title": "Jurassic World", "overview":"overviewremoved", "release_date": "2015-06-12", "poster_path": "/uXZYawqUsChGSj54wcuBtEdUJbh.jpg","popularity": 88.551849, "title": "Jurassic World", "video": false,"vote_average": 7.1, "vote_count": 435 }],"total_pages": 11543, "total_results": 230847}"""
type MovieList = JsonProvider<discoverUrl>
let getMoviesByPage page = async {
let! response =
String.Format("{0}/discover/movie?api_key={1}&page={2}",baseUrl, key, page)
|> MovieList.AsyncLoad
return response
|> fun js -> js.Results
|> Array.map(fun r -> Movie(Title=r.Title, ImagePath=baseImageUrl+r.PosterPath, Overview=r.Overview))
}
let getMovies (currentPage, times) =
[|currentPage..currentPage+times|]
|> Array.map(fun p -> p.ToString())
|> Array.map(getMoviesByPage)
|> Async.Parallel
|> Async.RunSynchronously
|> Array.collect(fun m -> m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.