]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/commitdiff
Added the ability to download Veoh files.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 28 Jun 2008 05:11:00 +0000 (01:11 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 28 Jun 2008 05:11:00 +0000 (01:11 -0400)
Added a new Veoh class, along with a couple of tests and one fixture file (of video details data).

src/websites/veoh.rb [new file with mode: 0644]
test/fixtures/veoh/details_data-v801204yMZ8BWcC.xml [new file with mode: 0644]
test/test_suite.rb
test/veoh_test.rb [new file with mode: 0644]

diff --git a/src/websites/veoh.rb b/src/websites/veoh.rb
new file mode 100644 (file)
index 0000000..e10d985
--- /dev/null
@@ -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 (file)
index 0000000..303f57e
--- /dev/null
@@ -0,0 +1,245 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+       \r
+               \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+       \r
+\r
+<videos offset="0" items="1" numItems="1" title="" guid="958c15f1-421c-44f9-8e71-eb0d8dd622c5"  >\r
+\r
+       \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+       \r
+               \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+       \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+       \r
+       \r
+\r
+       \r
+       \r
+\r
+       \r
+       \r
+\r
+       \r
+       \r
+\r
+\r
+\r
+\r
+       \r
+\r
+\r
+
+
+\r
+\r
+<video videoId="801204"\r
+       uploadToken=""\r
+       permalinkId="v801204yMZ8BWcC"\r
+       extension=".avi"\r
+       length="22 min 5 sec"\r
+       size="177805312"\r
+       releaseHash=""\r
+       tags="christmas tv funhouse christmas day comedy central"\r
+       tagsCommaSeparated=" christmas,  tv funhouse,  christmas day,  comedy central"\r
+       category="Movies &amp; TV"\r
+       previewHash="7b55b0e3fef09c5599ba2ab3d6a270c3dc9c0a0d"\r
+       fullPreviewHashPath="http://content.veoh.com/flash/p/801204/7b55b0e3fef09c5599ba2ab3d6a270c3dc9c0a0d.flv?ct=8c18f78c97a2df5cb5f7d849dce97c28996b0835dfc71ce9" \r
+       fullPreviewToken=""\r
+       previewHashLow="7b55b0e3fef09c5599ba2ab3d6a270c3dc9c0a0d"\r
+       fullPreviewHashLowPath="http://content.veoh.com/flash/p/801204/7b55b0e3fef09c5599ba2ab3d6a270c3dc9c0a0d.flv?ct=8c18f78c97a2df5cb5f7d849dce97c28996b0835dfc71ce9" \r
+       fullPreviewTokenLow=""\r
+       highResImage="media-v801204yMZ8BWcC1184584929.jpg"\r
+       fullHighResImagePath="http://p-images.veoh.com/image.out?imageId=media-v801204yMZ8BWcC1184584929.jpg"\r
+       medResImage="thumb-v801204yMZ8BWcC-24.jpg"\r
+       fullMedResImagePath="http://p-images.veoh.com/image.out?imageId=thumb-v801204yMZ8BWcC-24.jpg"\r
+       username="marvelocity"\r
+       views="1287"\r
+       rating="3.67"\r
+       numRatingVotes="3"\r
+       description="Episode 3 - Christmas Day"\r
+       title="TV Funhouse - 3 - Christmas Day"\r
+       dateAdded="2007-07-16 08:36:00"\r
+       age="11 months ago"\r
+       primaryCollectionPermalink=""\r
+       primaryCollectionTitle=""\r
+       primaryCollectionThumb=""\r
+       allowEmbedding="true"\r
+       premium="false"\r
+       paidContent="false" \r
+       \r
+       \r
+       portable="false" \r
+       ipodLink="" \r
+       showStreamingAd="1"\r
+       showCompanionAd="false"\r
+       \r
+       \r
+       houseAdDetailsUrl=""\r
+       houseAdPlacement="-1"\r
+       geoRestrictions=""\r
+       \r
+       \r
+       \r
+       \r
+       \r
+                                               \r
+       flashHash=""\r
+       flashExtension=""\r
+       flashPieceHashFile="http://p-cache.veoh.com/cache/veoh/.veoh"\r
+       flashUrlRoot="http://p-cache.veoh.com/cache"\r
+                                               \r
+       originalHash="ba231020e2bc45cc292cb9b2748c2b3d7d418753"\r
+       origExtension=".avi"    \r
+       originalPieceHashFile="http://p-cache.veoh.com/cache/veoh/ba231020e2bc45cc292cb9b2748c2b3d7d418753.veoh"\r
+       originalUrlRoot="http://p-cache.veoh.com/cache"\r
+       \r
+       \r
+               contentRating="2"\r
+       \r
+\r
+       \r
+       \r
+       \r
+       licenseId=""\r
+       licenseName=""\r
+       licenseType=""\r
+       licenseExpires=""\r
+       licensePrice=""\r
+       licenseDuration=""\r
+       licenseTimeUnits=""\r
+       \r
+       \r
+       \r
+       \r
+               aowPublisherName=""\r
+               aowPermalink=""\r
+               aowEmbedCode=""\r
+               aowGuideVideoId=""\r
+       \r
+       \r
+       isExternalMedia="false"\r
+       isDotComPlayable="true"\r
+       isTvPlayable="true"\r
+>\r
+       \r
+       \r
+       \r
+       \r
+       \r
+       \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+</video>\r
+\r
+       \r
+</videos>\r
+       \r
+       \r
+       \r
+       \r
+\r
index ddc078ebc6ba19c4477e61f841c9dd5dda2e6e11..6150e08637789ef6c63dfebfda815790425abb8b 100644 (file)
@@ -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 (file)
index 0000000..f104d3a
--- /dev/null
@@ -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