X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fwebsites%2Fhowcast.rb;h=58861e7d1da0ebf555f2ee06ba0077dfa56e0fda;hb=7fa3c93d0b469896d3681318031601c5de3341b8;hp=c07d8489f31efea5e3ad98bdffb021db11cf12b7;hpb=168ef3b2ccf5b97d561a3c542a18e8e7587de291;p=dead%2Fwhatever-dl.git diff --git a/src/websites/howcast.rb b/src/websites/howcast.rb index c07d848..58861e7 100644 --- a/src/websites/howcast.rb +++ b/src/websites/howcast.rb @@ -26,18 +26,40 @@ class Howcast < Website return url =~ VALID_HOWCAST_URL_REGEX end - - def get_video_url(url) + + 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 + + :private + + def parse_video_id() # This regex just pulls out the video id id_regex = /\/(\d+)-/ - matches = id_regex.match(url) + matches = id_regex.match(@url) if matches.nil? raise StandardError.new('The URL is a valid Howcast URL, but does not match on the digit portion of the regex. Since the digit portion is a subset of the "valid" regex, this should never occur.') end + + return matches[1] + end + + + 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 - video_id = matches[1] - return "http://media.howcast.com/system/videos/#{video_id}/#{video_id}.flv" + return matches[1] end end