From 9bc8faeaf23d0bb0e0e6cfb728e027f82f2b3fbb Mon Sep 17 00:00:00 2001 From: Ryan Boland Date: Thu, 25 Apr 2013 19:16:29 -0400 Subject: [PATCH] added rottentomatoes.com onebox --- app/assets/images/favicons/rottentomatoes.png | Bin 0 -> 1941 bytes .../stylesheets/application/onebox.scss | 15 + lib/oneboxer/rottentomatoes_onebox.rb | 72 +++ .../templates/rottentomatoes_onebox.hbrs | 25 + lib/oneboxer/whitelist.rb | 1 + .../oneboxer/rottentomatoes_onebox_spec.rb | 115 ++++ .../oneboxer/rottentomatoes_fresh.response | 607 +++++++++++++++++ .../rottentomatoes_incomplete.response | 462 +++++++++++++ .../oneboxer/rottentomatoes_rotten.response | 609 ++++++++++++++++++ 9 files changed, 1906 insertions(+) create mode 100644 app/assets/images/favicons/rottentomatoes.png create mode 100644 lib/oneboxer/rottentomatoes_onebox.rb create mode 100644 lib/oneboxer/templates/rottentomatoes_onebox.hbrs create mode 100644 spec/components/oneboxer/rottentomatoes_onebox_spec.rb create mode 100644 spec/fixtures/oneboxer/rottentomatoes_fresh.response create mode 100644 spec/fixtures/oneboxer/rottentomatoes_incomplete.response create mode 100644 spec/fixtures/oneboxer/rottentomatoes_rotten.response diff --git a/app/assets/images/favicons/rottentomatoes.png b/app/assets/images/favicons/rottentomatoes.png new file mode 100644 index 0000000000000000000000000000000000000000..74e0a676feb206220a5f32af87716c10003b7736 GIT binary patch literal 1941 zcmV;G2Wt34Tx05}naRo`#hR1`jmZ&IWdKOk5~hl<6oRa0BJ8yc;~21%2p?MfD<>DVeH z9(p*dx19w`~g7O0}n_%Aq@s%d)fBDv`JHkDym6Hd+5XuAtvnwRpGmK zVkc9?T=n|PIo~X-eVh__(Z?q}P9Z-Dj?gOW6|D%o20XmjW-qs4UjrD(li^iv8@eK9k+ZFm zVRFymFOPAzG5-%Pn|1W;U4vNroTa&AxDScmEA~{ri9gr1^c?U@uwSpaNnw8l_>cP1 zd;)kMQS_;jeRSUEM_*s96y65j1$)tOrwdK{YIQMt92l|D^(E_=$Rjw{b!QT@q!)ni zR`|5oW9X5n$Wv+HVc@|^eX5yXnsHX8PF3UX~a6)MwxDE0HaPjyrlI!;jX{6Kvuh*8ej?;85ekN$?5uuCiS zBTvvVG+XTxAO{m@bvM#Jr)z6J><&E22D|vq?Y?Vkbo_DijopiF$2PET#mZ8eu=y$(ArYkv7@Ex`GL?QCc!_*KFrd&;n1r7 zqW-CFs9&fT)ZaU5gc&=gBz-DaCw(vdOp0__x+47~U6sC(E(JNe@4cTT*n6*E zVH4eoU1-&7pEV~_PRe`a7v+@vy!^5}8?Y3)UmlaER00009a7bBm000XU000XU0RWnu7ytkR7fD1xR5%e` zlSyn%Q5eVn=iI?_-|Ks=d3Z$3N~2U7V!;y&3$ajMD-k;tD+^&EgxW~36A~`h8qpX-OleE|CU0nOdxvw5@4TjoILUYKJ;U$+{m*yKg;EOR0R`56vB}c?wsWgy ztv%3ie{2qHe9ixFj(?h#y4c~<6SX+YF!L_yGnSv!htc-z{w*S5rL3{OCr|ug@&6L5KS%J-#@WD z7RFtSewpO(X`h>|;PoQg>X~MuJ`-Zs)gcT73dcGoWB)4`4fk9KFuw+{^FU8h^)|9T z%sDuvhMz4iHGF@rZHpNZ*i`6P#)F&l;XLv1VuJ-ak)!#c3)eEh0t9tnRtd7j~CmC`Re&67U-$ZW5PgMVcr{CCPFK>KF{N6hIaQR9PcqU_kF- zg3ACLGluLiUN7dBDl|p;lD8F zZ4FrckgYr<*o5jHT(VzL@F;7A;39 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31' } + end + + def template + template_path('rottentomatoes_onebox') + end + + def translate_url + m = @url.match(/^http:\/\/(?:www\.)?rottentomatoes\.com(\/mobile)?\/m\/(?.*)$/mi) + "http://rottentomatoes.com/mobile/m/#{m[:movie]}" + end + + def parse(data) + html_doc = Nokogiri::HTML(data) + + result = {} + + result[:title] = html_doc.at('h1').content + result[:poster] = html_doc.at_css('.poster img')['src'] + + synopsis = html_doc.at_css('#movieSynopsis').content.squish + synopsis.gsub!(/\$\(function\(\).+$/, '') + result[:synopsis] = (synopsis.length > SYNOPSIS_MAX_TEXT ? "#{synopsis[0..SYNOPSIS_MAX_TEXT]}..." : synopsis) + + result[:verdict_percentage], result[:user_percentage] = html_doc.css('.rtscores .rating .percentage span').map(&:content) + result[:popcorn_image] = POPCORN_IMG + if html_doc.at_css('.rtscores .rating .splat') + result[:verdict_image] = ROTTEN_IMG + elsif html_doc.at_css('.rtscores .rating .tomato') + result[:verdict_image] = FRESH_IMG + end + + result[:cast] = html_doc.css('.summary .actors a').map(&:content).join(", ") + + html_doc.css('#movieInfo .info').map(&:inner_html).each do |element| + case + when element.include?('Director:') then result[:director] = clean_up_info(element) + when element.include?('Rated:') then result[:rated] = clean_up_info(element) + when element.include?('Running Time:') then result[:running_time] = clean_up_info(element) + when element.include?('DVD Release:') + result[:release_date] = clean_up_info(element) + result[:release_type] = 'DVD' + # Only show the theater release date if there is no DVD release date + when element.include?('Theater Release:') && !result[:release_type] + result[:release_date] = clean_up_info(element) + result[:release_type] = 'Theater' + end + end + + result.delete_if { |k, v| v.blank? } + end + + def clean_up_info(inner_html) + inner_html.squish.gsub(/^.*<\/span>\s*/, '') + end + + end +end diff --git a/lib/oneboxer/templates/rottentomatoes_onebox.hbrs b/lib/oneboxer/templates/rottentomatoes_onebox.hbrs new file mode 100644 index 00000000000..38c7841c9cd --- /dev/null +++ b/lib/oneboxer/templates/rottentomatoes_onebox.hbrs @@ -0,0 +1,25 @@ +
+ {{#host}} + + {{/host}} +
+ {{#poster}}{{/poster}} +

{{title}}

+ + {{#verdict_image}}{{verdict_percentage}} of critics liked it.{{/verdict_image}} + {{#user_percentage}}{{user_percentage}} of users liked it.
{{/user_percentage}} + {{#cast}}Cast: {{cast}}
{{/cast}} + {{#director}}Director: {{director}}
{{/director}} + {{#release_type}}{{release_type}} Release: {{release_date}}
{{/release_type}} + {{#running_time}}Running Time: {{running_time}}
{{/running_time}} + {{#rated}}Rated: {{rated}}
{{/rated}} + {{synopsis}} +
+
+
diff --git a/lib/oneboxer/whitelist.rb b/lib/oneboxer/whitelist.rb index 8197318fcbc..5026fc6291e 100644 --- a/lib/oneboxer/whitelist.rb +++ b/lib/oneboxer/whitelist.rb @@ -3,6 +3,7 @@ module Oneboxer module Whitelist def self.entries [ + Entry.new(/^https?:\/\/(?:www\.)?rottentomatoes\.com\/.+/), Entry.new(/^https?:\/\/(?:www\.)?cnn\.com\/.+/), Entry.new(/^https?:\/\/(?:www\.)?washingtonpost\.com\/.+/), Entry.new(/^https?:\/\/(?:www\.)?funnyordie\.com\/.+/), diff --git a/spec/components/oneboxer/rottentomatoes_onebox_spec.rb b/spec/components/oneboxer/rottentomatoes_onebox_spec.rb new file mode 100644 index 00000000000..5e88b92a50c --- /dev/null +++ b/spec/components/oneboxer/rottentomatoes_onebox_spec.rb @@ -0,0 +1,115 @@ +# encoding: utf-8 + +require 'spec_helper' +require 'oneboxer' +require 'oneboxer/rottentomatoes_onebox' + +describe Oneboxer::RottentomatoesOnebox do + it 'translates the URL' do + o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/mud_2012/') + expect(o.translate_url).to eq('http://rottentomatoes.com/mobile/m/mud_2012/') + end + + it 'generates the expected onebox for a fresh movie' do + o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/mud_2012/') + FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_fresh.response')) + expect(o.onebox).to eq(expected_fresh_result) + end + + it 'generates the expected onebox for a rotten movie' do + o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/the_big_wedding_2013/') + FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_rotten.response')) + expect(o.onebox).to eq(expected_rotten_result) + end + + it 'generates the expected onebox for a movie with an incomplete description' do + o = Oneboxer::RottentomatoesOnebox.new('http://www.rottentomatoes.com/m/gunde_jaari_gallanthayyinde/') + FakeWeb.register_uri(:get, o.translate_url, response: fixture_file('oneboxer/rottentomatoes_incomplete.response')) + expect(o.onebox).to eq(expected_incomplete_result) + end + +private + def expected_fresh_result + < + +
+ +

Mud

+ + 98% of critics liked it. + 85% of users liked it.
+ Cast: Matthew McConaughey, Reese Witherspoon
+ Director: Jeff Nichols
+ Theater Release: Apr 26, 2013
+ Running Time: 2 hr. 10 min.
+ Rated: PG-13
+ Mud is an adventure about two boys, Ellis and his friend Neckbone, who find a man named Mud hiding out on an island in the Mississippi. Mud describes fantastic scenarios-he killed a man in Texas and vengeful bounty hunters are coming to get him. He says he is planning to meet and escape with the love of his life, Juniper, who is waiting for him in town. Skeptical but i... +
+
+ +EXPECTED + end + + def expected_rotten_result + < + +
+ +

The Big Wedding

+ + 6% of critics liked it. + 80% of users liked it.
+ Cast: Robert De Niro, Diane Keaton
+ Director: Justin Zackham
+ Theater Release: Apr 26, 2013
+ Running Time: 1 hr. 29 min.
+ Rated: R
+ With an all-star cast led by Robert De Niro, Katherine Heigl, Diane Keaton, Amanda Seyfried, Topher Grace, with Susan Sarandon and Robin Williams, THE BIG WEDDING is an uproarious romantic comedy about a charmingly modern family trying to survive a weekend wedding celebration that has the potential to become a full blown family fiasco. To the amusement of their adult c... +
+
+ +EXPECTED + end + + def expected_incomplete_result + < + +
+ +

Gunde Jaari Gallanthayyinde

+ + + + Cast: Nithin, Nithya Menon
+ Director: Vijay Kumar Konda
+ Theater Release: Apr 19, 2013
+ Running Time: 2 hr. 35 min.
+ Rated: Unrated
+ Software engineer Karthik thinks he is the smartest guy on the earth, but he turns out be the biggest fool at the end. +
+
+ +EXPECTED + end +end diff --git a/spec/fixtures/oneboxer/rottentomatoes_fresh.response b/spec/fixtures/oneboxer/rottentomatoes_fresh.response new file mode 100644 index 00000000000..43c00d2fcf9 --- /dev/null +++ b/spec/fixtures/oneboxer/rottentomatoes_fresh.response @@ -0,0 +1,607 @@ +HTTP/1.0 200 OK +Date: Sun, 28 Apr 2013 19:11:21 GMT +Expires: Sat, 6 May 1995 12:00:00 GMT +Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 +Pragma: no-cache +Set-Cookie: ServerID=1332; Path=/ +Set-Cookie: JSESSIONID=9BE14DA3E8864346F04FF28AF6888AF2.localhost; Path=/ +Content-Type: text/html;charset=ISO-8859-1 +Content-Language: en-US +Vary: User-Agent,Accept-Encoding +Connection: close + + + + + + RottenTomatoes Mobile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+
+

Mud

+
+ + + + + + + + + + + + + +
+
+
+ + +
+ +
+

98% of critics liked it

+
+
+
+ +
+

85% of users liked it

+
+
+ + + +
+ +
+ +
In theaters Apr 26, 2013
+
PG-13, 2 hr. 10 min.
+ + + + + + + + + + + + + + + + + + +
+
+
+ +
+ + +
+

Showtimes

+
+ Get Showtimes: + + + +
+
+ + +
+

Movie Info

+ + + +
+ Director: Jeff Nichols +
+ +
+ Rated: PG-13 +
+ +
+ Running Time: 2 hr. 10 min. +
+ +
+ Genre: Drama +
+ +
+ Theater Release: Apr 26, 2013 +
+ + + + + + + + +
+ Synopsis: + Mud is an adventure about two boys, Ellis and his friend Neckbone, who find a man named Mud hiding out on an island in the Mississippi. Mud describes fantastic scenarios-he killed a man in Texas and vengeful bounty hunters are coming to get him. He says he is planning to meet and escape with the love of his life, Juniper, who is waiting for him in town. Skeptical but intrigued, Ellis and Neckbone agree to help him. It isn't long until Mud's visions come true and their small town is besieged by a + + + + + + + + +
+
+ +
+

Critic Reviews

+ + + +
    + +
  • +
    + + +
    + + "Mud" isn't just a movie. It's the firm confirmation of a career. + More... +
    +
  • + +
  • +
    + + +
    + + "Mud" unfolds at its own pace, revealing its story in slivers. The performances are outstanding, especially from Sheridan, who plays tough, sweet, vulnerable and confused with equal conviction. + More... +
    +
  • + +
  • +
    + + +
    + + The film is drenched in the humidity and salty air of a Delta summer, often recalling the musical, aphoristic cadences of Sam Shepard, who happens to appear in a supporting role. + More... +
    +
  • + +
  • +
    + + +
    + + A wonderful, piquant modern-day variation on "Huckleberry Finn.'' + More... +
    +
  • + +
  • +
    + + +
    + + One of the most creatively rich and emotionally rewarding movies to come along this year. + More... +
    +
  • + +
  • +
    + + +
    + + It's a movie that holds out hope for the movies' future. + More... +
    +
  • + +
  • +
    + + +
    + + Mr. Nichols's voice is a distinctive and welcome presence in American film. + More... +
    +
  • + +
  • +
    + + +
    + + Nichols' wild narrative tributaries all eventually intersect, and at no time does he let one's attention stall. + More... +
    +
  • + +
  • +
    + + +
    + + What you do need to know is that the acting is top-tier all the way. McConaughey, on a career roll, is magnificent. + More... +
    +
  • + +
  • +
    + + +
    + + Nichols lovingly sketches his characters and their world; he takes his time doing so, but it's a pleasure to watch the small interactions and the humid reality of secret coves and Piggly Wiggly supermarkets and seedy hotels. + More... +
    +
  • + +
+ + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/oneboxer/rottentomatoes_incomplete.response b/spec/fixtures/oneboxer/rottentomatoes_incomplete.response new file mode 100644 index 00000000000..7d7340d2613 --- /dev/null +++ b/spec/fixtures/oneboxer/rottentomatoes_incomplete.response @@ -0,0 +1,462 @@ +HTTP/1.0 200 OK +Date: Sun, 28 Apr 2013 18:19:31 GMT +Expires: Sat, 6 May 1995 12:00:00 GMT +Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 +Pragma: no-cache +Set-Cookie: ServerID=1210; Path=/ +Set-Cookie: JSESSIONID=968C19E80C72CF48C6EE1927ADBD369E.localhost; Path=/ +Content-Type: text/html;charset=ISO-8859-1 +Content-Language: en-US +Vary: User-Agent,Accept-Encoding +Connection: close + + + + + + RottenTomatoes Mobile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+
+

Gunde Jaari Gallanthayyinde

+
+ + + + + + + + + + + + + +
+
+
+ + + + + + +
+ +
+ +
In theaters Apr 19, 2013
+
Unrated, 2 hr. 35 min.
+ + + + + + + + + + + +
+
+
+ +
+ + +
+

Showtimes

+
+ Get Showtimes: + + + +
+
+ + +
+

Movie Info

+ + + +
+ Director: Vijay Kumar Konda +
+ +
+ Rated: Unrated +
+ +
+ Running Time: 2 hr. 35 min. +
+ +
+ Genre: Special Interest, Romance +
+ +
+ Theater Release: Apr 19, 2013 +
+ + + + + + + + +
+ Synopsis: + Software engineer Karthik thinks he is the smartest guy on the earth, but he turns out be the biggest fool at the end. + + +
+
+ +
+

Critic Reviews

+ + +

No recent ratings.

+ + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/oneboxer/rottentomatoes_rotten.response b/spec/fixtures/oneboxer/rottentomatoes_rotten.response new file mode 100644 index 00000000000..e48d0de47ea --- /dev/null +++ b/spec/fixtures/oneboxer/rottentomatoes_rotten.response @@ -0,0 +1,609 @@ +HTTP/1.0 200 OK +Date: Sun, 28 Apr 2013 18:17:44 GMT +Expires: Sat, 6 May 1995 12:00:00 GMT +Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 +Pragma: no-cache +Set-Cookie: ServerID=1231; Path=/ +Set-Cookie: JSESSIONID=F1555163A809558BB2A3A9EE3408FEF6.localhost; Path=/ +Content-Type: text/html;charset=ISO-8859-1 +Content-Language: en-US +Vary: User-Agent,Accept-Encoding +Connection: close + + + + + + RottenTomatoes Mobile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+
+

The Big Wedding

+
+ + + + + + + + + + + + + +
+
+
+ + +
+ +
+

6% of critics liked it

+
+
+
+ +
+

80% of users liked it

+
+
+ + + +
+ +
+ +
In theaters Apr 26, 2013
+
R, 1 hr. 29 min.
+ + + + + + + + + + + + + + + + + + +
+
+
+ +
+ + +
+

Showtimes

+
+ Get Showtimes: + + + +
+
+ + +
+

Movie Info

+ + + +
+ Director: Justin Zackham +
+ +
+ Rated: R +
+ +
+ Running Time: 1 hr. 29 min. +
+ +
+ Genre: Comedy +
+ +
+ Theater Release: Apr 26, 2013 +
+ + + + + + + + +
+ Synopsis: + With an all-star cast led by Robert De Niro, Katherine Heigl, Diane Keaton, Amanda Seyfried, Topher Grace, with Susan Sarandon and Robin Williams, THE BIG WEDDING is an uproarious romantic comedy about a charmingly modern family trying to survive a weekend wedding celebration that has the potential to become a full blown family fiasco. To the amusement of their adult children and friends, long divorced couple Don and Ellie Griffin (De Niro and Keaton) are once again forced to play the happy + + + + + + + + +
+
+ +
+

Critic Reviews

+ + + +
    + +
  • +
    + + +
    + + It's tired and dated with too few laughs to justify the stultifying attempts at drama and the impossible-to-swallow plot contortions. + More... +
    +
  • + +
  • +
    + + +
    + + Looks great, some terrific ingredients, but when you slice it up, what a disappointment. + More... +
    +
  • + +
  • +
    + + +
    + + Sarandon, Keaton and De Niro mesh beautifully, fully convincing as a trio of old friends and carting in lots of characterization that would be otherwise lacking in Zackham's rote screenplay. + More... +
    +
  • + +
  • +
    + + +
    + + The Big Wedding is a would-be screwball comedy that forgets to throw in the screws. + More... +
    +
  • + +
  • +
    + + +
    + + Many Hollywood films are founded on privilege, but few are as open and nasty about their racism, misogyny, and homophobia. It's a feel-good movie for people who only comfortable around people who look and act just like them. + More... +
    +
  • + +
  • +
    + + +
    + + The Big Wedding aims low and achieves every aspiration. + More... +
    +
  • + +
  • +
    + + +
    + + I suppose it's always nice to get an invitation but please, this "Wedding"? Send back your regrets. + More... +
    +
  • + +
  • +
    + + +
    + + A shining example of a dull studio comedy. + More... +
    +
  • + +
  • +
    + + +
    + + It never feels real, and its only saving grace is that it clocks in at a mercifully short 90 minutes, which is just about the amount of time you need to realize you never want to see these characters ever again. + More... +
    +
  • + +
  • +
    + + +
    + + Sadly, superior talent can propel a movie only so far. Bad scripts beget bad movies, even when four Academy Award winners are involved. + More... +
    +
  • + +
+ + +
+ +
+
+ + + + + + + + + + + + + + + + + + + +