From: Michael Orlitzky Date: Fri, 2 Oct 2009 02:16:02 +0000 (-0400) Subject: Added support for blip.tv. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=d56c687299c6db6d4571c78ddb54e5da0d8b96ca;p=dead%2Fwhatever-dl.git Added support for blip.tv. Created the Bliptv class. Added several tests, along with fixtures, for the new class. Added the Bliptv tests to the test suite. --- diff --git a/src/websites/bliptv.rb b/src/websites/bliptv.rb new file mode 100644 index 0000000..9322356 --- /dev/null +++ b/src/websites/bliptv.rb @@ -0,0 +1,73 @@ +# +# 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 Bliptv < Website + + VALID_BLIPTV_URL_REGEX = /^(http:\/\/)?([[:alnum:]\-]+\.)?blip\.tv\/file\/(\d+)(.*)?$/ + + def self.owns_url?(url) + return url =~ VALID_BLIPTV_URL_REGEX + end + + + def get_video_url() + page_data = self.get_page_data(@url) + filepath = parse_video_url(page_data) + + return filepath + end + + + protected; + + + def parse_video_url(page_data) + # First, try to find the MOV video. The source videos are usually + # encoded with MOV. + video_url_regex = /"Quicktime \(\.mov\)", "attribute" : "(.*?\.mov)/i + matches = video_url_regex.match(page_data) + + if not matches.nil? + return matches[1] + end + + # If that didn't work, try the WMV format, which is occasionally + # used for the source as well. + video_url_regex = /"Windows Media \(\.wmv\)", "attribute" : "(.*?\.wmv)/i + matches = video_url_regex.match(page_data) + + if not matches.nil? + return matches[1] + end + + + # If neither of the source formats are present, just grab the + # video URL from the Flash variable and be done with it. + video_url_regex = /setPrimaryMediaUrl\("(.*?\.(flv|mov|wmv|mp4))/i + matches = video_url_regex.match(page_data) + + if matches.nil? + raise StandardError.new("Couldn't parse any of the video format URLs.") + end + + return matches[1] + end + +end diff --git a/test/bliptv_test.rb b/test/bliptv_test.rb new file mode 100644 index 0000000..8a763fe --- /dev/null +++ b/test/bliptv_test.rb @@ -0,0 +1,147 @@ +# +# 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/bliptv' + +class BliptvTest < Test::Unit::TestCase + + def test_owns_bliptv_urls + + assert(Bliptv.owns_url?('http://www.blip.tv/file/2664572?utm_source=featured_ep&utm_medium=featured_ep')) + assert(Bliptv.owns_url?('www.blip.tv/file/2664572?utm_source=featured_ep&utm_medium=featured_ep')) + assert(Bliptv.owns_url?('http://www.blip.tv/file/2664626')) + assert(Bliptv.owns_url?('http://www.blip.tv/file/2664626?utm_source=featured_ep&utm_medium=featured_ep')) + assert(Bliptv.owns_url?('http://urbansustainableliv.blip.tv/file/1189454/')) + assert(Bliptv.owns_url?('http://rosa-menkman.blip.tv/file/1947851/')) + assert(Bliptv.owns_url?('rosa-menkman.blip.tv/file/1947851/')) + assert(Bliptv.owns_url?('rosa-menkman.blip.tv/file/1947851/?utm_source=featured_ep&utm_medium=featured_ep')) + assert(Bliptv.owns_url?('rosa-menkman.blip.tv/file/1947851?utm_source=featured_ep&utm_medium=featured_ep')) + assert(Bliptv.owns_url?('http://www.blip.tv/file/2664626')) + end + + + def test_doesnt_own_redtube_urls + assert(!Bliptv.owns_url?('http://www.redtube.com/6807')) + assert(!Bliptv.owns_url?('www.redtube.com/6807')) + assert(!Bliptv.owns_url?('http://redtube.com/6807')) + assert(!Bliptv.owns_url?('redtube.com/6807')) + end + + + def test_doesnt_own_howcast_urls + assert(!Bliptv.owns_url?('http://www.howcast.com/videos/6807-2twr')) + assert(!Bliptv.owns_url?('www.howcast.com/videos/6807-2dgfdg')) + assert(!Bliptv.owns_url?('http://howcast.com/videos/6807-cse')) + assert(!Bliptv.owns_url?('howcast.com/videos/6807-asdgasd')) + end + + + def test_doesnt_own_misc_urls + assert(!Bliptv.owns_url?('http://www.bliptv.com/123456')) + end + + + def test_parse_flv_video_url + # Here we're trying to parse the video URL out of some standard + # blip.tv pages, where the video playing is in FLV format. In both + # of these cases, though, we want to parse the source (MOV/WMV) + # video URL. + btv = Bliptv.new(nil) + + page_data = nil + + File.open('test/fixtures/bliptv/1752651.htm') do |f| + page_data = f.read + end + + test_result = btv.send('parse_video_url', page_data) + assert_equal('http://blip.tv/file/get/Esequeira82-AdventuresInEgypt567.wmv', test_result) + + + # Second Fixture + + File.open('test/fixtures/bliptv/923819.htm') do |f| + page_data = f.read + end + + test_result = btv.send('parse_video_url', page_data) + assert_equal('http://blip.tv/file/get/Kantel-SadSong186.mov', test_result) + end + + + + def test_parse_mov_video_url + # These fixtures are saved from pages where the high-quality MOV + # format was already selected. + btv = Bliptv.new(nil) + + page_data = nil + + File.open('test/fixtures/bliptv/923682-mov.htm') do |f| + page_data = f.read + end + + test_result = btv.send('parse_video_url', page_data) + assert_equal('http://blip.tv/file/get/Kantel-UbiUndPythonDemo816.mov', test_result) + + + # Second Fixture + + File.open('test/fixtures/bliptv/923819-mov.htm') do |f| + page_data = f.read + end + + test_result = btv.send('parse_video_url', page_data) + assert_equal('http://blip.tv/file/get/Kantel-SadSong186.mov', test_result) + end + + + + def test_parse_mp4_video_url + # And why not check one of the MP4 pages, too? + + btv = Bliptv.new(nil) + + page_data = nil + + File.open('test/fixtures/bliptv/923682-mp4.htm') do |f| + page_data = f.read + end + + test_result = btv.send('parse_video_url', page_data) + assert_equal('http://blip.tv/file/get/Kantel-UbiUndPythonDemo816.mov', test_result) + end + + + def test_parse_mp4_video_url + # And why not check one of the MP4 pages, too? + + btv = Bliptv.new(nil) + + page_data = nil + + File.open('test/fixtures/bliptv/923682-no_alternatives.htm') do |f| + page_data = f.read + end + + test_result = btv.send('parse_video_url', page_data) + assert_equal('http://blip.tv/file/get/Kantel-UbiUndPythonDemo816.flv', test_result) + end + +end diff --git a/test/fixtures/bliptv/1752651.htm b/test/fixtures/bliptv/1752651.htm new file mode 100644 index 0000000..5a74b94 --- /dev/null +++ b/test/fixtures/bliptv/1752651.htm @@ -0,0 +1,880 @@ + + + + + + + + + + + + + Adventures in Egypt + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + +
+ +
+ + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
Adventures in Egypt
+
+
+
+
+ +
+ + + +
+
+ +
+ +
+ +
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution 2.0
+ + + A pictorial and video synopsis of a trip to the last remaining ancient wonder of the world. Please sit back, relax, and enjoy the sites while brownie productions entertains you. If you have any questions call me. +
+
+
+ + Play episode as : + +
+
+
+
+
+ +
+ +
+
+
+ Oh, look at that. +
+ +
+ No one has commented yet. Be the first! +
+
+
+
+ + +
+ + +
+
+
+
+
+
+
+ Hey! You must be logged in to add comments. Login or Register. +
+
+
+
+ + + + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
You've reached the newest episode.
+
+
+
+
+
+
You've reached the oldest episode.
+
+
+ +
+ + +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + +
+
+ +
+
+
+
+ + + + + + + + + + + +
+ + + + + +
   + +
