我正在使用烂番茄API,这是相当直接的。以下是我的基本代码:
var apikey = "xxxxx";
function queryForMovie(query) {
queryUrl = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=" + apikey + "&q=" + encodeURI(query);
$.ajax({
url: queryUrl,
dataType: "jsonp",
success: queryCallback
});
}
function queryCallback(data) {
var el = $('#movie-listings');
$.each(data.movies, function(index, movie) {
el.append('img src="' + movie.posters.original + '" alt="' + movie.title + '"');
})
};
$(document).on("load", queryForMovie("Star Wars"));
但是,这会产生非常小的图像。
在尽可能限制请求的同时,获取更大尺寸图像的好方法是什么?
答案 0 :(得分:7)
烂番茄已经进行了配置更改,以便尝试直接引用云端网址不再有效。因此,此解决方案不再有效。
这是使用未经批准的变通办法的危险。
有人知道获得电影海报的好服务吗?
<小时/>
尽管烂番茄API在电影海报对象(thumbnail
,profile
,detailed
和original
)中列出了四个单独的图片,但它们目前都是,相同的网址:
"posters": {
"thumbnail": "http://resizing.flixster.com/AhKHxRwazY3brMINzfbnx-A8T9c=/54x80/dkpu1ddg7pbsk.cloudfront.net/movie/11/13/43/11134356_ori.jpg",
"profile": "http://resizing.flixster.com/AhKHxRwazY3brMINzfbnx-A8T9c=/54x80/dkpu1ddg7pbsk.cloudfront.net/movie/11/13/43/11134356_ori.jpg",
"detailed": "http://resizing.flixster.com/AhKHxRwazY3brMINzfbnx-A8T9c=/54x80/dkpu1ddg7pbsk.cloudfront.net/movie/11/13/43/11134356_ori.jpg",
"original": "http://resizing.flixster.com/AhKHxRwazY3brMINzfbnx-A8T9c=/54x80/dkpu1ddg7pbsk.cloudfront.net/movie/11/13/43/11134356_ori.jpg"
}
根据RT, high-resolution poster images are no longer available via the APIs 来保持对评分和评论的关注,更详细的内容。
但是,如果您愿意&#34;订购菜单,&#34;你仍然可以获得全分辨率图像。 / 54x80 /之后的海报图片网址部分是原始图片的云端网址:
... ...变为
http://dkpu1ddg7pbsk.cloudfront.net/movie/11/13/43/11134356_ori.jpg
javascript实现可能如下所示:
// movie = RT API movie object
var original = movie.posters.original.replace(/^.*?\/[\d]+x[\d]+\//,"http://");
此图像通常比54x80大得多,加载和显示这些图像的大列表可能不太可行。试图修改网址resizing.flixster.com网址不起作用 - 似乎涉及某种资源相关的哈希。如果您希望能够缩小图像,则需要设置或查找图像代理服务。我发现Pete Warden关于resizing and caching images with cloudfront的文章很有帮助。
使用他在文章中设置的服务的示例可能看起来像http://imageproxy.herokuapp.com/convert/resize/200x285/source/http%3A%2F%2Fdkpu1ddg7pbsk.cloudfront.net%2Fmovie%2F11%2F13%2F43%2F11134356_ori.jpg
在javascript中,这看起来像是:
// Match url: http://[some.kind/of/url/[height]x[width]/[original.cloudfront/url]
var url_parts = movie.posters.original.match(/^.*?\/([\d]+)x([\d]+)\/(.*)/);
var ratio = url_parts[1] / url_parts[2], // Determine the original image aspect ratio from the resize url
size = 200, // This is the final width of image (height is determined with the ratio)
original = "http://" + url_parts[3],
wxh = [size, Math.round(size/ratio)].join("x");
// Construct the final image url
movie.posters.original = [
"http://imageproxy.herokuapp.com/convert/resize/",
wxh,
"/source/",
encodeURIComponent(original)
].join("");
// The first request of this URL will take some time, as the original image will likely need to be scaled to the new size. Subsequent requests (from any browser) should be much quicker, so long as the image remains cached.
注意:做这样的事情取决于烂番茄保持调整大小的网址相同的形式(调整网址大小+ [宽度] x [高度] +编码的云端网址)。除非您设置自己的图像代理服务,否则在使用正常时间,性能,安全性和图像质量方面,您也受代理所有者的支配。