class Redtube < Website
VALID_REDTUBE_URL_REGEX = /^(http:\/\/)?(www\.)?redtube\.com\/(\d+)$/
-
+
def self.owns_url?(url)
return url =~ VALID_REDTUBE_URL_REGEX
end
def get_video_url()
page_data = self.get_page_data(@url)
- return self.parse_hashlink(page_data)
+ 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
end
+ def parse_html5_src(page_data)
+ html5_src_regex = /\"<source src='([^']+?)'/
+
+ matches = html5_src_regex.match(page_data)
+
+ if matches.nil? or matches.length < 2
+ raise StandardError.new("Could not parse the HTML5 source src.")
+ else
+ return matches[1]
+ end
+
+ end
+
+
def parse_hashlink(page_data)
hashlink_regex = /hashlink=([^&]+)&/
matches = hashlink_regex.match(page_data)
- if matches.nil?
+ if matches.nil? or matches.length < 2
raise StandardError.new("Could not parse the 'hashlink' Flash variable.")
end
# The hashlink variable /is/ the video URL, but it's encoded.
return CGI::unescape(matches[1])
end
-
+
end