+ + +
+
+ + + + + + + + + + + + diff --git a/test/fixtures/bliptv/923682-mov.htm b/test/fixtures/bliptv/923682-mov.htm new file mode 100644 index 0000000..73d5a19 --- /dev/null +++ b/test/fixtures/bliptv/923682-mov.htm @@ -0,0 +1,890 @@ + + + + + + + + + + + + + UbiGraph und Python: Demo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + +
+ +
+ + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
UbiGraph und Python: Demo
+
+
+
+
+ +
+ + + +
+
+ +
+ +
+ + + Mehr zu Ubi hier: http://www.ubietylab.net/ubigraph/index.html +
+
+
+ + Play episode as : + +
+
+
+
+
+ +
+ +
+
+
+ Oh, look at that. +
+ +
+ No one has commented yet. Be the first! +
+
+
+
+ + +
+ + +
+
+
+
+
+
+
+ Hey! You must be logged in to add comments. Login or Register. +
+
+
+
+ + + + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
You've reached the newest episode.
+
+
+
+
+
+
You've reached the oldest episode.
+
+
+ +
+ + +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + +
+
+ +
+
+
+
+ + + + + + + + + + + +
+ + + + + +
   + +
+ + +
+
+ + + + + + + + + + + + diff --git a/test/fixtures/bliptv/923682-mp4.htm b/test/fixtures/bliptv/923682-mp4.htm new file mode 100644 index 0000000..2e6d262 --- /dev/null +++ b/test/fixtures/bliptv/923682-mp4.htm @@ -0,0 +1,890 @@ + + + + + + + + + + + + + UbiGraph und Python: Demo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + +
+ +
+ + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
UbiGraph und Python: Demo
+
+
+
+
+ +
+ + + +
+
+ +
+ +
+ + + Mehr zu Ubi hier: http://www.ubietylab.net/ubigraph/index.html +
+
+
+ + Play episode as : + +
+
+
+
+
+ +
+ +
+
+
+ Oh, look at that. +
+ +
+ No one has commented yet. Be the first! +
+
+
+
+ + +
+ + +
+
+
+
+
+
+
+ Hey! You must be logged in to add comments. Login or Register. +
+
+
+
+ + + + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
You've reached the newest episode.
+
+
+
+
+
+
You've reached the oldest episode.
+
+
+ +
+ + +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + +
+
+ +
+
+
+
+ + + + + + + + + + + +
+ + + + + +
   + +
