X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=lib%2Fwhatever-dl%2Fwebsites%2Fhowcast.rb;fp=lib%2Fwhatever-dl%2Fwebsites%2Fhowcast.rb;h=90cbd615ca069c8c0f4a653796e2ae14b80c2374;hb=6de408333ceb0d142f8fa0fef2571228e89c8fc1;hp=0000000000000000000000000000000000000000;hpb=8e886df259246365023322b78f58e4037cb536a4;p=dead%2Fwhatever-dl.git diff --git a/lib/whatever-dl/websites/howcast.rb b/lib/whatever-dl/websites/howcast.rb new file mode 100644 index 0000000..90cbd61 --- /dev/null +++ b/lib/whatever-dl/websites/howcast.rb @@ -0,0 +1,65 @@ +# +# Copyright Michael Orlitzky +# +# http://michael.orlitzky.com/ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# http://www.fsf.org/licensing/licenses/gpl.html +# + +require 'src/website' + +class Howcast < Website + + VALID_HOWCAST_URL_REGEX = /^(http:\/\/)?(www\.)?howcast\.com\/videos\/(\d+)-(.+)$/ + + def self.owns_url?(url) + 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 + + protected; + + def parse_video_id() + # This regex just pulls out the video id + id_regex = /\/(\d+)-/ + 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 + + return matches[1] + end + +end