Method for retrieving movie posters

Jan 22, 2009

A couple of weeks ago I released an online TV guide for Danish viewers called ifjernsyn.dk. The goal was to make a very simple overview that could easily be accessed from a mobile phone and customized by any visitor without any login. The purpose was to always know what’s on the air right now and what programs will shortly follow – and of course to keep it simple.

Since the release, some people have asked me about how I did some of the things and one of the most frequently asked questions was how to find movie posters for all the movies. Apparently, people are interested in finding movie posters for their own pet projects involving their own media collection or even a media center plug-in.

The code

With only the name of a movie, the code will search the Yahoo image search API and return a thumbnail of the poster. The API returns an XML document with both the thumbnail and the full image, so to get the full image you should just change the XPath navigation.

private const string LINK = "http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&query={0} movie&results=1";

 

public static string FindMoviePoster(string title)

{

  string url = string.Format(LINK, HttpUtility.UrlEncode(title));

 

  XPathDocument xd = new XPathDocument(url);

  XPathNavigator navigator = xd.CreateNavigator();

  navigator.MoveToFollowing(XPathNodeType.Element);

  navigator.MoveToFirstChild();

  navigator.MoveToFirstChild();

 

  do

  {

    if (navigator.LocalName == "Thumbnail")

    {

      navigator.MoveToFirstChild();

      return navigator.Value;

    }

  } while (navigator.MoveToNext());

 

  return null;

}

The implementation

To use the method above in your own web page, simply pass a movie title to the method and the image URL is returned. It could look like this:

string posterUrl = FindMoviePoster("independance day");;

if (!string.IsNullOrEmpty(posterUrl))

{

  imgPoster.ImageUrl = posterUrl;

}

The reason to use the Yahoo API is because it provides the thumbnails as well as the full image.

* $4.95/month BlogEngine.net Hosting – Click Here!

Comments (4) -

Christian
Christian Denmark
1/23/2009 8:12:11 AM #

Nice site ifjernsyn.dk that is. And a cool example on getting images using imagesearch. But what im a bit more interested in is how you get the data for ifjernsyn.

And how about making a rss Wink

Mads Kristensen
Mads Kristensen Denmark
1/23/2009 11:01:45 AM #

There are RSS and ATOM feeds for the front page and the search. Look for the orange feed icon in your browser, because I haven't added a visible link. As for the data, I'm using XMLTV

Hector
Hector United States
1/24/2009 12:43:13 AM #

Good article, I try it, and I was able to see reasults.

masswowgold
masswowgold People's Republic of China
3/31/2009 12:15:02 AM #

Looking <a href="http://www.masswowgold.com">; wow gold </a>for thrilling weapons, <a href="http://www.masswowgold.com">; wow gold </a>items and new pets? Beating <a href="http://www.masswowgold.com">; wow gold </a>the more powerful and <a href='http://www.masswowgold.com'> wow gold 5000  </a>crueler giants? Becoming the cheers of your clan<a href='http://www.masswowgold.com'>buy wow gold 5000</a>and impressing your friends?<a href="http://www.masswowgold.com">; wow gold </a>All in http://www.masswowgold.com, We are the
<a href="http://www.masswowgold.com">; wow gold </a>best alliance of the online <a href="http://www.masswowgold.com">wow gold</a>game players! We have: 24×7 online <a href="http://www.masswowgold.com"; > wow gold </a>support;50,000+ registered users;10,000+Paypal
<a href='http://www.masswowgold.com'>cheap WOW gold</a> reputations;4 years professional service provider;We get <a href="http://www.masswowgold.com">; wow gold </a>gold from the players <a href='http://www.masswowgold.com'>cheap WOW gold </a>who do not need them any more or <a href='http://www.masswowgold.com'>wow gold 5000  </a>collect them from the direct <a href='http://www.masswowgold.com'>cheap WOW gold </a>gold farmers with <a href="http://www.masswowgold.com">; wow gold </a>lower price. Now the <a href='http://www.masswowgold.com'> sell wow gold  </a>WOW gold is under big promotion. <a href='http://www.masswowgold.com'> sell wow gold  </a>Registered Member will get 10% bonus.<a href='http://www.masswowgold.com'>wow gold 5000  </a>Most of the orders can be completedv<a href='http://www.masswowgold.com'> sell wow gold  </a>in 3 hours. And we will give our customers the extra 5% gold if<a href='http://www.masswowgold.com'> wow gold 5000  </a>we can not complete the order in <a href='http://www.masswowgold.com'>cheap WOW gold </a>24 hours.We deliver <a href='http://www.masswowgold.com'>cheap WOW gold </a>the gold by <a href='http://www.masswowgold.com'> sell wow gold  </a>face-to-face trade <a href='http://www.masswowgold.com'> wow gold 5000  </a>in game only. Full refund will be warranted if <a href='http://www.masswowgold.com'> wow gold 5000  </a>we can not complete the <a href='http://www.masswowgold.com'>cheap WOW gold </a>orders in <a href='http://www.masswowgold.com'>cheap WOW gold </a>time.

Pingbacks and trackbacks (4)+

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.