Skip to content

Commit

Permalink
Added support for Google videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Flores committed Mar 9, 2011
1 parent e4eb42a commit ee49883
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 43 deletions.
20 changes: 19 additions & 1 deletion lib/readability.rb
@@ -1,5 +1,6 @@
require 'rubygems'
require 'nokogiri'
require 'cgi'

# so to run with non-Rails projects
class Object
Expand Down Expand Up @@ -56,6 +57,7 @@ def content(remove_unlikely_candidates = true)
article = vimeo if is_vimeo? && remove_unlikely_candidates
article = ted if is_ted? && remove_unlikely_candidates
article = slideshare if is_slideshare? && remove_unlikely_candidates
article = google_videos if is_google_videos? && remove_unlikely_candidates
article = apply_custom_rule if has_special_rule?

if article && remove_unlikely_candidates
Expand Down Expand Up @@ -102,6 +104,22 @@ def is_special_case?
(@base_uri.to_s =~ REGEXES[:videoRe])
end

def is_google_videos?
(@base_uri.to_s =~ /video.google.com/)
end

def google_videos
uri = URI.parse(@base_uri + @request)
video_id = CGI::parse(uri.query)['docid'].first
Nokogiri::HTML.fragment <<-HTML
<div>
<embed id=VideoPlayback src=http://video.google.com/googleplayer.swf?docid=#{video_id}&hl=en&fs=true style=width:400px;height:326px allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash>
</embed>
</div>
HTML

end

def slideshare
title = @document.css("h1.h-slideshow-title").inner_html
movie_value = @document.css("link[name='media_presentation']").first.attributes["href"].value
Expand All @@ -119,7 +137,7 @@ def slideshare
<embed name=\"__sse2606283\" src=\"#{movie_value}\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"355\"></embed>
</object>
</div>
HTML
HTML
end

def youtube
Expand Down

0 comments on commit ee49883

Please sign in to comment.