From 6e9cec676f28db2fe9fd5872bc0ec7ebb954f5f6 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 2 Oct 2009 15:28:39 -0400 Subject: [PATCH] Updated Redtube to work with the site's new algorithm. Made one local Redtube test a remote test. Updated the remote test suite to include the Redtube remote tests. Added a local fixture for Redtube tests. Added one local test utilizing the new fixture. --- src/websites/redtube.rb | 49 +++- test/fixtures/redtube/6807.html | 425 ++++++++++++++++++++++++++++++++ test/redtube_remote_test.rb | 33 +++ test/redtube_test.rb | 24 +- test/remote_test_suite.rb | 1 + 5 files changed, 518 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/redtube/6807.html create mode 100644 test/redtube_remote_test.rb diff --git a/src/websites/redtube.rb b/src/websites/redtube.rb index 39ca901..3b1a4fa 100644 --- a/src/websites/redtube.rb +++ b/src/websites/redtube.rb @@ -54,14 +54,29 @@ class Redtube < Website video_dir = self.get_video_dir(video_id) file_name = self.get_file_name(padded_id) - # This mess is actually the only directory out of - # which they serve videos. - return 'http://dl.redtube.com/_videos_t4vn23s9jc5498tgj49icfj4678/' + - "#{video_dir}/#{file_name}" + page_data = self.get_page_data(@url) + + # As far as I know, the MP4s don't work yet. + # So just default to the FLV. + top_secret_hash = parse_hash_flv(page_data) + + return 'http://dl.redtube.com/' + + self.get_root_server_dir() + + "/#{video_dir}/#{file_name}" + + top_secret_hash end - - protected + + def get_video_filename() + # Mildly redundant. + video_id = parse_video_id() + padded_id = video_id.to_s.pad_left('0', 7) + + return self.get_file_name(padded_id) + end + + + protected; VIDEO_FILE_EXTENSION = '.flv' @@ -69,6 +84,28 @@ class Redtube < Website return /\d+/.match(@url)[0] end + + + def parse_hash_flv(page_data) + # Hashes are generated for both flv/mp4 and are delivered + # along with the video page. We need to stick them back on + # the end of the final video URL, or else it doesn't work. + hash_flv_regex = /&hash_flv=(\/.*?)&/ + + matches = hash_flv_regex.match(page_data) + + if matches.nil? + raise StandardError.new("Couldn't parse the hash_flv variable.") + end + + return matches[1] + end + + + def get_root_server_dir() + # They hard code this shit into the SWF file. + return '467f9bca32b1989277b48582944f325afa3374' + end # Not sure what they're thinking with this one. def get_video_dir(video_id) diff --git a/test/fixtures/redtube/6807.html b/test/fixtures/redtube/6807.html new file mode 100644 index 0000000..a269797 --- /dev/null +++ b/test/fixtures/redtube/6807.html @@ -0,0 +1,425 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Cum in her ass - RedTube - Free Porn Videos + + + + +
+
+
+ +
+ + + +
+
+ + + + +
+ + + + + +
+ + + +

Cum in her ass

+
+
+
+ + +
+
+ +
+ + + + +
+
+ +
+
+

Rate this Video

+ +

3,193 ratings

+ + +

+ + Embed + + Embed this video
on your website
+

+
+ +
+ + +
+
+ +
+

Related Videos

+ +
+ +
+

Related Premium Videos

+
+ +
+
+ + + + + + + +
+ +
+
+ +
+ + + +
+ +
+
+ +
+ + + + diff --git a/test/redtube_remote_test.rb b/test/redtube_remote_test.rb new file mode 100644 index 0000000..6bf44c7 --- /dev/null +++ b/test/redtube_remote_test.rb @@ -0,0 +1,33 @@ +# +# 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/redtube' + + +class RedtubeRemoteTest < Test::Unit::TestCase + + def test_get_video_url + # Won't work locally because we need the hash_flv attribute from the page. + rt = Redtube.new('http://www.redtube.com/6807') + expected_result = 'http://dl.redtube.com/467f9bca32b1989277b48582944f325afa3374/0000006/X57OBH08G.flv/1a9f62001c523752dc9a6bc3f7f5acad/4ac64671' + actual_result = rt.get_video_url() + assert_equal(expected_result, actual_result) + end + +end diff --git a/test/redtube_test.rb b/test/redtube_test.rb index 9d6c709..e226f81 100644 --- a/test/redtube_test.rb +++ b/test/redtube_test.rb @@ -46,14 +46,6 @@ class RedtubeTest < Test::Unit::TestCase end - def test_get_video_url - rt = Redtube.new('http://www.redtube.com/6807') - expected_result = 'http://dl.redtube.com/_videos_t4vn23s9jc5498tgj49icfj4678/0000006/X57OBH08G.flv' - actual_result = rt.get_video_url() - assert_equal(expected_result, actual_result) - end - - def test_get_video_filename rt = Redtube.new('http://www.redtube.com/6807') # I don't know where they get these filenames from, but whatever. @@ -61,4 +53,20 @@ class RedtubeTest < Test::Unit::TestCase actual_result = rt.get_video_filename() assert_equal(expected_result, actual_result) end + + + + def test_parse_hash_flv + rt = Redtube.new(nil) + + page_data = nil + + File.open('test/fixtures/redtube/6807.html') do |f| + page_data = f.read + end + + test_result = rt.send('parse_hash_flv', page_data) + assert_equal('/be03bc2d810017a8689d96c61a626303/4ac6529f', test_result) + end + end diff --git a/test/remote_test_suite.rb b/test/remote_test_suite.rb index 5068cf1..be135f7 100644 --- a/test/remote_test_suite.rb +++ b/test/remote_test_suite.rb @@ -18,5 +18,6 @@ require 'test/fuckedtube_remote_test' require 'test/infoq_remote_test' +require 'test/redtube_remote_test' require 'test/uri_utilities_remote_test' require 'test/youporn_remote_test' -- 2.43.2