From 7fa3c93d0b469896d3681318031601c5de3341b8 Mon Sep 17 00:00:00 2001
From: Michael Orlitzky
Date: Sat, 26 Sep 2009 20:20:41 -0400
Subject: [PATCH] Fixed the Howcast downloads. Modified the Howcast class to
parse an XML file containing the real video URL. Added a test for the new
method.
---
src/websites/howcast.rb | 29 +-
test/fixtures/howcast/81134.xml | 586 ++++++++++++++++++++++++++++++++
test/howcast_test.rb | 16 +
3 files changed, 624 insertions(+), 7 deletions(-)
create mode 100644 test/fixtures/howcast/81134.xml
diff --git a/src/websites/howcast.rb b/src/websites/howcast.rb
index c8dfcd3..58861e7 100644
--- a/src/websites/howcast.rb
+++ b/src/websites/howcast.rb
@@ -26,8 +26,19 @@ class Howcast < Website
return url =~ VALID_HOWCAST_URL_REGEX
end
+
+ def get_video_url()
+ video_id = parse_video_id()
+ xml_url = "http://www.howcast.com/videos/#{video_id}.xml"
+ xml_data = self.get_page_data(xml_url)
+ filepath = parse_file_path_from_xml(xml_data)
+
+ return "http://www.howcast.com#{filepath}"
+ end
- def parse_video_id()
+ :private
+
+ def parse_video_id()
# This regex just pulls out the video id
id_regex = /\/(\d+)-/
matches = id_regex.match(@url)
@@ -39,12 +50,16 @@ class Howcast < Website
return matches[1]
end
-
- def get_video_url()
- video_id = parse_video_id()
-
- return "http://media.howcast.com/system/videos/#{video_id}/#{video_id}.flv"
+
+ def parse_file_path_from_xml(data)
+ file_path_regex = /(.*?)<\/filename>/
+ matches = file_path_regex.match(data)
+
+ if matches.nil?
+ raise StandardError.new("Couldn't parse the tag from the XML file.")
+ end
+
+ return matches[1]
end
-
end
diff --git a/test/fixtures/howcast/81134.xml b/test/fixtures/howcast/81134.xml
new file mode 100644
index 0000000..b5c9282
--- /dev/null
+++ b/test/fixtures/howcast/81134.xml
@@ -0,0 +1,586 @@
+
+
+
]]>
+
+
+
+ 49489
+ 2
+ 35
+ Step
+ http://img.howcast.com/system/thumbnails/81134/35.jpg
+ Try a bribe
+
+
+
+
+ Drag yourself and your frisky friend over to the buffet table and discreetly offer him a tasty treat in exchange for a dismount.]]>
+
+
+
+ 49490
+ 3
+ 43
+ Tip
+
+
+
+
+
+
+ Go for a meaty snack; he probably wonât let go of your leg for a celery stick.]]>
+
+
+
+ 49491
+ 4
+ 50
+ Step
+ http://img.howcast.com/system/thumbnails/81134/50.jpg
+ Fake him out
+
+
+
+
+ If you donât have a snack, try throwing an imaginary ball across the room.]]>
+
+
+
+ 49492
+ 5
+ 55
+ Step
+ http://img.howcast.com/system/thumbnails/81134/55.jpg
+ Make a joke
+
+
+
+
+ If none of your tricks have worked, itâs time to get others involved. Call attention to your predicament with a joke. Just be cool about it. Your host will be embarrassed enough without you piling on.]]>
+
+
+
+ 49493
+ 6
+ 66
+ Tip
+
+
+
+
+
+
+ Try this one: âWhoa, easy there, Fidoâthatâs not a Milk Bone in my pocket.â]]>
+
+
+
+ 49494
+ 7
+ 73
+ Step
+ http://img.howcast.com/system/thumbnails/81134/73.jpg
+ Demand assistance
+
+
+
+
+ At this point, if the mutt has not been removed, all bets are off. You are well within your rights to howl at your host. Feel free to use profanity.]]>
+
+
+
+ 49495
+ 8
+ 84
+ Step
+ http://img.howcast.com/system/thumbnails/81134/84.jpg
+ Ride it out
+
+
+
+
+ If the dogâs owner is uncooperative, you just may have to weather the storm. Who knows? Maybe youâll get a new best friend out of the deal.]]>
+
+
+
+ 49496
+ 9
+ 93
+ Fact
+
+
+
+
+
+
+ Neutered and female dogs sometimes hump legs as an act of dominance, not sexâso get over yourself already!]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/howcast_test.rb b/test/howcast_test.rb
index a76c725..aacfcf2 100644
--- a/test/howcast_test.rb
+++ b/test/howcast_test.rb
@@ -42,7 +42,23 @@ class HowcastTest < Test::Unit::TestCase
assert(!Howcast.owns_url?('redtube.com/6807'))
end
+
def test_doesnt_own_misc_urls
assert(!Howcast.owns_url?('http://www.howcast.com/abc'))
end
+
+
+ def test_parse_file_path_from_xml
+ hc = Howcast.new(nil)
+
+ page_data = nil
+
+ File.open('test/fixtures/howcast/81134.xml') do |f|
+ page_data = f.read
+ end
+
+ test_result = hc.send('parse_file_path_from_xml', page_data)
+ assert_equal('/system/videos/4/34/11/08/81134.flv', test_result)
+ end
+
end
--
2.44.2