X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fwebsites%2Fredtube.rb;h=4de8772e9f27a8f695f231b16bbd7e00a934536e;hb=9a0f311962f0348bb676e513e18b378e4ad11086;hp=3b1a4fa5005641817a2f0cc4f87902e8d20f263f;hpb=6e9cec676f28db2fe9fd5872bc0ec7ebb954f5f6;p=dead%2Fwhatever-dl.git diff --git a/src/websites/redtube.rb b/src/websites/redtube.rb index 3b1a4fa..4de8772 100644 --- a/src/websites/redtube.rb +++ b/src/websites/redtube.rb @@ -14,160 +14,64 @@ # GNU General Public License for more details. # # http://www.fsf.org/licensing/licenses/gpl.html -# -# -# NOTE: -# -# All credit belongs to whomever reverse-engineered the Redtube -# Flash applet in the first place. I took the algorithm from this -# script: -# -# http://userscripts.org/scripts/review/8691 -# -# and merely cleaned it up a bit while porting it to Ruby. -# -# The Redtube class needs the extra string methods.. -require 'src/string' require 'src/website' +require 'cgi' + -# This class handles the algorithm magic needed to get -# the URL from a Redtube video id. class Redtube < Website VALID_REDTUBE_URL_REGEX = /^(http:\/\/)?(www\.)?redtube\.com\/(\d+)$/ - + def self.owns_url?(url) return url =~ VALID_REDTUBE_URL_REGEX end - # The only public method. This calls the other parts - # of the algorithm and, with any luck, we wind up with - # the URL to the video. def get_video_url() - # First, parse the video ID out of the URL. - video_id = parse_video_id() - - padded_id = video_id.to_s.pad_left('0', 7) - - video_dir = self.get_video_dir(video_id) - file_name = self.get_file_name(padded_id) - 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 - - - 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) + begin + # We prefer to parse the HTML5 version because it can come in a + # nicer container format. + return parse_html5_src(page_data) + rescue StandardError => e + return self.parse_hashlink(page_data) + end end protected; - VIDEO_FILE_EXTENSION = '.flv' - def parse_video_id() return /\d+/.match(@url)[0] end + def parse_html5_src(page_data) + html5_src_regex = /\"= 10 then - new_char = my_int.to_s - end - - file_name = map[file_string[3] - 48 + my_int + 3] - file_name += new_char[1,1] - file_name += map[file_string[0] - 48 + my_int + 2] - file_name += map[file_string[2] - 48 + my_int + 1] - file_name += map[file_string[5] - 48 + my_int + 6] - file_name += map[file_string[1] - 48 + my_int + 5] - file_name += new_char[0,1] - file_name += map[file_string[4] - 48 + my_int + 7] - file_name += map[file_string[6] - 48 + my_int + 4] - file_name += VIDEO_FILE_EXTENSION - - return file_name - end - - end