Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of upcoming movies from IMDb [closed]

I'm currently building a website and one of the blocks in the website features upcoming films (for the next week or so). I figured out IMDb is the best place to go to for that.

Problem is, IMDb has no API, and I have no idea on how to extract the data from it and show it the way I want to in my website. After reading a bit online, I saw that I am able to download pages with Ajax and then find and extract the data I need from there. However, that seems very inefficient to me, and I don't know how to find information in the downloaded file.

Is there a better way?

like image 519
Gofilord Avatar asked May 26 '14 18:05

Gofilord


1 Answers

I did this same thing for my app. Since Imdb doesn't have an API, I chose to use www.themoviedb.org. Sign up to get an API key then you can query their service. The docs are located here: http://docs.themoviedb.apiary.io/.

This is inside of a PCL and I used JSON.NET for (de)serialization and I used System.Net.Http for the network calls. Both are nuget packages. You can also use http://json2csharp.com/ to generate your classes from the sample JSON that the service returns.

Example from my app:

private const string basePath = "https://api.themoviedb.org/3/";
private const string apiKey = "<your api key here>";

...

public async Task<IEnumerable<Movie>> GetUpcomingMovies(string title)
{
    string url = string.Format("{0}movie/upcoming?api_key={1}", basePath, apiKey);

    using (var client = new HttpClient())
    {
        var result = await client.GetStringAsync(url);
        return JsonConvert.DeserializeObject<MovieList>(result).Movies;
    }
}

Themoviedatabase also returns the ID for Imdbd. So you could use that to query Imdb. I just opened a new webview in my iOS app and let it open Imdb in a new page if the user wanted to.

webview.LoadRequest(new NSUrlRequest(
     new NSUrl(string.Format("http://m.imdb.com/title/{0}", viewModel.ImdbId))));
like image 120
valdetero Avatar answered Oct 18 '22 02:10

valdetero