- fmt_list_regex = /\"fmt_list\"\:[[:space:]]\"([^\"]+?)\"/
- matches = fmt_list_regex.match(page_data)
-
- if matches.nil?
- return nil
- else
- fmts_string = CGI::unescape(matches[1])
-
- fmts_string.split(',').each do |fmt|
- # Each "fmt" will look something like,
- #
- # 35/640000/9/0/115
- #
- # with the format identifier coming before the first slash.
- first_slash_idx = fmt.index('/')
- available_formats << fmt[0...first_slash_idx].to_i
- end
-
+ fmt_list_regexes = [ /\"fmt_list\"\:[[:space:]]\"([^\"]+?)\"/,
+ /fmt_list=([^&\"\\]+)/ ]
+
+ matches = fmt_list_regexes.map { |flr| flr.match(page_data) }
+
+ if matches.nitems == 0
+ raise StandardError.new("Could not find any valid formats.")
+ end
+
+ first_match = matches.compact[0]
+ fmts_string = CGI::unescape(first_match[1])
+
+ fmts_string.split(',').each do |fmt|
+ # Each "fmt" will look something like,
+ #
+ # 35/640000/9/0/115
+ #
+ # with the format identifier coming before the first slash.
+ first_slash_idx = fmt.index('/')
+ available_formats << fmt[0...first_slash_idx].to_i