Skip to content

Commit

Permalink
adding marca.tv service and tests, fixing embed_html for blip
Browse files Browse the repository at this point in the history
  • Loading branch information
mamuso committed Jan 3, 2009
1 parent bfe8126 commit abda147
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/acts_as_unvlogable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'vg_dalealplay'
require 'vg_flickr'
require 'vg_qik'
require 'vg_marca'


class UnvlogIt
Expand Down
2 changes: 1 addition & 1 deletion lib/vg_blip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def embed_url
end

def embed_html(width=425, height=344, options={})
"<embed src='#{embed_url}' type='application/x-shockwave-flash' width='#{width}' height='#{height} allowscriptaccess='always' allowfullscreen='true'></embed>"
"<embed src='#{embed_url}' type='application/x-shockwave-flash' width='#{width}' height='#{height}' allowscriptaccess='always' allowfullscreen='true'></embed>"
end

def flv
Expand Down
55 changes: 55 additions & 0 deletions lib/vg_marca.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ----------------------------------------------
# Class for Marca.tv (www.marca.tv)
# http://www.marca.com/tv/?v=DN23wG8c1Rj
# ----------------------------------------------


class VgMarca

def initialize(url=nil, options={})
@url = url
@video_id = parse_url(url)
res = Net::HTTP.get(URI.parse("http://www.marca.com/consolamultimedia/marcaTV/elementos/#{@video_id[0,1]}/#{@video_id[1,1]}/#{@video_id[2,100]}.xml"))
@feed = REXML::Document.new(res)
end

def title
REXML::XPath.first( @feed, "//titulo" )[0].to_s
end

def thumbnail
REXML::XPath.first( @feed, "//foto" )[0].to_s
end

def embed_url
"http://www.marca.com/componentes/flash/embed.swf?ba=0&cvol=1&bt=1&lg=1&vID=#{@video_id}&ba=1"
end

def embed_html(width=425, height=344, options={})
"<embed width='#{width}' height='#{height}' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' allowfullscreen='true' quality='high' src='#{embed_url}'/>"
end

def flv
REXML::XPath.first(@feed, "//media")[0].to_s
end


protected

def parse_url(url)
uri = URI.parse(url)
args = uri.query
video_id = ''
if args and args.split('&').size >= 1
args.split('&').each do |arg|
k,v = arg.split('=')
video_id = v and break if k == 'v'
end
raise unless video_id
video_id
else
raise
end
end

end
24 changes: 23 additions & 1 deletion test/acts_as_unvlogable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class ActsAsUnvlogableTest < Test::Unit::TestCase
# ----------------------------------------------------------
context "with an qik.com video url" do
setup do
@videotron = UnvlogIt.new("http://qik.com/video/340982") # => Visto en la Tate Modern
@videotron = UnvlogIt.new("http://qik.com/video/340982") # => Honolulu Day 8: USS Arizona at Pearl Harbor
end
should "initialize a VgQik instance" do
assert_equal VgQik, @videotron.instance_values['object'].class
Expand All @@ -324,6 +324,28 @@ class ActsAsUnvlogableTest < Test::Unit::TestCase



# ----------------------------------------------------------
# Testing www.marca.tv
# ----------------------------------------------------------
context "with an www.marca.tv video url" do
setup do
@videotron = UnvlogIt.new("http://www.marca.com/tv/?v=DN23wG8c1Rj") # => Pau entra por la puerta grande en el club de los 10.000
end
should "initialize a VgMarca instance" do
assert_equal VgMarca, @videotron.instance_values['object'].class
assert_equal "http://www.marca.com/tv/?v=DN23wG8c1Rj", @videotron.instance_values['object'].instance_values['url']
assert_equal "DN23wG8c1Rj", @videotron.instance_values['object'].instance_values['video_id']
assert_not_nil @videotron.instance_values['object'].instance_values['feed']
end

should "return the video properties" do
check_video_attributes({:title => "Pau entra por la puerta grande en el club de los 10.000"})
end
end





protected

Expand Down

0 comments on commit abda147

Please sign in to comment.