1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Grab Movie Poster from IMDB

Discussion in 'PHP' started by Vick.Kumar, Feb 25, 2013.

  1. #1
    Hi,

    I was going through old files on mediafire, and found a few useful php scripts, so here's a source code to grab the movie image/post from IMDB based on the movie named passed through in the function/param.

    <?php
    /**
    * Grab Movie Poster from IMDB to display on hover
    *
    * @author Vick Kumar <vickkumar2011@gmail.com>
    * @copyright Seecure.me, 2012
    * @version 1.0
    * @license http://creativecommons.org/licenses/by/3.0/legalcode
    */
     
    function getImage($title)
    {
      $source = file_get_contents("http://www.imdbapi.com/?i=&t=$title");
      $decode = json_decode($source, true);
      return $decode['Poster'];
    }
    ?>
    PHP:
     
    Vick.Kumar, Feb 25, 2013 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Have you tested it? Does it work or has IMDB changed since this code was valid?

    there are lots of code on mediafire - how does this rate compared to other IMDB scripts?

    And why have you posted it? Is it a personal recommendation, are you hoping someone might be overcome with gratitude and give you a "like"?
     
    sarahk, Feb 25, 2013 IP
  3. Vick.Kumar

    Vick.Kumar Active Member

    Messages:
    138
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Yeah man. It works !, and like I said I posted it cause I thought it would be useful to share, and if not go ahead and delete it, your the queen.
     
    Vick.Kumar, Feb 26, 2013 IP
  4. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #4
    In case anybody couldn't get the above to work;

    <?php
    $homepage = file_get_contents('http://www.imdbapi.com/?t=The%20Holiday');
    $arr = json_decode($homepage, true);
    print($arr['Poster']);
    ?>
    PHP:
    To see all the data you can grab:

    <?php
    $homepage = file_get_contents('http://www.imdbapi.com/?t=The%20Holiday');
    $arr = json_decode($homepage, true);
    print($homepage);
    ?>
    PHP:
     
    scottlpool2003, Feb 27, 2013 IP
  5. Vick.Kumar

    Vick.Kumar Active Member

    Messages:
    138
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    90
    #5
    ^ In regards to that. Awesome ! Also, if you do use it and you want to do bulk processing I recommend using CURL instead of file_get_contents !
     
    Vick.Kumar, Feb 27, 2013 IP
  6. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #6
    Yes CURL would probably be better at handling larger amounts of data, here's an example of usage using the URL to get the movie title:

    <?php
     
        $title = rawurlencode($_GET['title']);
     
        //optional comment out or delete 
        error_reporting(E_ALL); 
     
        // The POST URL and parameters 
        $request =  'http://www.imdbapi.com/?t='.$title.'&r=XML'; 
     
        // Get the curl session object 
        $session = curl_init($request); 
     
        // Set the POST options. 
        curl_setopt($session, CURLOPT_HEADER, true); 
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true); 
     
        // Do the POST and then close the session 
        $response = curl_exec($session); 
        curl_close($session); 
     
        // Get HTTP Status code from the response 
        $status_code = array(); 
        preg_match('/\d\d\d/', $response, $status_code); 
     
        // Check for errors 
        switch( $status_code[0] ) { 
            case 200: 
                // Success 
                break; 
            case 503: 
                die('Service unavailable. An internal problem prevented us from returning data to you.'); 
                break; 
            case 403: 
                die('Forbidden. You do not have permission to access this resource, or are over your rate limit.'); 
                break; 
            case 400: 
                // You may want to fall through here and read the specific XML error 
                die('Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.'); 
                break; 
            default: 
                die('Your call returned an unexpected HTTP status of:' . $status_code[0]); 
        } 
     
        // Get the XML from the response, bypassing the header 
        if (!($xml = strstr($response, '<?xml'))) { 
            $xml = null; 
        } 
     
        // Output the XML 
     
        $movieInfo = simplexml_load_string($xml); 
     
     
     
        echo "Title: ".$movieInfo->movie['title']."<br />Poster: ".$movieInfo->movie['poster']."<br />";
     
    ?>
    PHP:
    Slightly modified from this example: http://stackoverflow.com/questions/6932838/php-curl-error-after-changing-only-url

    I think another process to actually grab and save the image would be needed as IMDB do not allow embedding on their images so you'll only get the image URL and not be able to do anything with it.

    Its also worth noting that according to their T&C:


    http://www.imdb.com/help/show_article?conditions
     
    scottlpool2003, Feb 27, 2013 IP
  7. Vick.Kumar

    Vick.Kumar Active Member

    Messages:
    138
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    90
    #7
    Thats right, so it's better to use an API provided by a third-party rather than suffer financial disputes with IMDB's law team.
     
    Vick.Kumar, Feb 27, 2013 IP