I give you RottenFlix, my first published Greasemonkey script.
What is it?
RottenFlix is a result of the time-honored tradition of scratching your own itch. I'm a huge movie fan and a devoted member of Netflix. I've also been a user of Rotten Tomatoes for many years and have come to rely on it heavily for movie ratings; I'll rarely commit to watching a movie until I've looked up its rating on RT. While browsing Netflix for intriguing movies, it became tedious and annoying to have to constantly leave the site to look up ratings on RT, so I developed RottenFlix to alleviate this pain by making RT ratings available in the Netflix interface with a single click.
You can find more details as well as screenshots here.
What I learned
Along the way, I learned a great deal about Greasemonkey and its various oddities, including integrating third-party JavaScript libraries, and troubleshooting cross-domain Ajax requests with GM_xmlhttpRequest. I picked up a few new jQuery tricks as well.
Caveats
One thing to be aware of if you install RottenFlix: because Rotten Tomatoes does not have an API for fetching movie ratings, I had to reverse-engineer the scheme that they use to map movie titles to URLs on the site. So I essentially have to make certain guesses that are not always correct, though I'd say at this point that my code guesses correctly about 90% of the time. When a guess is incorrect, you'll see a little "?" where the rating would normally appear, and by clicking the "?" you'll be taken to a search results page for that movie title on RottenTomatoes.com where you can easily find the correct movie yourself.
Plans
In the future, one major enhancement I'd like to make to RottenFlix is to redesign it to use Web Workers. My original design of RottenFlix fetched all relevant movie ratings up-front with no action required from the user, but it was just too slow and it blocked the UI awkwardly. With Web Workers I'm pretty confident I could go back to my original vision and make it fast and usable.
There's also the issue of new movie titles that are brought into the page via Netflix's own Ajax effects. RottenFlix does not currently handle those movie titles. I could probably make this work, but I'm not sure how.
Brilliant script! I love it when I think of an idea, Google it, and find that somebody was thinking the exact same thing. I get so tired of getting dud movies, but often I don't trust the ratings at Netflix. It has become tedious to tab back and forth between RT and NF.
ReplyDeleteThanks for the compliment! It's awesome to hear that people (other than myself) are finding RottenFlix useful. :-)
ReplyDeleteYes, RottenFlix is awesome. Good work!
ReplyDeleteThanks for the effort Matt. Have you looked at how InstantWatcher matches title to RT ratings ?
ReplyDeletehttp://instantwatcher.com/about#comment-34806063
About to start developing the same thing, but you saved me the effort! Great work!
ReplyDeleteEddie,
ReplyDeleteIf the source code for InstantWatcher were available, I'd definitely have a look, but that doesn't seem likely.
I followed that link you posted, and the algorithm "danchoi" describes is definitely something I could implement, but I don't think it would be worth the effort.
Hey man, awesome script. One thing I noticed as far as reverse-engineering the RT API is that a title like "Punch-Drunk Love" resolves itself to http://www.rottentomatoes.com/m/punchdrunk_love/. Just possibly another rule you could add to your algorithm. Thanks!
ReplyDeleteMatt,
ReplyDeleteRotten Tomatoes supports IMDb-Related Linking. For example, you can link to Punch-Drunk Love (2002) using this URL:
http://www.rottentomatoes.com/alias/?s=Punch-Drunk Love (2002)
This will result in a 302 response with a location header of /m/punchdrunk_love/
This is fantastic! I was really expecting to spend the next few hours writing this myself, but then I thought on the slim chance that someone already had done it.
ReplyDeleteThanks Matt!
Hey, awesome script! I was able to solve the Netflix to Rotten Tomatoes url problem by using google as an intermediary. In other words, the request url becomes http://www.google.com/search?q=rotten%20tomatoes%20 + movieTitle. After making this request all you have to do is scrape the google search page for the proper RT movie url and the rating itself (google includes the movies current rating in the summary). The specific code I used to do the scraping is as follows:
ReplyDeletevar pos = responseHTML.search(/Rating: \d+/g);
var rating = pos > 0 ? '' + parseInt(responseHTML.substring(pos + 8, pos + 10)) : 'No';
Note this only grabs the rating, not the proper RT url. It's ugly but it works.
Cheers,
Curtis
Curtis,
ReplyDeleteThat's an interesting approach! I never thought to scrape Google search results.
Matt, this is super-useful-awesome! (I wish there was a word that combined all three). By the way, we (rottentomatoes.com) have a new developer api in beta - http://developer.rottentomatoes.com - check it out :)
ReplyDeleteEugene,
ReplyDeleteThanks for the tip about your API! I'll take a look.
Matt, i am sure i am doing something wrong, but when i try to install the script i get a 502 error.
ReplyDeleteparas,
ReplyDeleteIt seems that userscripts.org is experiencing some technical difficulties at the moment. I'm getting 502 errors all over the site.
Try back later and hopefully the site will be functioning again.