Skip to content

Commit

Permalink
adding metacafe filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Derrick Camerino committed Nov 8, 2010
1 parent 5b3f2d8 commit 8c3663a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions auto_html.gemspec
Expand Up @@ -31,6 +31,7 @@ Gem::Specification.new do |s|
"lib/auto_html/builder.rb",
"lib/auto_html/filter.rb",
"lib/auto_html/filters/dailymotion.rb",
"lib/auto_html/filters/metacafe.rb",
"lib/auto_html/filters/google_video.rb",
"lib/auto_html/filters/html_escape.rb",
"lib/auto_html/filters/image.rb",
Expand All @@ -49,6 +50,7 @@ Gem::Specification.new do |s|
"test/test_helper.rb",
"test/unit/auto_html_test.rb",
"test/unit/filters/dailymotion_test.rb",
"test/unit/filters/metacafe_test.rb",
"test/unit/filters/google_video_test.rb",
"test/unit/filters/html_escape_test.rb",
"test/unit/filters/image_test.rb",
Expand All @@ -73,6 +75,7 @@ Gem::Specification.new do |s|
"test/test_helper.rb",
"test/unit/auto_html_test.rb",
"test/unit/filters/dailymotion_test.rb",
"test/unit/filters/metacafe_test.rb",
"test/unit/filters/google_video_test.rb",
"test/unit/filters/html_escape_test.rb",
"test/unit/filters/image_test.rb",
Expand Down
13 changes: 13 additions & 0 deletions lib/auto_html/filters/metacafe.rb
@@ -0,0 +1,13 @@
AutoHtml.add_filter(:metacafe).with(:width => 440, :height => 272, :show_stats => false, :autoplay => false) do |text, options|
text.gsub(/http:\/\/www\.metacafe\.com\/watch\/([A-Za-z0-9._%-]*)\/([A-Za-z0-9._%-]*)(\/)?/) do
metacafe_id = $1
metacafe_slug = $2
width = options[:width]
height = options[:height]
show_stats = options[:show_stats] ? "showStats=yes" : "showStats=no"
autoplay = options[:autoplay] ? "autoPlay=yes" : "autoPlay=no"
flash_vars = [show_stats, autoplay].join("|")

%{<div style="background:#000000;width:#{width}px;height:#{height}px"><embed flashVars="playerVars=#{flash_vars}" src="http://www.metacafe.com/fplayer/#{metacafe_id}/#{metacafe_slug}.swf" width="#{width}" height="#{height}" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_#{metacafe_id}" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>}
end
end
2 changes: 1 addition & 1 deletion test/unit/filters/dailymotion_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../unit_test_helper'

class GoogleVideoTest < Test::Unit::TestCase
class DailyMotionTest < Test::Unit::TestCase

def test_transform
result = auto_html("http://www.dailymotion.com/en/featured/video/xag4p2_tempsmorttv-episode-01_shortfilms") { dailymotion }
Expand Down
29 changes: 29 additions & 0 deletions test/unit/filters/metacafe_test.rb
@@ -0,0 +1,29 @@
require File.dirname(__FILE__) + '/../unit_test_helper'

class MetaCafeTest < Test::Unit::TestCase

def test_transform
result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe }
assert_equal '<div style="background:#000000;width:440px;height:272px"><embed flashVars="playerVars=showStats=no|autoPlay=no" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="440" height="272" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
end

def test_transform_with_dimensions
result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe(:width => 500, :height => 300) }
assert_equal '<div style="background:#000000;width:500px;height:300px"><embed flashVars="playerVars=showStats=no|autoPlay=no" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="500" height="300" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
end

def test_transform_with_show_stats
result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe(:width => 500, :height => 300, :show_stats => true) }
assert_equal '<div style="background:#000000;width:500px;height:300px"><embed flashVars="playerVars=showStats=yes|autoPlay=no" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="500" height="300" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
end

def test_transform_with_autoplay
result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe(:width => 500, :height => 300, :autoplay => true) }
assert_equal '<div style="background:#000000;width:500px;height:300px"><embed flashVars="playerVars=showStats=no|autoPlay=yes" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="500" height="300" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
end

def test_transform_with_options
result = auto_html("http://www.metacafe.com/watch/5440707/exclusive_tron_evolution_dev_diary_the_art_design") { metacafe(:width => 500, :height => 300, :show_stats => true, :autoplay => true) }
assert_equal '<div style="background:#000000;width:500px;height:300px"><embed flashVars="playerVars=showStats=yes|autoPlay=yes" src="http://www.metacafe.com/fplayer/5440707/exclusive_tron_evolution_dev_diary_the_art_design.swf" width="500" height="300" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_5440707" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></div>', result
end
end

0 comments on commit 8c3663a

Please sign in to comment.