]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - src/websites/howcast.rb
Fixed the Howcast downloads.
[dead/whatever-dl.git] / src / websites / howcast.rb
index c8dfcd3fc12a13564bcd53c56d9ccaf81621c75a..58861e7d1da0ebf555f2ee06ba0077dfa56e0fda 100644 (file)
@@ -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>(.*?)<\/filename>/
+    matches = file_path_regex.match(data)
+
+    if matches.nil?
+      raise StandardError.new("Couldn't parse the <filename> tag from the XML file.")
+    end
+
+    return matches[1]
   end
 
-  
 end