Search code examples
javascriptphpjqueryjsonimdb

Integrate an image to movie titles in IMDb Suggest autocomplete


I was searching for a way to integrate movie images to their titles in my jQuery auto-complete text-box in my form, and I found IMDb Suggest quite useful. It works perfectly, but the only problem that I noticed is that it returns movie titles, TV-series, actors, directors, etc.. while I ONLY need MOVIE TITLES.

Question:

Is there a way to get only movie titles integrating with their image in my auto-complete text-box (Not TV-series, Not actors, ..)? (I mean I want to disable auto-complete feature for actors, Series, etc., so if user typed "Tom.." in the search-box, it shouldn't show "Tom Criuse"..)

PS. If it is not possible, How can I show small image of movies when user types a movie name in auto-complete text-box? I have crawled IMDb poster links of movies and saved them in my database. (I saw This similar question, but actually, It didn't use images stored in DB which is my case)

UPDATE:

In order to avoid TV-series, I crawled list of IMDb movie titles and saved them in my DB. I am trying to compare the string that user enters with the titles in my DB, ao if no match were found it means it is not a movie and it might be g.g., TV-series..

Here is what I changed in suggest.php:

if(isset($arr['d'])){
  foreach($arr['d'] as $d){
           try{
              include('imdbconnection.php');
              $stmt = $conn->prepare("SELECT movieName FROM featuredfilms_EN WHERE movieName = :term");
              $stmt->bindValue(':term', $d['l']);
              $stmt->execute();
              $result = $stmt->fetch(PDO::FETCH_OBJ);

             if (!empty($result)) {

            $img = preg_replace('/_V1_.*?.jpg/ms', "_V1._SY50.jpg", $d['i'][0]);

                if ((strpos($d['s'], "Actor,") === false) {
                       $s[] = array('label' => $d['l'], 'value' => $d['id'], 'cast' => $d['s'], 'img' => $img, 'q' => $d['q']);
                       }   
                 //REST OF THE CODE 

However, it does not work :|


Solution

  • Set condition (Actor, Tv-series, Directors and writers) & filter the results in suggestion page (Line #23)

    if (strpos($d['s'], "Actor,") === false) { // Here avoiding all actors
    $s[] = array('label' => $d['l'], 'value' => $d['id'], 'cast' => $d['s'], 'img' => $img, 'q' => $d['q']);
    }