+ + +
+
+ + + + + + + + + + + + diff --git a/test/fixtures/bliptv/923682-no_alternatives.htm b/test/fixtures/bliptv/923682-no_alternatives.htm new file mode 100644 index 0000000..867c731 --- /dev/null +++ b/test/fixtures/bliptv/923682-no_alternatives.htm @@ -0,0 +1,884 @@ + + + + + + + + + + + + + UbiGraph und Python: Demo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + +
+ +
+ + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
UbiGraph und Python: Demo
+
+
+
+
+ +
+ + + +
+
+ +
+ +
+ + + Mehr zu Ubi hier: http://www.ubietylab.net/ubigraph/index.html +
+
+
+ + Play episode as : + +
+
+
+
+
+ +
+ +
+
+
+ Oh, look at that. +
+ +
+ No one has commented yet. Be the first! +
+
+
+
+ + +
+ + +
+
+
+
+
+
+
+ Hey! You must be logged in to add comments. Login or Register. +
+
+
+
+ + + + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
You've reached the newest episode.
+
+
+
+
+
+
You've reached the oldest episode.
+
+
+ +
+ + +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + +
+
+ +
+
+
+
+ + + + + + + + + + + +
+ + + + + +
   + +
+ + +
+
+ + + + + + + + + + + + diff --git a/test/fixtures/bliptv/923819-mov.htm b/test/fixtures/bliptv/923819-mov.htm new file mode 100644 index 0000000..9797f68 --- /dev/null +++ b/test/fixtures/bliptv/923819-mov.htm @@ -0,0 +1,880 @@ + + + + + + + + + + + + + Sad Song + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + +
+ +
+ + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
Sad Song
+
+
+
+
+ +
+ + + +
+
+ +
+ +
+ + + Apple Commercial mit John Hodgman. +
+
+
+ + Play episode as : + +
+
+
+
+
+ +
+ +
+
+
+ Oh, look at that. +
+ +
+ No one has commented yet. Be the first! +
+
+
+
+ + +
+ + +
+
+
+
+
+
+
+ Hey! You must be logged in to add comments. Login or Register. +
+
+
+
+ + + + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
You've reached the newest episode.
+
+
+
+
+
+
You've reached the oldest episode.
+
+
+ +
+ + +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + +
+
+ +
+
+
+
+ + + + + + + + + + + +
+ + + + + +
   + +
+ + +
+
+ + + + + + + + + + + + diff --git a/test/fixtures/bliptv/923819.htm b/test/fixtures/bliptv/923819.htm new file mode 100644 index 0000000..5150447 --- /dev/null +++ b/test/fixtures/bliptv/923819.htm @@ -0,0 +1,880 @@ + + + + + + + + + + + + + Sad Song + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + + +
+ +
+ + + + + + + + + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
Sad Song
+
+
+
+
+ +
+ + + +
+
+ +
+ +
+ + + Apple Commercial mit John Hodgman. +
+
+
+ + Play episode as : + +
+
+
+
+
+ +
+ +
+
+
+ Oh, look at that. +
+ +
+ No one has commented yet. Be the first! +
+
+
+
+ + +
+ + +
+
+
+
+
+
+
+ Hey! You must be logged in to add comments. Login or Register. +
+
+
+
+ + + + + +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
You've reached the newest episode.
+
+
+
+
+
+
You've reached the oldest episode.
+
+
+ +
+ + +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+ + + + + + + +
+
+ +
+
+
+
+ + + + + + + + + + + +
+ + + + + +
   + +
+ + +
+
+ + + + + + + + + + + + diff --git a/test/test_suite.rb b/test/test_suite.rb index 3cf8af3..d5d42c4 100644 --- a/test/test_suite.rb +++ b/test/test_suite.rb @@ -16,6 +16,7 @@ # http://www.fsf.org/licensing/licenses/gpl.html # +require 'test/bliptv_test' require 'test/efukt_test' require 'test/fuckedtube_test' require 'test/howcast_test'