Login   Register  
PHP Classes
elePHPant
Icontem

File: list.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Randy Gerritse  >  IMDBSearch  >  list.php  >  Download  
File: list.php
Role: Auxiliary script
Content type: text/plain
Description: parses the movielist.txt file and adds all items that have 1 found record directly to the local db (if not already present), offers a choice when multiple records have been found
Class: IMDBSearch
Search the Internet Movie DataBase
Author: By
Last change:
Date: 2003-07-30 10:23
Size: 3,439 bytes
 

Contents

Class file image Download
<?
/*    Parse movielist.txt, add single results to db, offer choice for multi-records
    Don't modify without written authorization
    Created by: Randy Gerritse
    Email: randy@randy.nu
    ©2003, All rights reserved.
    ================================================================================ */

require("init.php");

$list file("movielist.txt");
foreach (
$list as $item) {
    
$imdb = new IMDBSearch($item);
    if (!isset(
$imdb->imdb_result["multiple"])) {
        
        
$indb $connection->execute($sql->checkID($imdb->imdb_result["id"]));
        if (
count($indb) <= 0) {
            
            
//add the movie
            
$connection->execute($sql->addMovie($imdb->imdb_result["id"],$imdb->imdb_result["title"],$imdb->imdb_result["cover"],$imdb->imdb_result["year"],$imdb->imdb_result["rating"],$imdb->imdb_result["tagline"],$imdb->imdb_result["outline"],$imdb->imdb_result["outlinemore"]));
            
            
//get the movie genres
            
if (count($imdb->imdb_result["genre"]) > 0) {
                foreach (
$imdb->imdb_result["genre"] as $genre) {
                    
//create the genre if not existent
                    
$genres $connection->execute($sql->getGenre($genre));
                    if (
count($genres) <= 0) {
                        
$genreid $connection->execute($sql->createGenre(strtolower($genre)));
                    } else {
                        
$gen current($genres);
                        
$genreid $gen["id"];
                    }
                    
//add the movie to the genre
                    
$connection->execute($sql->addMovieToGenre($imdb->imdb_result["id"],$genreid));
                }
            }
            
            
//get the movie cast
            
if (count($imdb->imdb_result["cast"]) > 0) {
                foreach (
$imdb->imdb_result["cast"] as $actor) {
                    
//create the actor if not existent
                    
$actors $connection->execute($sql->getActor($actor["Name"]));
                    if (
count($actors) <= 0) {
                        
$actorid $connection->execute($sql->createActor($actor["Name"]));
                    } else {
                        
$act current($actors);
                        
$actorid $act["id"];
                    }
                    
//add the actor to the movie
                    
$connection->execute($sql->addActorToMovie($imdb->imdb_result["id"],$actorid,$actor["Character"]));
                }
            }
            
            
//get the directors
            
if (count($imdb->imdb_result["directors"]) > 0) {
                foreach (
$imdb->imdb_result["directors"] as $director) {
                    
//create the director if not existent
                    
$directors $connection->execute($sql->getDirector($director["name"]));
                    if (
count($directors) <= 0) {
                        
$directorid $connection->execute($sql->createDirector($director["name"]));
                    } else {
                        
$dir current($directors);
                        
$directorid $dir["id"];
                    }
                    
//add the director to the movie
                    
$connection->execute($sql->addDirectorToMovie($imdb->imdb_result["id"],$directorid));
                }
            }
            
            echo 
'('.$imdb->imdb_result["rating"].') '.$imdb->imdb_result["title"].' (id = '.$imdb->imdb_result["id"].')<br>';
            
flush();
        }
    } else {
        
        
//echo the multiple listings...
        
if (count($imdb->imdb_result["multiple"]) > 0) {
            
$break 0;
            foreach (
$imdb->imdb_result["multiple"] as $key=>$val) {
                
$indb $connection->execute($sql->checkID($key));
                if (
count($indb) > 0)
                    
$break 1;
            }
            if (
$break != 1) {
                echo 
"we found multiple records for \"$item\":<br>";
                foreach (
$imdb->imdb_result["multiple"] as $alt) {
                    echo 
'<a href="new.php?item='.$alt["Id"].'" target="_BLANK">'.$alt["Title"].'</a> (<a href="'.IMDB_URL.$alt["Id"].'" target="_BLANK">IMDB</a>)<br>';
                }
                echo 
"<hr>";
                
flush();
            }
        }
    }
}


?>