예제 #1
0
function newMovie($title)
{
    //require("connect.php");
    //require("string.php");
    $movieId = str_replace(" ", "+", $title);
    $movieId = mysqli_real_escape_string($conn, $movieId);
    //in case of apostrophes etc.
    //@ to suppress warnings and notices...
    /*OMDB API -DOESNT EXIST FOR ALL MOVIES*/
    $omdbXml = @simplexml_load_file("http://www.omdbapi.com/?t=" . urlencode($movieId) . "&plot=full&r=xml&tomatoes=true");
    $poster = "";
    $metascore = "";
    $imdbRating = "";
    $imdbVotes = "";
    $imdbID = "";
    $runtime = "";
    $plot = "";
    $releaseDate = "";
    $rated = "";
    $genre = "";
    $director = "";
    $writer = "";
    $language = "";
    $country = "";
    $actors = "";
    $website = "";
    $boxOffice = "";
    $awards = "";
    $tomatoMeter = "";
    $tomatoImage = "";
    $tomatoRating = "";
    $tomatoReviews = "";
    $tomatoFresh = "";
    $tomatoRotten = "";
    $tomatoUserMeter = "";
    $tomatoUserRating = "";
    $tomatoUserReviews = "";
    $imdbLink = "";
    //echo $omdbXml->attributes()->response;
    if (@$omdbXml->root['response'] == "False") {
        echo "movie not found in omdb";
        // throw new Exception("Cannot load xml source.\n");
        $poster = "";
        $metascore = "";
        $imdbRating = "";
        $imdbVotes = "";
        $imdbID = "";
        $runtime = "";
        $plot = "";
        $releaseDate = "";
        $rated = "";
        $genre = "";
        $rated = "";
        $genre = "";
        $director = "";
        $writer = "";
        $language = "";
        $country = "";
        $actors = "";
        $website = "";
        $boxOffice = "";
        $awards = "";
        $tomatoMeter = "";
        $tomatoImage = "";
        $tomatoRating = "";
        $tomatoReviews = "";
        $tomatoFresh = "";
        $tomatoRotten = "";
        $tomatoUserMeter = "";
        $tomatoUserRating = "";
        $tomatoUserReviews = "";
        $imdbLink = "";
    } else {
        //$genre = $omdbXml->movie['genre'];
        $director = mysqli_real_escape_string($conn, htmlentities(@$omdbXml->movie['director']));
        //$releaseDate = $omdbXml->movie['released'];
        $writer = mysqli_real_escape_string($conn, htmlentities(@$omdbXml->movie['writer']));
        $language = @$omdbXml->movie['language'];
        $country = @$omdbXml->movie['country'];
        $actors = mysqli_real_escape_string($conn, htmlentities(@$omdbXml->movie['actors']));
        $website = @$omdbXml->movie['Website'];
        $boxOffice = @$omdbXml->movie['boxOffice'];
        $awards = @$omdbXml->movie['awards'];
        //omdb tomato
        $tomatoMeter = @$omdbXml->movie['tomatoMeter'];
        $tomatoImage = @$omdbXml->movie['tomatoImage'];
        $tomatoRating = @$omdbXml->movie['tomatoRating'];
        $tomatoReviews = @$omdbXml->movie['tomatoReviews'];
        $tomatoFresh = @$omdbXml->movie['tomatoFresh'];
        $tomatoRotten = @$omdbXml->movie['tomatoRotten'];
        $tomatoUserMeter = @$omdbXml->movie['tomatoUserMeter'];
        $tomatoUserRating = @$omdbXml->movie['tomatoUserRating'];
        $tomatoUserReviews = @$omdbXml->movie['tomatoUserReviews'];
        $metascore = @$omdbXml->movie['metascore'];
        $imdbRating = @$omdbXml->movie['imdbRating'];
        $imdbVotes = @$omdbXml->movie['imdbVotes'];
        $imdbID = @$omdbXml->movie['imdbID'];
        $runtime = @$omdbXml->movie['runtime'];
        $plot = mysqli_real_escape_string($conn, @$omdbXml->movie['plot']);
        $releaseDate = @$omdbXml->movie['releaseDate'];
        $rated = @$omdbXml->movie['rated'];
        $genre = @$omdbXml->movie['genre'];
        $poster = @$omdbXml->movie['poster'];
        $imdbLink = "";
    }
    if (!IsEmpty($imdbID)) {
        echo "getting myapi films ";
        $myApiFilmsUrl = "http://api.myapifilms.com/imdb/idIMDB?idIMDB=" . $imdbID . "&token=870c3596-fa05-4ced-82cf-a76d58be8a5a&format=json&language=en-us&aka=0&business=0&seasons=0&seasonYear=0&technical=0&trailer=0&movieTrivia=0&awards=0&moviePhotos=0&movieVideos=0&actors=0&biography=0&uniqueName=0&filmography=0&bornAndDead=0&starSign=0&actorActress=0&actorTrivia=0&similarMovies=0";
        $json = file_get_contents($myApiFilmsUrl);
        $data = json_decode($json, true);
        //true for array format
        if (IsEmpty($plot)) {
            $plot = mysqli_real_escape_string($conn, $data['data']['movies'][0]['plot']);
        }
        $imdbLink = $data['data']['movies'][0]['urlIMDB'];
        if (IsEmpty($poster)) {
            $poster = $data['data']['movies'][0]['urlPoster'];
            //$poster = 'http://ia.media-imdb.com/images/M/MV5BMTAzNjU4MzYwNDdeQTJeQWpwZ15BbWU4MDg3NTEzMjcx._V1_SY317_CR0,0,214,317_AL_.jpg';
        }
        echo "poster is" . IsEmpty($poster);
        if (!IsEmpty($poster)) {
            //download
            echo "download poster";
            downloadPoster($movieId, $poster);
        }
    }
    $subtitleLink = 'http://www.opensubtitles.org/en/search2/sublanguageid-all/moviename-' . $movieId;
    //cant find
    $tomatoLink = "";
    $tmdbLink = "";
    $youtubeLink = "";
    if (IsEmpty($movieId)) {
        return;
    }
    $title = mysqli_real_escape_string($conn, $title);
    $movieInfoInsertQuery = "INSERT INTO `movieinfo` (`movieId`, `rated`, `releaseDate`, `runtime`, `genre`, `director`, `writer`, `actors`, `plot`, `language`, `country`, `awards`, `poster`, `boxOffice`, `Website`, `Screenshots`) VALUES ('{$movieId}', '{$rated}', '{$releaseDate}', '{$runtime}', '{$genre}', '{$director}', '{$writer}', '{$actors}', '{$plot}', '{$language}', '{$country}', '{$awards}', '{$poster}', '{$boxOffice}', '{$website}', '{$boxOffice}')";
    $movieNameInsertQuery = "INSERT INTO `moviename` (`movieId`, `name`) VALUES ('{$movieId}', '{$title}')";
    $imdbInsertQuery = "INSERT INTO `imdb` (`movieId`, `metaCriticScore`, `imdbRating`, `imdbVotes`, `imdbID`) VALUES ('{$movieId}', '{$metascore}', '{$imdbRating}', '{$imdbVotes}', '{$imdbID}')";
    $linksInsertQuery = "INSERT INTO `links` (`movieId`, `youtubeLink`, `imdbLink`, `tomatoLink`, `subtitleLink`) VALUES ('{$movieId}', '{$youtubeLink}', '{$imdbLink}', '{$tomatoLink}','{$subtitleLink}')";
    $tomatoInsertQuery = "INSERT INTO `tomato` (`movieId`,`tomatoMeter`, `tomatoImage`, `tomatoRating`, `tomatoReviews`, `tomatoFresh`, `tomatoRotten`, `tomatoUserMeter`,`tomatoUserRating`, `tomatoUserReviews`) VALUES ('{$movieId}', '{$tomatoMeter}', '{$tomatoImage}', '{$tomatoRating}', '{$tomatoReviews}', '{$tomatoFresh}', '{$tomatoRotten}','{$tomatoUserMeter}', '{$tomatoUserRating}', '{$tomatoUserReviews}')";
    mysqli_query($conn, $movieInfoInsertQuery) or die(mysqli_error($conn));
    echo "info d  ";
    mysqli_query($conn, $movieNameInsertQuery) or die(mysqli_error($conn));
    echo "name d  ";
    mysqli_query($conn, $imdbInsertQuery) or die(mysqli_error($conn));
    echo "imdb d  ";
    mysqli_query($conn, $linksInsertQuery) or die(mysqli_error($conn));
    echo "links d  ";
    mysqli_query($conn, $tomatoInsertQuery) or die(mysqli_error($conn));
    echo "tomato d <br>";
}
예제 #2
0
function updateMovie()
{
    set_time_limit(7200);
    require "../includes/connect.php";
    require "../functions/string.php";
    $selectQuery = "SELECT * FROM `imdb`";
    $selectResult = mysqli_query($conn, $selectQuery) or die(mysqli_error($conn));
    while ($row = mysqli_fetch_array($selectResult)) {
        $movieId = $row['movieId'];
        //$movieId = "Dragonheart+3:+The+Sorcerer's+Curse";
        $imdbID = $row['imdbID'];
        //$imdbID = "tt2974918";
        //$movieId = "Alvin+and+the+Chipmunks:+The+Road+Chip";
        echo "updating id  :" . $imdbID . " ";
        if (IsEmpty($imdbID) || IsEmpty($movieId)) {
            continue;
        }
        $movieInfoQuery = "SELECT * FROM `movieinfo` WHERE movieId =  '" . mysql_real_escape_string($movieId) . "'";
        //escape as id may have apostrophe
        $movieInfoResult = mysqli_query($conn, $movieInfoQuery) or die(mysqli_error($conn));
        $movieInfoRow = mysqli_fetch_array($movieInfoResult);
        //if(IsEmpty($movieInfoRow['movieId'])){
        //	continue;
        //}
        echo "getting omdb for  " . $movieId . ", ";
        //@ to suppress warnings and notices...
        /*OMDB API -DOESNT EXIST FOR ALL MOVIES*/
        $omdbXml = @simplexml_load_file("http://www.omdbapi.com/?t=" . urlencode($movieId) . "&plot=full&r=xml&tomatoes=true");
        echo "omdb is  http://www.omdbapi.com/?t=" . urlencode($movieId) . "&plot=full&r=xml&tomatoes=true  , ";
        $poster = "";
        $metascore = "";
        $imdbRating = "";
        $imdbVotes = "";
        //$imdbID = "";
        $runtime = "";
        $plot = "";
        $releaseDate = "";
        $rated = "";
        $genre = "";
        $director = "";
        $writer = "";
        $language = "";
        $country = "";
        $actors = "";
        $website = "";
        $boxOffice = "";
        $awards = "";
        $tomatoMeter = "";
        $tomatoImage = "";
        $tomatoRating = "";
        $tomatoReviews = "";
        $tomatoFresh = "";
        $tomatoRotten = "";
        $tomatoUserMeter = "";
        $tomatoUserRating = "";
        $tomatoUserReviews = "";
        $imdbLink = "";
        //echo $omdbXml->attributes()->response;
        if (@$omdbXml->root['response'] == "False") {
            echo "movie not found in omdb";
            // throw new Exception("Cannot load xml source.\n");
            $poster = "";
            $metascore = "";
            $imdbRating = "";
            $imdbVotes = "";
            //$imdbID = "";
            $runtime = "";
            $plot = "";
            $releaseDate = "";
            $rated = "";
            $genre = "";
            $rated = "";
            $genre = "";
            $director = "";
            $writer = "";
            $language = "";
            $country = "";
            $actors = "";
            $website = "";
            $boxOffice = "";
            $awards = "";
            $tomatoMeter = "";
            $tomatoImage = "";
            $tomatoRating = "";
            $tomatoReviews = "";
            $tomatoFresh = "";
            $tomatoRotten = "";
            $tomatoUserMeter = "";
            $tomatoUserRating = "";
            $tomatoUserReviews = "";
            $imdbLink = "";
        } else {
            //$genre = $omdbXml->movie['genre'];
            $director = mysql_real_escape_string(htmlentities(@$omdbXml->movie['director']));
            //$releaseDate = $omdbXml->movie['released'];
            $writer = mysql_real_escape_string(htmlentities(@$omdbXml->movie['writer']));
            $language = @$omdbXml->movie['language'];
            $country = @$omdbXml->movie['country'];
            $actors = mysql_real_escape_string(htmlentities(@$omdbXml->movie['actors']));
            $website = @$omdbXml->movie['Website'];
            $boxOffice = @$omdbXml->movie['boxOffice'];
            $awards = @$omdbXml->movie['awards'];
            //omdb tomato
            $tomatoMeter = @$omdbXml->movie['tomatoMeter'];
            $tomatoImage = @$omdbXml->movie['tomatoImage'];
            $tomatoRating = @$omdbXml->movie['tomatoRating'];
            $tomatoReviews = @$omdbXml->movie['tomatoReviews'];
            $tomatoFresh = @$omdbXml->movie['tomatoFresh'];
            $tomatoRotten = @$omdbXml->movie['tomatoRotten'];
            $tomatoUserMeter = @$omdbXml->movie['tomatoUserMeter'];
            $tomatoUserRating = @$omdbXml->movie['tomatoUserRating'];
            $tomatoUserReviews = @$omdbXml->movie['tomatoUserReviews'];
            $metascore = @$omdbXml->movie['metascore'];
            $imdbRating = @$omdbXml->movie['imdbRating'];
            $imdbVotes = @$omdbXml->movie['imdbVotes'];
            //$imdbID = @$omdbXml->movie['imdbID'];
            $runtime = @$omdbXml->movie['runtime'];
            $plot = mysql_real_escape_string(@$omdbXml->movie['plot']);
            $releaseDate = @$omdbXml->movie['releaseDate'];
            $rated = @$omdbXml->movie['rated'];
            $genre = @$omdbXml->movie['genre'];
            $poster = @$omdbXml->movie['poster'];
            $imdbLink = "";
        }
        $myApiFilmsUrl = "http://api.myapifilms.com/imdb/idIMDB?idIMDB=" . $imdbID . "&token=870c3596-fa05-4ced-82cf-a76d58be8a5a&format=json&language=en-us&aka=0&business=0&seasons=0&seasonYear=0&technical=0&trailer=0&movieTrivia=0&awards=0&moviePhotos=0&movieVideos=0&actors=0&biography=0&uniqueName=0&filmography=0&bornAndDead=0&starSign=0&actorActress=0&actorTrivia=0&similarMovies=0";
        //echo $myApiFilmsUrl."<br>";
        $json = file_get_contents($myApiFilmsUrl);
        $data = json_decode($json, true);
        //true for array format
        //print_r($data);
        if (IsEmpty($plot)) {
            $plot = mysql_real_escape_string($data['data']['movies'][0]['plot']);
        }
        $imdbLink = $data['data']['movies'][0]['urlIMDB'];
        if (IsEmpty($poster)) {
            $poster = $data['data']['movies'][0]['urlPoster'];
            //$poster = 'http://ia.media-imdb.com/images/M/MV5BMTAzNjU4MzYwNDdeQTJeQWpwZ15BbWU4MDg3NTEzMjcx._V1_SY317_CR0,0,214,317_AL_.jpg';
        }
        //echo "poster is".IsEmpty($poster);
        if (!IsEmpty($poster)) {
            //download
            if (IsEmpty($movieInfoRow['poster'])) {
                echo "download poster for update<br>";
                downloadPoster($movieId, $poster);
            }
        }
        //$plot = "plesase.";
        $subtitleLink = 'http://www.opensubtitles.org/en/search2/sublanguageid-all/moviename-' . $movieId;
        //cant find
        $tomatoLink = "";
        $tmdbLink = "";
        $youtubeLink = "";
        echo " --inserting...-";
        $movieInfoInsertQuery = "UPDATE `movieinfo` SET \n\t\t\t\trated = IF(LENGTH(rated)=0, '{$rated}', rated),\n\t\t\t\treleaseDate = IF(LENGTH(releaseDate)=0, '{$releaseDate}', releaseDate),\n\t\t\t\truntime = IF(LENGTH(runtime)=0, '{$runtime}', runtime),\n\t\t\t\tgenre = IF(LENGTH(genre)=0, '{$genre}', genre),\n\t\t\t\tdirector = IF(LENGTH(director)=0, '{$director}', director),\n\t\t\t\twriter = IF(LENGTH(writer)=0, '{$writer}', writer),\n\t\t\t\tactors = IF(LENGTH(actors)=0, '{$actors}', actors),\n\t\t\t\tplot = IF(LENGTH(plot)=0, '{$plot}', plot),\n\t\t\t\tlanguage = IF(LENGTH(language)=0, '{$language}', language),\n\t\t\t\tcountry = IF(LENGTH(country)=0, '{$country}', country),\n\t\t\t\tawards = IF(LENGTH(awards)=0, '{$awards}', awards),\n\t\t\t\tposter = IF(LENGTH(poster)=0, '{$poster}', poster),\n\t\t\t\tboxOffice = IF(LENGTH(boxOffice)=0, '{$boxOffice}', boxOffice),\n\t\t\t\tWebsite = IF(LENGTH(Website)=0, '{$website}', Website)\n\t\t\t\tWHERE movieId = '" . mysql_real_escape_string($movieId) . "'";
        echo $movieInfoInsertQuery;
        /*$movieInfoInsertQuery = "UPDATE `movieinfo` SET 
        		`rated` = IF(`rated` IS NULL, '$rated', `rated`),
        		`releaseDate` = '$releaseDate',
        		`runtime` = '$runtime', 
        		`genre` = '$genre', 
        		`director` = '$director', 
        		`writer` = '$writer', 
        		`actors` = '$actors', 
        		`plot` = '$plot', 
        		`language` = '$language', 
        		`country` = '$country', 
        		`awards` = '$awards', 
        		`poster` = '$poster', 
        		`boxOffice` = '$boxOffice', 
        		`Website` = '$website'
        		WHERE `movieId = '$movieId'";*/
        $tomatoInsertQuery = "UPDATE `tomato` SET \n\t\t\t\ttomatoMeter = '{$tomatoMeter}',\n\t\t\t\ttomatoImage = '{$tomatoImage}',\n\t\t\t\ttomatoRating = '{$tomatoRating}', \n\t\t\t\ttomatoReviews = '{$tomatoReviews}', \n\t\t\t\ttomatoFresh = '{$tomatoFresh}', \n\t\t\t\ttomatoRotten = '{$tomatoRotten}', \n\t\t\t\ttomatoUserMeter = '{$tomatoUserMeter}', \n\t\t\t\ttomatoUserRating = '{$tomatoUserRating}', \n\t\t\t\ttomatoUserReviews = '{$tomatoUserReviews}' \n\t\t\t\tWHERE movieId = '" . mysql_real_escape_string($movieId) . "'";
        $linksInsertQuery = "UPDATE `links` SET \n\t\t\t\timdbLink = '{$imdbLink}'\n\t\t\t\tWHERE movieId = '" . mysql_real_escape_string($movieId) . "'";
        $imdbInsertQuery = "UPDATE `imdb` SET \n\t\t\t\tmetaCriticScore = '{$metascore}'\n\t\t\t\tWHERE movieId = '" . mysql_real_escape_string($movieId) . "'";
        if (IsEmpty($movieInfoRow['poster'])) {
            $posterQuery = "UPDATE `movieinfo` SET \n\t\t\t\t\t\tposter = '{$poster}'\n\t\t\t\t\t\tWHERE movieId = '" . mysql_real_escape_string($movieId) . "'";
            mysqli_query($conn, $posterQuery) or die(mysqli_error($conn));
        }
        if (!mysqli_query($conn, $movieInfoInsertQuery)) {
            die('Error: ' . mysqli_error($conn));
        }
        echo "movieinfo updated,  ";
        if (!mysqli_query($conn, $tomatoInsertQuery)) {
            die('Error: ' . mysqli_error($conn));
        }
        echo "tomato updated,  ";
        if (!mysqli_query($conn, $linksInsertQuery)) {
            die('Error: ' . mysqli_error($conn));
        }
        echo "links updated,  ";
        if (!mysqli_query($conn, $imdbInsertQuery)) {
            die('Error: ' . mysqli_error($conn));
        }
        echo "imdb updated,  ";
        echo "<br>";
        /*mysqli_query($conn, $movieInfoInsertQuery) or die(mysqli_error($conn));
        
        	          mysqli_query($conn, $imdbInsertQuery)or die(mysqli_error($conn));
        	          mysqli_query($conn, $linksInsertQuery)or die(mysqli_error($conn));
        	          mysqli_query($conn, $tomatoInsertQuery)or die(mysqli_error($conn));*/
    }
}
예제 #3
0
function getRecent()
{
    require "../includes/connect.php";
    //require("../functions/string.php");
    /*
    	find title of each recently released movie then put into omdb
    */
    //xml
    /*<RESPONSE_DATA>
    	    <FILE_INFORMATION Order_Number="19222835">
    
    	    response_data->file_information['Order_Number']
    	*/
    $xml = simplexml_load_file("http://api.myapifilms.com/imdb/inTheaters?token=870c3596-fa05-4ced-82cf-a76d58be8a5a&format=xml&language=en-us");
    //the "recently released" date
    $date = htmlentities($xml->data->movies->date);
    $trim = trim(str_replace(" ", "", $date));
    $trim = str_replace("&nbsp;", "", $trim);
    //$rest = substr("abcdef", -1);    // returns "f"
    $day = substr($trim, -2);
    $month = substr($trim, 0, 3);
    $year = date("Y");
    //echo $date;
    global $formattedRecentDate;
    $formattedRecentDate = $day . " " . $month . " " . $year;
    //echo $formattedRecentDate;
    //store formatted date for use in recent.php so you dont have to keep calling api
    $newFileName = '../includes/recentDate.txt';
    $appendContent = $formattedRecentDate;
    //If filename does not exist, the file is created. Otherwise, the existing file is overwritten, unless the FILE_APPEND flag is set.
    if (file_put_contents($newFileName, $appendContent) != false) {
        echo "File created (" . basename($newFileName) . ")";
    } else {
        echo "Cannot create file (" . basename($newFileName) . ")";
    }
    $zeroOrOne;
    //for($zeroOrOne=0; $zeroOrOne <=1; $zeroOrOne++){
    for ($zeroOrOne = 0; $zeroOrOne <= 0; $zeroOrOne++) {
        //use this to skip first row (blank)
        $b = false;
        //movies[0] is the array for recently released, [1] is in theatres now
        foreach ($xml->data->movies[$zeroOrOne] as $movie) {
            if (!$b) {
                $b = true;
                continue;
            }
            //insert to omdb if not already found
            //rating is imdb rating
            $title = htmlentities($movie->title);
            echo $title . "<br>";
            if (empty($title)) {
                continue;
            }
            //echo $title .'<br>';
            $selectQuery = "SELECT movieId FROM moviename";
            $selectResult = mysqli_query($conn, $selectQuery);
            $exists = 0;
            while ($row = mysqli_fetch_array($selectResult)) {
                if (fuzzy_match($title, $row['movieId'])) {
                    $exists = 1;
                    break;
                }
            }
            if ($exists == 1) {
                if ($zeroOrOne == 1) {
                    $movieId = str_replace(" ", "+", $title);
                    $theatreInsertQurey = "INSERT INTO `intheatres` (`movieId`) VALUES ('{$movieId}')";
                    mysqli_query($conn, $theatreInsertQurey) or die(mysqli_error($conn));
                }
                continue;
            } else {
                //print("not found");
                //insert
                /*MYAPIFILMS*/
                //format is 20151113
                if ($zeroOrOne == 0) {
                    $releaseDate = $formattedRecentDate;
                } else {
                    if ($zeroOrOne == 1) {
                        //format is 20151113
                        $releaseDate = $movie->releaseDate;
                        $day = substr($releaseDate, -2);
                        $monthNum = substr($releaseDate, 5, 6);
                        $monthName = date("F", mktime(0, 0, 0, $monthNum, 15));
                        $month = substr($monthName, 0, 3);
                        $year = substr($releaseDate, 0, 4);
                        $releaseDate = $day . " " . $month . " " . $year;
                    }
                }
                //movieId
                $movieId = mysqli_real_escape_string($conn, str_replace(" ", "+", $title));
                //rated
                $rated = htmlentities($movie->rated);
                //runtime
                $runtime = htmlentities($movie->runtime);
                //plot
                $plot = mysqli_real_escape_string($conn, htmlentities($movie->plot));
                //poster
                $poster = $movie->urlPoster;
                echo $poster . "<br>";
                //download
                downloadPoster($movieId, $poster);
                //imdblink
                $imdbLink = $movie->urlIMDB;
                $metascore = substr($movie->metascore, 0, -4);
                $imdbRating = $movie->rating;
                $imdbVotes = $movie->votes;
                $imdbID = $movie->idIMDB;
                try {
                    //genre
                    $genreList = "";
                    foreach ((array) $movie->genres->genre as $genre) {
                        $temp = (string) $genre;
                        $genreList = $genreList . $temp . " ";
                    }
                    $genreList = trim($genreList);
                    $genre = $genreList;
                } catch (Exception $e) {
                    //echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }
                if (IsEmpty($movieId)) {
                    continue;
                }
                //@ to suppress warnings and notices...
                /*OMDB API -DOESNT EXIST FOR ALL MOVIES*/
                $omdbXml = @simplexml_load_file("http://www.omdbapi.com/?t=" . $movieId . "&y=" . $year . "&plot=full&r=xml&tomatoes=true");
                $director = "";
                $writer = "";
                $language = "";
                $country = "";
                $actors = "";
                $website = "";
                $boxOffice = "";
                $awards = "";
                $tomatoMeter = "";
                $tomatoImage = "";
                $tomatoRating = "";
                $tomatoReviews = "";
                $tomatoFresh = "";
                $tomatoRotten = "";
                $tomatoUserMeter = "";
                $tomatoUserRating = "";
                $tomatoUserReviews = "";
                if (@$omdbXml->root['response'] == "False") {
                    // throw new Exception("Cannot load xml source.\n");
                    $director = "";
                    $writer = "";
                    $language = "";
                    $country = "";
                    $actors = "";
                    $website = "";
                    $boxOffice = "";
                    $awards = "";
                    $tomatoMeter = "";
                    $tomatoImage = "";
                    $tomatoRating = "";
                    $tomatoReviews = "";
                    $tomatoFresh = "";
                    $tomatoRotten = "";
                    $tomatoUserMeter = "";
                    $tomatoUserRating = "";
                    $tomatoUserReviews = "";
                } else {
                    //$genre = $omdbXml->movie['genre'];
                    $director = @$omdbXml->movie['director'];
                    //$releaseDate = $omdbXml->movie['released'];
                    $writer = @$omdbXml->movie['writer'];
                    $language = @$omdbXml->movie['language'];
                    $country = @$omdbXml->movie['country'];
                    $actors = @$omdbXml->movie['actors'];
                    $website = @$omdbXml->movie['Website'];
                    $boxOffice = @$omdbXml->movie['boxOffice'];
                    $awards = @$omdbXml->movie['awards'];
                    //omdb tomato
                    $tomatoMeter = @$omdbXml->movie['tomatoMeter'];
                    $tomatoImage = @$omdbXml->movie['tomatoImage'];
                    $tomatoRating = @$omdbXml->movie['tomatoRating'];
                    $tomatoReviews = @$omdbXml->movie['tomatoReviews'];
                    $tomatoFresh = @$omdbXml->movie['tomatoFresh'];
                    $tomatoRotten = @$omdbXml->movie['tomatoRotten'];
                    $tomatoUserMeter = @$omdbXml->movie['tomatoUserMeter'];
                    $tomatoUserRating = @$omdbXml->movie['tomatoUserRating'];
                    $tomatoUserReviews = @$omdbXml->movie['tomatoUserReviews'];
                }
                $myApiFilmsUrl = "http://api.myapifilms.com/imdb/idIMDB?idIMDB=" . $imdbID . "&token=870c3596-fa05-4ced-82cf-a76d58be8a5a&format=json&language=en-us&aka=0&business=0&seasons=0&seasonYear=0&technical=0&trailer=0&movieTrivia=0&awards=0&moviePhotos=0&movieVideos=0&actors=0&biography=0&uniqueName=0&filmography=0&bornAndDead=0&starSign=0&actorActress=0&actorTrivia=0&similarMovies=0";
                $json = file_get_contents($myApiFilmsUrl);
                $data = json_decode($json, true);
                //true for array format
                if (IsEmpty($plot)) {
                    $plot = mysqli_real_escape_string($conn, $data['data']['movies'][0]['plot']);
                }
                $imdbLink = $data['data']['movies'][0]['urlIMDB'];
                if (IsEmpty($poster)) {
                    $poster = $data['data']['movies'][0]['urlPoster'];
                }
                if (!IsEmpty($poster)) {
                    //download
                    downloadPoster($movieId, $poster);
                }
                $subtitleLink = 'http://www.opensubtitles.org/en/search2/sublanguageid-all/moviename-' . $movieId;
                //cant find
                $tomatoLink = "";
                $tmdbLink = "";
                $youtubeLink = "";
                $movieInfoInsertQuery = "INSERT INTO `movieinfo` (`movieId`, `rated`, `releaseDate`, `runtime`, `genre`, `director`, `writer`, `actors`, `plot`, `language`, `country`, `awards`, `poster`, `boxOffice`, `Website`, `Screenshots`) VALUES ('{$movieId}', '{$rated}', '{$releaseDate}', '{$runtime}', '{$genre}', '{$director}', '{$writer}', '{$actors}', '{$plot}', '{$language}', '{$country}', '{$awards}', '{$poster}', '{$boxOffice}', '{$website}', '{$boxOffice}')";
                $movieNameInsertQuery = "INSERT INTO `moviename` (`movieId`, `name`) VALUES ('{$movieId}', '{$title}')";
                $imdbInsertQuery = "INSERT INTO `imdb` (`movieId`, `metaCriticScore`, `imdbRating`, `imdbVotes`, `imdbID`) VALUES ('{$movieId}', '{$metascore}', '{$imdbRating}', '{$imdbVotes}', '{$imdbID}')";
                $linksInsertQuery = "INSERT INTO `links` (`movieId`, `youtubeLink`, `imdbLink`, `tomatoLink`, `subtitleLink`) VALUES ('{$movieId}', '{$youtubeLink}', '{$imdbLink}', '{$tomatoLink}','{$subtitleLink}')";
                $tomatoInsertQuery = "INSERT INTO `tomato` (`movieId`,`tomatoMeter`, `tomatoImage`, `tomatoRating`, `tomatoReviews`, `tomatoFresh`, `tomatoRotten`, `tomatoUserMeter`,`tomatoUserRating`, `tomatoUserReviews`) VALUES ('{$movieId}', '{$tomatoMeter}', '{$tomatoImage}', '{$tomatoRating}', '{$tomatoReviews}', '{$tomatoFresh}', '{$tomatoRotten}','{$tomatoUserMeter}', '{$tomatoUserRating}', '{$tomatoUserReviews}')";
                if ($zeroOrOne == 1) {
                    $theatreInsertQurey = "INSERT INTO `intheatres` (`movieId`) VALUES ('{$movieId}')";
                    mysqli_query($conn, $theatreInsertQurey) or die(mysqli_error($conn));
                }
                mysqli_query($conn, $movieInfoInsertQuery) or die(mysqli_error($conn));
                mysqli_query($conn, $movieNameInsertQuery) or die(mysqli_error($conn));
                mysqli_query($conn, $imdbInsertQuery) or die(mysqli_error($conn));
                mysqli_query($conn, $linksInsertQuery) or die(mysqli_error($conn));
                mysqli_query($conn, $tomatoInsertQuery) or die(mysqli_error($conn));
            }
        }
    }
}