+ 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
+
+ return available_formats
+ end
+
+
+ def get_desired_format(available_formats)
+ # Check for the presence of formats, in order of preference
+ # (quality). That is, we check for the best formats first. As soon
+ # as a format is found to be available, we return it as the
+ # desired format, since the first format we find is going to be
+ # the best available format.
+ return 37 if available_formats.include?(37)
+ return 22 if available_formats.include?(22)
+ return 35 if available_formats.include?(35)
+ return 18 if available_formats.include?(18)
+ return 34 if available_formats.include?(34)
+ return 17 if available_formats.include?(17)