--- /dev/null
+#
+# 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 Veoh < Website
+
+ VALID_VEOH_URL_REGEX = /^(http:\/\/)?(www\.)?veoh\.com\/.*?(v[[:alnum:]]+)$/
+
+ def self.owns_url?(url)
+ return url =~ VALID_VEOH_URL_REGEX
+ end
+
+
+ def get_video_url()
+ # First, figure out the video id from the URL.
+ # Then, use the video id to construct the video details URL.
+ # Get the video details page, and parse the redirect
+ # URL from it. Now, I guess we *could* retrieve the video
+ # id from the redirect, but for now we're going to rely
+ # on our HTTP library to follow the redirect for us and
+ # save us a step.
+ video_id = self.parse_video_id()
+ details_url = "http://www.veoh.com/rest/video/#{video_id}/details"
+ details_data = get_page_data(details_url)
+ redirect_url = parse_redirect_url(details_data)
+
+ # We trust our HTTP library to do the right thing here.
+ return redirect_url
+ end
+
+
+ def get_video_filename()
+ return (self.parse_video_id() + '.flv')
+ end
+
+ protected;
+
+ def parse_video_id()
+ video_id_regex = /v[[:alnum:]]+$/
+ matches = video_id_regex.match(@url)
+ video_id = matches[0] if not matches.nil?
+
+ return video_id
+ end
+
+
+ # The main video page has the "video" URL buried
+ # in some javascript parameters.
+ def parse_redirect_url(page_data)
+ redirect_url_regex = /fullPreviewHashPath=\"(.*?)\"/
+ matches = redirect_url_regex.match(page_data)
+ redirect_url = matches[1] if not matches.nil? || matches.length < 2
+
+ return redirect_url
+ end
+
+
+end