diff --git a/app/assets/images/favicons/rottentomatoes.png b/app/assets/images/favicons/rottentomatoes.png new file mode 100644 index 00000000000..74e0a676feb Binary files /dev/null and b/app/assets/images/favicons/rottentomatoes.png differ diff --git a/app/assets/stylesheets/application/onebox.scss b/app/assets/stylesheets/application/onebox.scss index 318811dba05..0ea9f94cc60 100644 --- a/app/assets/stylesheets/application/onebox.scss +++ b/app/assets/stylesheets/application/onebox.scss @@ -69,3 +69,18 @@ a.loading-onebox { } } } + +// RottenTomatoes Onebox +.onebox-result { + .onebox-result-body { + img.verdict { + float: none; + margin-right: 7px; + } + img.popcorn { + float: none; + margin-left: 20px; + margin-right: 5px; + } + } +} diff --git a/lib/oneboxer/rottentomatoes_onebox.rb b/lib/oneboxer/rottentomatoes_onebox.rb new file mode 100644 index 00000000000..580ed68e1da --- /dev/null +++ b/lib/oneboxer/rottentomatoes_onebox.rb @@ -0,0 +1,72 @@ +require_dependency 'oneboxer/handlebars_onebox' + +module Oneboxer + class RottentomatoesOnebox < HandlebarsOnebox + + SYNOPSIS_MAX_TEXT = 370 + ROTTEN_IMG = 'http://images.rottentomatoescdn.com/images/icons/rt.rotten.med.png' + FRESH_IMG = 'http://images.rottentomatoescdn.com/images/icons/rt.fresh.med.png' + POPCORN_IMG = 'http://images.rottentomatoescdn.com/images/icons/popcorn_27x31.png' + + matcher /^http:\/\/(?:www\.)?rottentomatoes\.com(\/mobile)?\/m\/.*$/ + favicon 'rottentomatoes.png' + + def http_params + {'User-Agent' => '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... +
    +
  • + +
+ + +
+ +
+
+ + + + + + + + + + + + + + + + + + + +