# Thus, our require statements will work regardless of
# how or from where the script was run.
executable = Pathname.new(__FILE__).realpath.to_s
-$: << File.dirname(executable) + '/../'
+$LOAD_PATH << File.dirname(executable) + '/../'
# Load our config file.
require 'bin/configuration'
end
# Warn about nonsensical options.
- if options[:continue] and not (Configuration::DOWNLOAD_METHOD == :wget)
+ if options[:continue] and not Configuration::DOWNLOAD_METHOD == :wget
puts 'WARNING: The --continue flag does nothing unless DOWNLOAD_METHOD is :wget.'
end
matches = filename_regex.match(@url)
# Overwrite the default if our regex worked.
- filename = matches[1] if not (matches.nil? || matches.length < 1)
+ filename = matches[1] if not matches.nil? || matches.length < 1
return (filename + '.flv')
end
video_url_regex = /flashvars\.file = "(http:\/\/.*\.flv)"/i
matches = video_url_regex.match(page_data)
- if not (matches.nil? || matches.length < 2)
+ if not matches.nil? || matches.length < 2
return matches[1]
else
raise StandardError.new('Could not find the "file" Flash variable.');
full_video_url_regex = /(http:\/\/[^\"\']+?\.(flv|mp4))/i
matches = full_video_url_regex.match(page_data)
- if not (matches.nil? || matches.length < 2)
+ if not matches.nil? || matches.length < 2
return matches[1]
end
partial_video_url_regex = /([^\=\"\']+\.(flv|mp4))/i
matches = partial_video_url_regex.match(page_data)
- if not (matches.nil? || matches.length < 2)
+ if not matches.nil? || matches.length < 2
return base_url + matches[1]
end
# http://www.fsf.org/licensing/licenses/gpl.html
#
-# jcode still needed for String.each_char in Ruby 1.8.6.
-require 'jcode'
require 'src/website'
class Megaporn < Website
# 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
+ rescue StandardError
return self.parse_hashlink(page_data)
end
end
def get_video_url()
- # First, figure out the video id from the URL.
- # Then we download the page, and parse the Flash
- # variable that we need to construct the URL.
- video_id = self.parse_video_id()
-
# The old player page has the video URL conveniently
# stored in one variable.
old_player_url = @url + '&player=old'
def parse_video_id()
video_id_regex = /([[:alnum:]]+)(&player=old)?$/
matches = video_id_regex.match(@url)
- video_id = matches[1] if not (matches.nil? || matches.length < 2)
+ video_id = matches[1] if not matches.nil? || matches.length < 2
return video_id
end
def parse_video_url(page_data)
video_url_regex = /addVariable\(\'videoUrl\',\'([^\']+)/
matches = video_url_regex.match(page_data)
- video_url = matches[1] if not (matches.nil? || matches.length < 1)
+ video_url = matches[1] if not matches.nil? || matches.length < 1
return video_url
end
def parse_redirect_url(page_data)
redirect_url_regex = /fullPreviewHashPath=\"(.*?)\"/
matches = redirect_url_regex.match(page_data)
- redirect_url = matches[1] if not (matches.nil? || matches.length < 2)
+ redirect_url = matches[1] if not matches.nil? || matches.length < 2
return redirect_url
end
# If that didn't work, the URL must be of the clip_id= form.
video_id_regex = /clip_id\=(\d+)/
matches = video_id_regex.match(@url)
- video_id = matches[1] if not (matches.nil? || matches.length < 1)
+ video_id = matches[1] if not matches.nil? || matches.length < 1
else
- video_id = matches[1] if not (matches.nil? || matches.length < 1)
+ video_id = matches[1] if not matches.nil? || matches.length < 1
end
return video_id
# It's XML.
rs_regex = /<request_signature>(.*?)<\/request_signature>/
matches = rs_regex.match(page_data)
- request_signature = matches[1] if not (matches.nil? || matches.length < 1)
+ request_signature = matches[1] if not matches.nil? || matches.length < 1
return request_signature
end
def parse_request_signature_expires(page_data)
rse_regex = /<request_signature_expires>(.*?)<\/request_signature_expires>/
matches = rse_regex.match(page_data)
- request_signature_expires = matches[1] if not (matches.nil? || matches.length < 1)
+ rse = matches[1] if not matches.nil? || matches.length < 1
- return request_signature_expires
+ return rse
end
def parse_quality(page_data)
- quality_regex = /<isHD>([01])<\isHD>/
+ quality_regex = /<isHD>([01])<\/isHD>/
matches = quality_regex.match(page_data)
- is_hd = matches[1] if not (matches.nil? || matches.length < 1)
+ is_hd = matches[1] if not matches.nil? || matches.length < 1
if is_hd == '1' then
# High-definition
matches = filename_regex.match(@url)
# Overwrite the default if our regex worked.
- filename = matches[1] if not (matches.nil? || matches.length < 1)
+ filename = matches[1] if not matches.nil? || matches.length < 1
return (filename + '.flv')
end
def get_headers()
headers = { 'Referer' => @url,
'Content-Type' => 'application/x-www-form-urlencoded' }
+ return headers
end
# fmt_url_map hash.
video_url = fmt_url_map[desired_format]
return video_url
- rescue StandardError => e
+ rescue StandardError
# If at first you do not succeed, maybe someone decided to
# change some shit. This alternate method parses
# url_encoded_fmt_stream_map.
# We'll call /watch?v=video_id the "first form."
first_form_video_id_regex = /v=([0-9a-z_\-]+)/i
first_form_matches = first_form_video_id_regex.match(@url)
- return first_form_matches[1] if not (first_form_matches.nil? ||
- first_form_matches.length < 2)
+ if not first_form_matches.nil? || first_form_matches.length < 2
+ return first_form_matches[1]
+ end
# First form didn't work? Try the second.
second_form_video_id_regex = /\/v\/([0-9a-z_\-]+)/i
second_form_matches = second_form_video_id_regex.match(@url)
- return second_form_matches[1] if not (second_form_matches.nil? ||
- second_form_matches.length < 2)
+ if not second_form_matches.nil? || second_form_matches.length < 2
+ return second_form_matches[1]
+ end
# ...and the third.
third_form_video_id_regex = /\/([[:alnum:]]+)$/i
third_form_matches = third_form_video_id_regex.match(@url)
- return third_form_matches[1] if not (third_form_matches.nil? ||
- third_form_matches.length < 2)
+ if not third_form_matches.nil? || third_form_matches.length < 2
+ return third_form_matches[1]
+ end
# If we made it here, we couldn't figure out the video id. Yes,
# this is fatal, since we don't know where the video file is
tiocgwinsz = 0x5413
data = [0, 0, 0, 0].pack("SSSS")
if @out.ioctl(tiocgwinsz, data) >= 0 then
- rows, cols, xpixels, ypixels = data.unpack("SSSS")
+ # rows,cols,xpixels,ypixels
+ cols = data.unpack("SSSS")[1]
if cols >= 0 then cols else default_width end
else
default_width