IMDB 是否提供 API? [英] Does IMDB provide an API?

查看:32
本文介绍了IMDB 是否提供 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现了一个电影管理器应用程序,它从 IMDB 数据库 中获取数据.

I recently found a movie organizer application which fetches its data from the IMDB database.

IMDB 是否为此提供 API 或任何可用的第三方 API?

Does IMDB provide an API for this, or any third party APIs available?

推荐答案

IMDb 有一个公共 API,虽然没有记录,但速度快且可靠(通过 AJAX 在官方网站上使用).

The IMDb has a public API that, although undocumented, is fast and reliable (used on the official website through AJAX).

https://v2.sg.media-imdb.com/suggests/h/hello.json(截至 2019 年)

https://v2.sg.media-imdb.com/suggests/h/hello.json (as of 2019)

  • 格式:JSON-P
  • 注意:JSON-P 格式,回调参数无法自定义.要跨域使用它,您必须将它们的函数名称用于回调(采用 imdb${searchphrase} 格式).或者,可以通过本地代理去除或替换填充.
  • Format: JSON-P
  • Caveat: It's in JSON-P format, and the callback parameter can not customised. To use it cross-domain you'll have to use their function name for the callback (which is in the imdb${searchphrase} format). Alternatively, one could strip or replace the padding via a local proxy.

https://v2.sg.media-imdb.com/suggestion/h/hello.json(截至 2020 年)

https://v2.sg.media-imdb.com/suggestion/h/hello.json (as of 2020)

  • 格式:JSON
  • 警告:它不支持 CORS.这适用于应用程序和服务器端脚本.要在网络应用中使用,您需要通过一个简单的代理对其进行路由(并考虑启用缓存!)
// 1) Vanilla JavaScript (JSON-P)
function addScript(src) { var s = document.createElement('script'); s.src = src; document.head.appendChild(s); }
window.imdb$foo = function (results) {
  /* ... */
};
addScript('https://sg.media-imdb.com/suggests/f/foo.json');

// 2) Using jQuery (JSON-P)
jQuery.ajax({
    url: 'https://sg.media-imdb.com/suggests/f/foo.json',
    dataType: 'jsonp',
    cache: true,
    jsonp: false,
    jsonpCallback: 'imdb$foo'
}).then(function (results) {
    /* ... */
});

// 3) Pure JSON (with jQuery)
// Use a local proxy to the clean `/suggestion` API.
jQuery.getJSON('/api/imdb/?q=foo', function (results) {
    /* ... */
});

// 4) Pure JSON (plain JavaScript; Modern ES6, ES2017, and Fetch API)
// Serve a "/api" route in your app, that proxies (and caches!)
// to v2.sg.media-imdb.com/suggestion/h/hello.json
const resp = await fetch('/api/imdb/?q=foo');
const results = await resp.json();

高级搜索

  • 姓名搜索(json):http://www.imdb.com/xml/find?json=1&nr=1&nm=on&q=jeniffer+garner
  • 标题搜索 (xml):http://www.imdb.com/xml/find?xml=1&nr=1&tt=on&q=lost
  • 格式:XML
  • 优点:同时支持电影片名和演员姓名(与 Suggestions API 不同).
  • 请注意,这些 API 是非官方的,可能会随时更改!

    Beware that these APIs are unofficial and could change at any time!

    更新(2019 年 1 月):高级 API 不再存在.好消息是,Suggestions API 现在支持高级"还具有按片名和演员姓名搜索的功能.

    Update (January 2019): The Advanced API no longer exists. The good news is, that the Suggestions API now supports the "advanced" features of searching by film titles and actor names as well.

    这篇关于IMDB 是否提供 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