Given an IMDB movie id, how do I programmatically get its poster image?

前端 未结 17 698
礼貌的吻别
礼貌的吻别 2020-12-08 03:17

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

What\'s the url for its poster image?

相关标签:
17条回答
  • 2020-12-08 03:36

    I know that it is way too late, but in my project I used this:-

    1. Use omdbapi, Lets take example of Inception, use www.omdbapi.com/?t=inception it will return a json object.
    2. In that json object get the "Poster" object, it contains the poster for the image.
    0 讨论(0)
  • 2020-12-08 03:37

    There is one API service provider which will provide you poster image URL and many other details based on the movie name you have provided in their query string.

    Over here is the link to the above service provider's website.

    You can sign up and use the API service within your code.

    0 讨论(0)
  • 2020-12-08 03:39

    omdbapi works, but I found out you cannot really use these images (because of screen scraping and they are blocked anyway if you use them in an img tag)

    The best solution is to use tmdb.org :

    1 use your imdbid in this api url:

    https://api.themoviedb.org/3/find/tt0111161?api_key=___YOURAPIKEY___&external_source=imdb_id
    

    2 Retrieve the json response and select the poster_path attribute:

    "poster_path":"/9O7gLzmreU0nGkIB6K3BsJbzvNv.jpg"
    

    3 Prepend this path with "http://image.tmdb.org/t/p/original", and you will have the poster URL that you can use in an img tag :-)

    4 You can even change sizes like this:

    http://image.tmdb.org/t/p/original/9O7gLzmreU0nGkIB6K3BsJbzvNv.jpg
    http://image.tmdb.org/t/p/w150/9O7gLzmreU0nGkIB6K3BsJbzvNv.jpg
    
    0 讨论(0)
  • 2020-12-08 03:39

    Those poster images don't appear to have any correlation to the title page, so you'll have to retrieve the title page first, and then retrieve the img element for the page. The good news is that the img tag is wrapped in an a tag with name="poster". You didn't say what kind of tools you are using, but this basically a screen scraping operation.

    0 讨论(0)
  • 2020-12-08 03:40

    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.

    0 讨论(0)
  • 2020-12-08 03:41

    Here is my program to generate human readable html summary page for movie companies found on imdb page. Change the initial url to your liking and it generates a html file where you can see title, summary, score and thumbnail.

    npm install -g phantomjs
    

    Here is the script, save it to imdb.js

    var system = require('system');
    
    var page = require('webpage').create();
    page.open('http://www.imdb.com/company/co0026841/?ref_=fn_al_co_1', function() {
      console.log('Fetching movies list');
      var movies = page.evaluate(function() {
        var list = $('ol li');
        var json = []
        $.each(list, function(index, listItem) {
          var link = $(listItem).find('a');
          json.push({link: 'http://www.imdb.com' + link.attr('href')});
        });
        return json;
      });
      page.close();
    
      console.log('Found ' + movies.length + ' movies');
    
      fetchMovies(movies, 0);
    });
    
    function fetchMovies(movies, index) {
      if (index == movies.length) {
        console.log('Done');
    
        console.log('Generating HTML');
        genHtml(movies);
    
        phantom.exit();
        return;
      }
      var movie = movies[index];
    
      console.log('Requesting data for '+ movie.link);
    
      var page = require('webpage').create();
      page.open(movie.link, function() {
        console.log('Fetching data');
        var data = page.evaluate(function() {
          var title = $('.title_wrapper h1').text().trim();
          var summary = $('.summary_text').text().trim();
          var rating = $('.ratingValue strong').attr('title');
          var thumb = $('.poster img').attr('src');
    
          if (title == undefined || thumb == undefined) {
            return null;
          }
          return { title: title, summary: summary, rating: rating, thumb: thumb };
        });
    
        if (data != null) {
          movie.title = data.title;
          movie.summary = data.summary;
          movie.rating = data.rating;
          movie.thumb = data.thumb;
          console.log(movie.title)
          console.log('Request complete');
        } else {
          movies.slice(index, 1);
          index -= 1;
          console.log('No data found');
        }
        page.close();
        fetchMovies(movies, index + 1);
      });
    }
    
    function genHtml(movies) {
      var fs = require('fs');
    
      var path = 'movies.html';
      var content = Array();
    
      movies.forEach(function(movie) {
        var section = '';
    
        section += '<div>';
        section += '<h3>'+movie.title+'</h3>';
        section += '<p>'+movie.summary+'</p>';
        section += '<p>'+movie.rating+'</p>';
        section += '<img src="'+movie.thumb+'">';
        section += '</div>';
    
        content.push(section);
      });
    
      var html = '<html>'+content.join('\n')+'</html>';
    
      fs.write(path, html, 'w');
    }
    

    And run it like so

    phantomjs imdb.js
    
    0 讨论(0)
提交回复
热议问题