How to make a rich movie search interface with instant trailers

Today a quick post to show you a new feature I rolled out last week on sharemovi.es: #nw or Now Watching. Go check it out here. In this post some printscreens and a what technologies I used

rich autocomplete

More on the technology behind it

When you start to type a movie name it queries themoviedb.org API for movie info. The API seems quite complete and the response it fast. I thought name, poster, year, rating and short summary extract would be most relevant … and … the trailer. You see the red youtube button? Well … when you hover with your mouse over the whole row, the trailer loads in the white box. All thanks to some jQuery – see the JS code; in order to not make too many calls to themoviedb.org API, I use YQL to dynamically look up the trailer. You can also use Gdata/ Youtube.

featured image

I use an autocomplete box from the jQuery UI, it comes with some nice styles incorporated. I rolled my own loader gif, but the real workhorses are PHP and jQuery, a powerful duo.

The ‘autocomplete’ function polls the API via search.php upon detected key strokes. I had to play a bit with ‘renderItem’ to show a rich result (poster, etc). Upon ‘select’ of a title, comment.php is called to generate a customized form with message and share buttons. The field is readonly (not editable), but clicking on the pencil, jQuery takes the readonly attribute off (removeAttr) so you can edit it.

I didn’t include Twitter / Facebook APIs, just a link to the corresponding page with the right URL parameters. With FB dialogs you can give quite some options and it does not require authorization because the user has to submit the info anyway. The links get created in the .submit .. ‘click’ function (note the encodeURIComponent). A richer experience is using one of the APIs. As sharemovi.es has the FB API setup already, I will definitely build this in. I will also integrate this richer experience into sharemovi.es as a whole. I’d like movies to be added to sharemovi.es this way, manual or automagically.

Note the live function in the jQuery code: when you add new content without page refresh (Ajax), your JS needs to be made aware that that content is there, this is what ‘live’ is for.

Now the trailer bit: ‘mouseenter’ and ‘mouseleave’ are the functions responsible for loading/ hiding the trailer for each title. You see another $.post, but now to youtube.php which as said uses YQL to find the corresponding movie trailer. And it returns an iframe that fits nicely in the white mini-canvas.

So step-by-step:

1. Go to sharemovi.es/nw/ (or at the homepage click on “Now Watching” to use the embedded version).

2. Start to type a movie, you should see titles approximating what you type:

trailer autocomplete

3. When you hover over the row, you should see a trailer starting to play:

trailer playing

4. When you click on one of the movies, a share box slides down with a proposed text.

share box

5. Example of clicking Facebook button (I put the text “want to see this one” in as addition)
fb button

6. Same for twitter, however I clicked the pencil which made the field editable:
edit button clicked

7. And the result shown on Twitter before posting. Again with APIs this can all be slicker but I wanted an easy standalone example:
share on twitter

Update 18.01.2012

The complete source code is posted here. Enjoy … and please leave me a comment if you use it somewhere …


You might also like:



Enjoyed this article?

Share on Google+

This entry was posted in Jquery, Work in progress. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • Angie Stropp

    Very cool! :o)

  • Muffins_cucpake

    really nice well done :D can you send the whole php so i can learn from it and how it works thnx 
    email is muffins_cupcake@hotmail.com

    • http://bobbelderbos.com/ Bob Belderbos

      OK I will send you the php

      • Muffins_cucpake

        thank you so much! i really appreciate the help :DDD thumbs up :D

        • http://bobbelderbos.com/ Bob Belderbos

          you are welcome. let me know if you have any further questions or new ideas / inspirations …

          • Iluvcoding

            hey sorry to bother again, but what do you mean by: 
            wrapper (glamorous) under lib/

          • http://bobbelderbos.com/ Bob Belderbos

            You need to use that code to make the sample work, it’s basically an API / (php wrapper) to communicate with themoviedb.org API

          • Anonymous

            Hey Bob can I get the copy of the code!
            At virendra.rajput567@gmail.com

          • http://bobbelderbos.com/ Bob Belderbos

            will send it later this week

          • Anonymous

            OK

          • http://bobbelderbos.com/ Bob Belderbos
  • http://bobbelderbos.com/ Bob Belderbos

    will post it in a comment when I can

  • http://bobbelderbos.com/ Bob Belderbos
  • Links

  • Post categories

  • Bob’s Reading List

  • My Facebook Apps

    hi folks, what are you reading?

    sharemovi.es: tell your friends about your favorite movies

    Friends Jukebox | Create a Jukebox based on the Music your Friends like!