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'
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)