imdb api for other websites
The IMDb currently has two public APIs that are, although undocumented, very quick and reliable (used on their own site through AJAX).
-
A statically cached search suggestions API:
- http://sg.media-imdb.com/suggests/a/aa.json
- http://sg.media-imdb.com/suggests/h/hello.json
- Format: JSONP
-
Downside:
It's in JSONP format, however the callback parameter can not be set by passing a callback-query parameter. In order to use it cross-domain you'll have to use the function name they choose (which is in the "imdb${searchphrase}" format, see example below). Or use a local proxy (e.g. a small php file) that downloads (and caches!) it from IMDb and strips the JSON-P callback, or replaces it with a custom callback.
If there are no results, it doesn't gracefully fallback, but displays an XML error instead
// Basic
window.imdb$foo = function (list) {
/* ... */
};
jQuery.getScript('http://sg.media-imdb.com/suggests/f/foo.json');
// Using jQuery.ajax (let jQuery handle the callback)
jQuery.ajax({
url: 'http://sg.media-imdb.com/suggests/f/foo.json',
dataType: 'jsonp',
cache: true,
jsonp: false,
jsonpCallback: 'imdb$foo'
}).done(function (result) {
/* ... */
});
// With local proxy to a PHP script replacing imdb$foo with a sanitized
// version of $_GET['callback'] (http://stackoverflow.com/a/8811412/319266)
jQuery.getJSON('./imdb.php?q=foo&callback=?', function (list) {
/* ... */
});
-
More advanced search
- Name search (json): http://www.imdb.com/xml/find?json=1&nr=1&nm=on&q=jeniffer+garner
- Title search (xml): http://www.imdb.com/xml/find?xml=1&nr=1&tt=on&q=lost
- Format: JSON, XML and more
- Downside:
- No JSONP. In order to use from JavaScript cross-domain, a local proxy is required.
- No documentation, more formats may be available
- Upside
- Live search!
- Name support for actors as well!
- Proper fallback to empty object
As said, both of these APIs are undocumented. They could change at any time.
See also http://stackoverflow.com/a/8811412/319266, for an example of a JSON API in PHP.
- ۹۴/۰۹/۰۲