From: Michael Orlitzky Date: Sat, 17 Apr 2010 19:31:09 +0000 (-0400) Subject: Add support for dailymotion.com, with tests. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fwhatever-dl.git;a=commitdiff_plain;h=455d65b183518c9fb23470cc5f3a987046de0965 Add support for dailymotion.com, with tests. --- diff --git a/src/websites/dailymotion.rb b/src/websites/dailymotion.rb new file mode 100644 index 0000000..f988ce6 --- /dev/null +++ b/src/websites/dailymotion.rb @@ -0,0 +1,56 @@ +# +# 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 Dailymotion < Website + + VALID_DAILYMOTION_URL_REGEX = /^(http:\/\/)?(www\.)?dailymotion\.com\/video\/(.+)$/ + + def self.owns_url?(url) + return url =~ VALID_DAILYMOTION_URL_REGEX + end + + + def get_video_url() + # Disable the family filter if necessary. + headers = { 'Cookie' => 'family_filter=off' } + page_data = self.get_page_data(@url, headers) + video_url = self.parse_video_url(page_data) + + return video_url + end + + + protected; + + # Get the FLV file URL from the HTML page for this movie. + # It's stored in some Flash variable. + def parse_video_url(page_data) + video_url_regex = /addVariable\(\"video\", \"([^\"]+)\"/i + matches = video_url_regex.match(page_data) + + if (matches.nil? || matches.length < 2) + raise StandardError.new('Could not find the "video" flash variable on the page.'); + end + + return matches[1] + end + + +end diff --git a/test/dailymotion_test.rb b/test/dailymotion_test.rb new file mode 100644 index 0000000..25ae463 --- /dev/null +++ b/test/dailymotion_test.rb @@ -0,0 +1,58 @@ +# +# 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 'test/unit' +require 'src/websites/dailymotion' + + +class DailymotionTest < Test::Unit::TestCase + + def test_owns_dailymotion_urls + assert(Dailymotion.owns_url?('http://www.dailymotion.com/video/xavgrm_japanese-cosplay-babes_news#hp-v-v8')) + assert(Dailymotion.owns_url?('http://www.dailymotion.com/video/xavgrm_japanese-cosplay-babes_news')) + assert(Dailymotion.owns_url?('http://www.dailymotion.com/video/xcuw24_penn-edgar-feature_sport#hp-v-v5')) + assert(Dailymotion.owns_url?('http://www.dailymotion.com/video/xcuw24_penn-edgar-feature_sport')) + assert(Dailymotion.owns_url?('http://www.dailymotion.com/video/x241fi_epic-movie-mrs-new-booty')) + end + + + def test_doesnt_own_infoq_urls + assert(!Dailymotion.owns_url?('http://www.infoq.com/interviews/jim-weirich-discusses-rake')) + end + + + def test_doesnt_own_efukt_urls + assert(!Dailymotion.owns_url?('http://www.efukt.com/2308_How_To_Fuck_Like_A_King.html')) + assert(!Dailymotion.owns_url?('http://www.efukt.com/2304_The_Dumbest_Porno_Ever_Made.html')) + end + + + def test_parse_video_url + ft = Dailymotion.new(nil) + + page_data = nil + + File.open('test/fixtures/dailymotion/ms_new_booty.html') do |f| + page_data = f.read + end + + test_result = ft.send('parse_video_url', page_data) + assert_equal('http://www.dailymotion.com/cdn/FLV-320x240/video/x241fi.flv?auth=1271704672-bc7bb7d6447e816d9247908b89407d3e', test_result) + end + +end diff --git a/test/fixtures/dailymotion/ms_new_booty.html b/test/fixtures/dailymotion/ms_new_booty.html new file mode 100644 index 0000000..0c2252b --- /dev/null +++ b/test/fixtures/dailymotion/ms_new_booty.html @@ -0,0 +1,463 @@ + + + + Dailymotion - Epic Movie - Mrs. New Booty - une vidéo Comédie et Humour + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+
+
+
+
+
+
+
+
+

Epic Movie - Mrs. New Booty

+
+
+
+
+
+
+
+
+ +
+

541 views. | 0 com. | 0 fav.

+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
Vote!
+
+
+
+
+ + +
+
+
+
Channel: Funny
+
Uploaded: 05/29/07
+
+
+
Tags: fun drôle hip hop epic movie bubba sparxxx narnia pirates caraibes parodie shortfilms
+
+
+
+
+
+
+

Statistics

+
+
+
+
+ +
+
+
+
+
Comments are deactivated for this video.
+
+
+
+
+
+
+
+
advertising
+
+
+
+
+
+ + +
+ + + +
+
+
+
+
+
+ +
+ +
+ +
+
+ +
+ + + +
+
+ +
+ + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/test/test_suite.rb b/test/test_suite.rb index 2c60e68..67da44c 100644 --- a/test/test_suite.rb +++ b/test/test_suite.rb @@ -17,6 +17,7 @@ # require 'test/bliptv_test' +require 'test/dailymotion_test' require 'test/efukt_test' require 'test/fuckedtube_test' require 'test/howcast_test'