X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fwhatever-dl.git;a=blobdiff_plain;f=src%2Fwebsites%2Fyoutube.rb;h=ed5ab4b8a96efa62ee49379caf205f9b89c5e69c;hp=5f87754f9de85e69a3124f22c192f7df57e20a93;hb=dbde07faafd93f8a9503c1fedfe317723da7cac5;hpb=5eb21ca889d29ca8ee8b5e6b7de9d0fb6c88266d diff --git a/src/websites/youtube.rb b/src/websites/youtube.rb index 5f87754..ed5ab4b 100644 --- a/src/websites/youtube.rb +++ b/src/websites/youtube.rb @@ -124,31 +124,43 @@ class Youtube < Website # Parse out the "t" parameter from the video's page. I'm not sure - # what "t" stands for, but it's located in some JSON, and is required - # for the final video URL to work. + # what "t" stands for, but it's required for the final video URL to + # work. It can be stored in either JSON or URL parameters. def parse_t_parameter(page_data) t_parameter = nil - t_parameter_regex = /\"t\"\:[[:space:]]\"([^\"]+?)\"/ - matches = t_parameter_regex.match(page_data) - t_parameter = matches[1] if not (matches.nil? || matches.length < 2) + t_parameter_regexes = [ /\"t\"\:[[:space:]]\"([^\"]+?)\"/, + /&t=([^&\"\\]+)/ ] + matches = t_parameter_regexes.map { |tpr| tpr.match(page_data) } + + if matches.nitems == 0 + raise StandardError.new("Could not parse the 't' parameter.") + end + + first_match = matches.compact[0] + t_parameter = CGI::unescape(first_match[1]) return t_parameter end def get_available_formats(page_data) - # Parse the list of available formats from the "fmt_list" Flash - # variable. + # Parse the list of available formats from the "fmt_list" + # variable. It can be stored as either a Flash variable (JSON + # notation), or as URL parameter. available_formats = [] - fmt_list_regex = /\"fmt_list\"\:[[:space:]]\"([^\"]+?)\"/ - matches = fmt_list_regex.match(page_data) + fmt_list_regexes = [ /\"fmt_list\"\:[[:space:]]\"([^\"]+?)\"/, + /fmt_list=([^&\"\\]+)/ ] - if matches.nil? + matches = fmt_list_regexes.map { |flr| flr.match(page_data) } + + if matches.nitems == 0 raise StandardError.new("Could not find any valid formats.") end - fmts_string = CGI::unescape(matches[1]) + first_match = matches.compact[0] + fmts_string = CGI::unescape(first_match[1]) + fmts_string.split(',').each do |fmt| # Each "fmt" will look something like, #