This query:
https://imdbparser.appspot.com/?callback=foo&context=bar&action=rating&id=tt0411008
Gives this result: foo('bar', '8.7')
So you can write something like that:<script type="text/javascript">
function foo(context, rating)
{
alert("The rating is: " + rating);
}
</script>
<script src="https://imdbparser.appspot.com/?callback=foo&context=bar&action=rating&id=tt0411008" type="text/javascript"></script>
</script>
Original Post:
Solution to what exactly?
In JavaScript you aren't suppose to communicate with other sites, such as IMDB. As a result, you can't get the rating of a movie just like that.
For more information:
http://en.wikipedia.org/wiki/Same_origin_policy
Example: Vicky Cristina Barcelona
How to use it in your website?
Put this code in the top of the page:
<script src="http://sites.google.com/site/ycouriel/files/imdbrating.js" type="text/javascript"> </script>
Put this code each time you want to get rating:<script type="text/javascript"> IMDBRATING.registerTitle("tt0068646");</script>
Finally, put this code in the bottom of the page: <script type="text/javascript"> IMDBRATING.processTitles();</script>
You also need to put this CSS if you want the nice stars: imdbrating.css
You also need to put this CSS if you want the nice stars: imdbrating.css
How it's done?
The trick is to use Google. Consider the following query:
You get in return:
IMDBRATING.ratingCallback( <search results here> );
This wonderful feature of Google allows you to write a query as the source of JavaScript:
<script src=" <the query above here> " type="text/javascript"> </script>
By parsing the search results, you can easily find the rating.Notes:
- This is a JavaScript solution; if you have a server running PHP or something you can put some page like Google's, only instead of search results you return the ratings. This could be wonderful, but all the websites on the Internet that do exactly that didn't work for me or were very slow.
- The rating you get is sometimes not updated, it entirely depends on how often Google database is updated.
how would you do this for things other than score, e.g. if I wanted to find the runtime of the movie from IMDB?
ReplyDeletei added some functionality so it also finds: runtime, title and description
ReplyDeleteexample:
https://imdbparser.appspot.com/?callback=foo&context=bar&id=tt1067583
gives:
foo("bar", {"rating": "7.0", "description": "A veterinary student abandons his studies after his parents are killed and joins a traveling circus as their vet.", "time": "120", "id": "tt1067583", "title": "Water for Elephants"})
Can't you add one more functionality of numbers of voter?
ReplyDeleteHi Yoni,
ReplyDeleteI found an issue in the script... this has to do with the parseGoogleData function... the regular expression don't work.
I replaced the current regexp to "/vote\s*of\s*([0-9\.]+)\s*\/\s*10/i"
This script works fine for me now. Thank you very much and sorry my bad english :)
--
www.gilbertopineda.com
Why do not you use the IMDb Ratings boost service at leeseohits.com. I find it helpful to you
ReplyDeleteNice functionality - that was helpful for my website.
ReplyDelete