Given an IMDB movie id, how do I programmatically

2020-02-02 09:47发布

movie id tt0438097 can be found at http://www.imdb.com/title/tt0438097/

What's the url for its poster image?

标签: imdb
16条回答
Anthone
2楼-- · 2020-02-02 10:27

After playing around with @Hawk's BASE64 discovery above, I found that everything after the BASE64 code is display info. If you remove everything between the last @ and .jpg it will load the image in the highest res it has.

https://m.media-amazon.com/images/M/MV5BMjAwODg3OTAxMl5BMl5BanBnXkFtZTcwMjg2NjYyMw@@._V1_UX182_CR0,0,182,268_AL_.jpg

becomes

https://m.media-amazon.com/images/M/MV5BMjAwODg3OTAxMl5BMl5BanBnXkFtZTcwMjg2NjYyMw@@.jpg
查看更多
对你真心纯属浪费
3楼-- · 2020-02-02 10:30
$Title = $($Movie.Name)

$searchTitle = $Title.Replace(' ','%20')  

$moviesearch = Invoke-WebRequest "http://www.imdb.com/search/title?title=$searchTitle&title_type=feature"

$titleclassarray = $moviesearch.AllElements | where Class -eq 'loadlate' | select -First 1

$MoviePoster = $titleclassarray.loadlate
查看更多
We Are One
4楼-- · 2020-02-02 10:33

As I'm sure you know, the actual url for that image is

http://ia.media-imdb.com/images/M/MV5BMTI0MDcxMzE3OF5BMl5BanBnXkFtZTcwODc3OTYzMQ@@._V1._SX100_SY133_.jpg

You're going to be hard pressed to figure out how it's generated though and they don't seem to have a publicly available API.

Screenscraping is probably your best bet.

The picture seems to generally be inside a div with class=photo and the name of the a tag is poster.

The image itself is just inside the a tag.

查看更多
贪生不怕死
5楼-- · 2020-02-02 10:34

I've done something similar using phantomjs and wget. This bit of phantomjs accepts a search query and returns the first result's movie poster url. You could easily change it to your needs.

var system = require('system');

if (system.args.length === 1) {
  console.log('Usage: moviePoster.js <movie name>');
  phantom.exit();
}

var formattedTitle = encodeURIComponent(system.args[1]).replace(/%20/g, "+");
var page = require('webpage').create();
page.open('http://m.imdb.com/find?q=' + formattedTitle, function() {
  var url = page.evaluate(function() {
    return 'http://www.imdb.com' + $(".title").first().find('a').attr('href');
  });
  page.close();
  page = require('webpage').create();
  page.open(url, function() {
    var url = page.evaluate(function() {
      return 'http://www.imdb.com' + $("#img_primary").find('a').attr('href');
    });
    page.close();
    page = require('webpage').create();
    page.open(url, function() {
      var url = page.evaluate(function() {
        return $(".photo").first().find('img').attr('src');
      });
      console.log(url);
      page.close();
      phantom.exit();
    });
  });
});

I download the image using wget for many movies in a directory using this bash script. The mp4 files have names that the IMDB likes, and that's why the first search result is nearly guaranteed to be correct. Names like "Love Exposure (2008).mp4".

for file in *.mp4; do
  title="${file%.mp4}"
  if [ ! -f "${title}.jpg" ] 
    then
      wget `phantomjs moviePoster.js "$title"` -O "${title}.jpg"
  fi
done

Then minidlna uses the movie poster when it builds the thumbnail database, because it has the same name as the video file.

查看更多
登录 后发表回答