繁体   English   中英

使用rottentomatoes API获得体面大小的图片

[英]Getting decent sized pictures using the rottentomatoes API

我正在使用烂番茄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"));

但是,这会产生非常小的图像。

什么是获得更大尺寸图像的好方法,同时尽可能限制请求?

** 更新 **

烂番茄已进行配置更改,以便尝试直接引用云端网址不再有效。 因此, 此解决方案不再有效

这是使用未经批准的变通办法的危险。

有谁知道获得电影海报的好服务?


原来的非工作答案:

尽管Rotten Tomatoes API在电影海报对象( thumbnailprofiledetailedoriginal照片)中列出了四个单独的图像,但它们目前都是相同的URL:

"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, 不再通过API提供高分辨率的海报图像,以保持对评级和评论的关注,更详细的内容。

但是,如果您愿意“订购菜单”,您仍然可以获得全分辨率图像。 / 54x80 /​​之后的海报图片网址部分是原始图片的云端网址:

http://resizing.flixster.com/AhKHxRwazY3brMINzfbnx-A8T9c=/54x80/dkpu1ddg7pbsk.cloudfront.net/movie/11/13/43/11134356_ori.jpg

... ...变

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,并且加载和显示这些图像的大列表可能是不可行的。 尝试修改url resizing.flixster.com url不起作用 - 似乎涉及某种资源相关的哈希。 如果您希望能够缩小图像,则需要设置或查找图像代理服务。 我发现Pete Warden关于调整和使用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 [高度] +编码的云端网址)。 除非您设置自己的图像代理服务,否则在使用正常运行时间,性能,安全性和图像质量方面,您也受代理所有者的支配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM