lib/flickvimeo/video.rb in flickvimeo-1.0.0 vs lib/flickvimeo/video.rb in flickvimeo-1.0.1

- old
+ new

@@ -40,18 +40,20 @@ def config @config ||= begin response = http_request(@url) if m = response.body.match(/clip\d+_\d+ = (.*)?;Player.checkRatio/) - # Cleanup javascript to be valid JSON - json = m[1].gsub(/([\{\[,]\s*)([a-zA-Z_]+):/) { %{#{$1}"#{$2}":} } - json = json.gsub(/(:\s*)'(.*?)'/, '\1"\2"') - - Yajl::Parser.parse(json) + Yajl::Parser.parse(convert_javascript_to_valid_json(m[1])) end end end + def convert_javascript_to_valid_json(input) + # Cleanup javascript to be valid JSON + json = input.gsub(/([\{\[,]\s*)([a-zA-Z_]+):/) { %{#{$1}"#{$2}":} } + json = json.gsub(/(:\s*)'((?:[^'\\]|\\.)*)'/, '\1"\2"') + end + def vimeo_url(id) case id.to_s when %r{^http://.*vimeo.com.*[#/](\d+)} "http://player.vimeo.com/video/#{$1}" when /^\d+$/ \ No newline at end of file