Friday, January 20, 2012

webProgramming - http://api.themoviedb.org. Getting info about movies

I have a friend that among other things sells movies. I decided to give him a hand to fetch the relevant info about them so he can publish his own movie catalog.
With the api from http://api.themoviedb.org, it couldn't be easier. You need to request an access key first (it's free) for personal use or to develop an open source application.

I'm using this implementation for php
http://sourceforge.net/projects/simpletmdb/
and an example by Dan Bettles

Fetching the info is as simple as this: 






 * modified a little bit by René Romero
 */

$title = basename(__FILE__, '.php') . ' Demo';

$oResults = false;

if (isset($_GET['sendRequest'])) {
    require_once dirname(dirname(__DIR__)) . '/include/boot.php';
    $oResults = simpletmdb\Tmdb::create('here you put your access key')
        ->Movie
        ->getInfo($_GET['id']);
}
?>


    
        
        <?php echo $title ?>
        
    
    
        

id ?> | name ?> | tagline ?> | imdb_id ?> | certification ?> | language ?> | released ?> | homepage ?> | url ?> | runtime ?> | trailer ?> | images->xpath("image[(@type = 'poster') and (@size = 'cover')]")) { ?> | overview ?>| categories && ($oGenres = $oResults->categories->xpath("category[@type = 'genre']"))) { ?> studios && ($oStudios = $oResults->studios->xpath("studio"))){?> | countries && ($oCountries = $oResults->countries->xpath("country"))){?> | cast && ($oCast = $oResults->cast->xpath("person[@job = 'Director']"))){?> | cast && ($oCast = $oResults->cast->xpath("person[@job = 'Producer']"))){?> | cast && ($oCast = $oResults->cast->xpath("person[@job = 'Original Music Composer']"))){?> | cast && ($oCast = $oResults->cast->xpath("person[@job = 'Author']"))){?> | cast && ($oCast = $oResults->cast->xpath("person[@job = 'Actor']"))){?> |

Movie not found

TODO: Batch processing, and remove trailing commas.

No comments:

Post a Comment