From: Michael Orlitzky Date: Sat, 28 Jun 2008 05:11:00 +0000 (-0400) Subject: Added the ability to download Veoh files. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=cb1b5a8a87ec46656e3d860c208210a5cc24a32e;p=dead%2Fwhatever-dl.git Added the ability to download Veoh files. Added a new Veoh class, along with a couple of tests and one fixture file (of video details data). --- diff --git a/src/websites/veoh.rb b/src/websites/veoh.rb new file mode 100644 index 0000000..e10d985 --- /dev/null +++ b/src/websites/veoh.rb @@ -0,0 +1,88 @@ +# +# 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' + +# Needed to download the page, which is in turn +# needed because it contains the video (redirect) URL. +require 'net/http' +require 'uri' + + +class Veoh < Website + + VALID_VEOH_URL_REGEX = /^(http:\/\/)?(www\.)?veoh\.com\/videos\/([[:alnum:]]+)$/ + + def self.owns_url?(url) + return url =~ VALID_VEOH_URL_REGEX + end + + + def get_video_url(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 = parse_video_id(url) + 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) + + # Being slightly explicit about what we're doing here... + video_url = redirect_url + + return video_url + end + + + protected; + + def parse_video_id(url) + video_id_regex = /[[: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 < 1) + + return redirect_url + end + + + def get_page_data(url) + uri = URI.parse(url) + + response = Net::HTTP.start(uri.host, uri.port) do |http| + http.get(uri.path) + end + + return response.body + end + +end diff --git a/test/fixtures/veoh/details_data-v801204yMZ8BWcC.xml b/test/fixtures/veoh/details_data-v801204yMZ8BWcC.xml new file mode 100644 index 0000000..303f57e --- /dev/null +++ b/test/fixtures/veoh/details_data-v801204yMZ8BWcC.xml @@ -0,0 +1,245 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/test_suite.rb b/test/test_suite.rb index ddc078e..6150e08 100644 --- a/test/test_suite.rb +++ b/test/test_suite.rb @@ -1,5 +1,6 @@ require 'test/howcast_test' require 'test/infoq_test' require 'test/redtube_test' +require 'test/veoh_test' require 'test/website_test' require 'test/youporn_test' diff --git a/test/veoh_test.rb b/test/veoh_test.rb new file mode 100644 index 0000000..f104d3a --- /dev/null +++ b/test/veoh_test.rb @@ -0,0 +1,33 @@ +require 'test/unit' +require 'src/websites/veoh' + +class VeohTest < Test::Unit::TestCase + + def test_parse_video_id + v = Veoh.new + video_id = v.send('parse_video_id', 'http://www.veoh.com/videos/v801204yMZ8BWcC') + assert_equal('v801204yMZ8BWcC', video_id) + end + + + def test_parse_redirect_url + v = Veoh.new + + details_data = nil + + File.open('test/fixtures/veoh/details_data-v801204yMZ8BWcC.xml') do |f| + details_data = f.read + end + + actual_result = v.send('parse_redirect_url', details_data) + expected_result = 'http://content.veoh.com/flash/p/801204/7b55b0e3fef09c5599ba2ab3d6a270c3dc9c0a0d.flv?ct=8c18f78c97a2df5cb5f7d849dce97c28996b0835dfc71ce9' + + assert_equal(expected_result, actual_result) + end + + + def test_owns_veoh_urls + assert(Veoh.owns_url?('http://www.veoh.com/videos/v801204yMZ8BWcC')) + end + +end