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.
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:
#include <span class="code-string">"IMDBSearch.h"</span>
if (CIMDBSearch::SearchIMDB(_T("Enter a searching keyword here..."), ST_TITLES_EXACT))
int iNumberResults = CIMDBSearch::GetSearchCount();
for (int i=0; i<iNumberResults; i++)
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:
typedef struct _SEARCH_INFO
_TCHAR szPath; _TCHAR szTitle; _TCHAR szYear;
} SEARCH_INFO, *LPSEARCH_INFO;
To get the movie details, see the following:
int item = 0;
LPMOVIE_INFO lpMovieInfo = NULL;
The definition of the
MOVIE_INFO structure is the following:
typedef struct _MOVIE_INFO
_TCHAR szUserRating; _TCHAR szDirector; _TCHAR szWriter; _TCHAR szReleaseDate; _TCHAR szGenre; _TCHAR szPlot; _TCHAR szAwards; _TCHAR szUserComments; _TCHAR szRuntime; _TCHAR szCountry; _TCHAR szLanguage; _TCHAR szColor; _TCHAR szAspectRatio; _TCHAR szSoundMix; _TCHAR szFilmingLocations; _TCHAR szCompany; _TCHAR szPoster; _TCHAR szCast;
} 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.
- 6th June, 2008: Initial post