From 8e886df259246365023322b78f58e4037cb536a4 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 10 Jun 2012 20:23:39 -0400 Subject: [PATCH] Fix all Ruby 1.9 errors and warnings. --- bin/whatever-dl | 4 ++-- src/websites/efukt.rb | 4 ++-- src/websites/generic.rb | 4 ++-- src/websites/megaporn.rb | 2 -- src/websites/redtube.rb | 2 +- src/websites/tnaflix.rb | 9 ++------- src/websites/veoh.rb | 2 +- src/websites/vimeo.rb | 14 +++++++------- src/websites/yikers.rb | 2 +- src/websites/youporn.rb | 1 + src/websites/youtube.rb | 17 ++++++++++------- vendor/ruby-progressbar/progressbar.rb | 3 ++- 12 files changed, 31 insertions(+), 33 deletions(-) diff --git a/bin/whatever-dl b/bin/whatever-dl index 787e9db..146dbec 100755 --- a/bin/whatever-dl +++ b/bin/whatever-dl @@ -32,7 +32,7 @@ require 'getoptlong' # 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' @@ -95,7 +95,7 @@ if (__FILE__ == $0) then 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 diff --git a/src/websites/efukt.rb b/src/websites/efukt.rb index 0a1e10e..0818eac 100644 --- a/src/websites/efukt.rb +++ b/src/websites/efukt.rb @@ -49,7 +49,7 @@ class Efukt < Website 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 @@ -63,7 +63,7 @@ class Efukt < Website 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.'); diff --git a/src/websites/generic.rb b/src/websites/generic.rb index 51fe078..0453727 100644 --- a/src/websites/generic.rb +++ b/src/websites/generic.rb @@ -51,14 +51,14 @@ class Generic < Website 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 diff --git a/src/websites/megaporn.rb b/src/websites/megaporn.rb index bbd55c2..57a61a7 100644 --- a/src/websites/megaporn.rb +++ b/src/websites/megaporn.rb @@ -16,8 +16,6 @@ # 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 diff --git a/src/websites/redtube.rb b/src/websites/redtube.rb index 4de8772..78480c9 100644 --- a/src/websites/redtube.rb +++ b/src/websites/redtube.rb @@ -34,7 +34,7 @@ class Redtube < 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 diff --git a/src/websites/tnaflix.rb b/src/websites/tnaflix.rb index 7fd5f90..cc6bfd0 100644 --- a/src/websites/tnaflix.rb +++ b/src/websites/tnaflix.rb @@ -29,11 +29,6 @@ class Tnaflix < Website 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' @@ -53,7 +48,7 @@ class Tnaflix < Website 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 @@ -64,7 +59,7 @@ class Tnaflix < Website 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 diff --git a/src/websites/veoh.rb b/src/websites/veoh.rb index d2744c3..951d87d 100644 --- a/src/websites/veoh.rb +++ b/src/websites/veoh.rb @@ -66,7 +66,7 @@ class Veoh < Website 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 diff --git a/src/websites/vimeo.rb b/src/websites/vimeo.rb index f8e6ad3..a6a4ea3 100644 --- a/src/websites/vimeo.rb +++ b/src/websites/vimeo.rb @@ -77,9 +77,9 @@ class Vimeo < Website # 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 @@ -90,7 +90,7 @@ class Vimeo < Website # It's XML. rs_regex = /(.*?)<\/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 @@ -99,16 +99,16 @@ class Vimeo < Website def parse_request_signature_expires(page_data) rse_regex = /(.*?)<\/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 = /([01])<\isHD>/ + quality_regex = /([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 diff --git a/src/websites/yikers.rb b/src/websites/yikers.rb index 8cf407a..9784cf5 100644 --- a/src/websites/yikers.rb +++ b/src/websites/yikers.rb @@ -57,7 +57,7 @@ class Yikers < Website 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 diff --git a/src/websites/youporn.rb b/src/websites/youporn.rb index 3e98e9b..2c453dd 100644 --- a/src/websites/youporn.rb +++ b/src/websites/youporn.rb @@ -66,6 +66,7 @@ class Youporn < Website def get_headers() headers = { 'Referer' => @url, 'Content-Type' => 'application/x-www-form-urlencoded' } + return headers end diff --git a/src/websites/youtube.rb b/src/websites/youtube.rb index bdf2c2c..2ab4678 100644 --- a/src/websites/youtube.rb +++ b/src/websites/youtube.rb @@ -67,7 +67,7 @@ class Youtube < Website # 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. @@ -173,20 +173,23 @@ class Youtube < Website # 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 diff --git a/vendor/ruby-progressbar/progressbar.rb b/vendor/ruby-progressbar/progressbar.rb index 507082d..cb56056 100644 --- a/vendor/ruby-progressbar/progressbar.rb +++ b/vendor/ruby-progressbar/progressbar.rb @@ -126,7 +126,8 @@ class ProgressBar 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 -- 2.44.2