Click here to Skip to main content
15,883,929 members
Articles / Programming Languages / C++
Article

CIMDBSearch Class

Rate me:
Please Sign up or sign in to vote.
4.29/5 (6 votes)
6 Jun 2008CPOL2 min read 43K   902   18   15
An article on a simple C++ IMDB search class
CIMDBSearch_project_screenshot.jpg

Introduction

This article is about a simple C++ class that can be used to search for movie information from the IMDB Web site. The IMDB Web site is organized as the free online service that offers detailed information about movies, series, actors etc. Please see more about it using this link. IMDB - Internet Movie Database is also a database system, so many applications are using this way of providing information to extract the details about movies, series, actors, filming locations, etc.

Background

The basic idea was to write a C++ class with a very simple interface to IMDB. I have found one or two .NET classes on SourceForge, but no implementation in C++. So, I have decided to give a small contribution to the world-wide C++ community. Also, for anyone that is developing a software for movie catalogisation, this class could be interesting.

Using the Code

To use the CIMDBSearch class, add IMDBSearch.h and IMDBSearch.cpp files to your project. Using few simple static methods of this class, you can extract information about the movie you are looking for on IMDB, see below:

C++
#include "IMDBSearch.h"

// Search IMDB database
if (CIMDBSearch::SearchIMDB(_T("Enter a searching keyword here..."), ST_TITLES_EXACT))
{
    // Get number of search results
    int iNumberResults = CIMDBSearch::GetSearchCount();
    for (int i=0; i<iNumberResults; i++)
    {
        // Get search item
        LPSEARCH_INFO lpSearchItem = CIMDBSearch::GetSearchItem(i);
    }
}

The previous code snippet will get you a list of the exact title matching inside the IMDB database. To get all possible titles, use the flag ST_TITLES_PARTIAL instead of the ST_TITLES_EXACT flag. The IMDB Web site returns different lists of titles during its search. One is Titles (Exact Matching), and the other one is Titles (Partial Matching). This flags support data extraction from these lists.

The definition of the SEARCH_INFO structure is the following:

C++
typedef struct _SEARCH_INFO
{
    _TCHAR szPath[256];        // IMDB Web page with the movie details
    _TCHAR szTitle[256];       // The title of the movie
    _TCHAR szYear[256];        // Year the movie was filmed

} SEARCH_INFO, *LPSEARCH_INFO;

To get the movie details, see the following:

C++
// Get movie details
int item = 0;
LPMOVIE_INFO lpMovieInfo = NULL;
if ((lpMovieInfo=CIMDBSearch::GetMovieInfo(item)))
{
}

The definition of the MOVIE_INFO structure is the following:

C++
typedef struct _MOVIE_INFO
{
    _TCHAR szUserRating[256];        // The movie user rating
    _TCHAR szDirector[256];          // The director
    _TCHAR szWriter[256];            // The writer
    _TCHAR szReleaseDate[256];       // First release date
    _TCHAR szGenre[256];             // The movie genre
    _TCHAR szPlot[1024];             // A short description
    _TCHAR szAwards[256];            // The awards
    _TCHAR szUserComments[1024];     // User comments
    _TCHAR szRuntime[256];           // The length of the movie
    _TCHAR szCountry[256];           // The movie production country
    _TCHAR szLanguage[256];          // The movie language
    _TCHAR szColor[256];             // Color system
    _TCHAR szAspectRatio[256];       // Picture aspect ratio
    _TCHAR szSoundMix[256];          // The sound quality
    _TCHAR szFilmingLocations[256];   // Filming locations
    _TCHAR szCompany[256];           // The movie production company
    _TCHAR szPoster[256];            // The link to the movie poster
                                     // (.JPEG image generally)
    _TCHAR szCast[15][256];          // The movie cast

} MOVIE_INFO, *LPMOVIE_INFO;

The last thing to do is to clear the memory by calling the CIMDBSearch::Clear() method before you exit your application.

Points of Interest

I was very interested in extracting the information from the IMDB Web site, since many popular movie catalogisation software use this free Web service to collect the details considering different movies when building home-made digital movie collections.

History

  • 6th June, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

Comments and Discussions

 
GeneralVB.net Version Pin
CeremBeyazit24-Apr-10 5:54
CeremBeyazit24-Apr-10 5:54 
GeneralCIMDBSearch is no longer running Pin
Superball Dadada2-May-09 2:03
Superball Dadada2-May-09 2:03 
GeneralCompile Errors Pin
rmk1139019-Oct-08 2:06
rmk1139019-Oct-08 2:06 
GeneralRe: Compile Errors Pin
darkoman19-Oct-08 3:14
darkoman19-Oct-08 3:14 
GeneralAdded Popular Titles to Search Modus Pin
Klimpi8311-Aug-08 4:38
Klimpi8311-Aug-08 4:38 
GeneralRe: Added Popular Titles to Search Modus Pin
darkoman12-Aug-08 21:39
darkoman12-Aug-08 21:39 
GeneralImage Pin
David Crow10-Jun-08 2:48
David Crow10-Jun-08 2:48 
The image is not rendering properly on either 1024x768 or 1152x864. It's too small in both cases.

"Love people and use things, not love things and use people." - Unknown

"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne


GeneralRe: Image Pin
darkoman10-Jun-08 20:41
darkoman10-Jun-08 20:41 
GeneralRe: Image Pin
David Crow11-Jun-08 3:08
David Crow11-Jun-08 3:08 
GeneralRe: Image Pin
darkoman11-Jun-08 20:13
darkoman11-Jun-08 20:13 
QuestionRe: Image Pin
David Crow12-Jun-08 2:27
David Crow12-Jun-08 2:27 
AnswerRe: Image Pin
darkoman12-Jun-08 7:59
darkoman12-Jun-08 7:59 
GeneralRe: Image Pin
David Crow12-Jun-08 8:08
David Crow12-Jun-08 8:08 
GeneralFreeImage Library Pin
Michael Rusakow9-Jun-08 23:12
Michael Rusakow9-Jun-08 23:12 
GeneralRe: FreeImage Library Pin
darkoman10-Jun-08 0:58
darkoman10-Jun-08 0:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.