# encoding: UTF-8 require 'open-uri' require 'nokogiri' require 'rack' module Spontaneous::Field class WebVideo class YouTube < Provider def self.id "youtube" end def self.match(field, url) case url when /youtube\.com.*\?.*v=([^&]+)/, /youtu\.be\/([^&]+)/ video_id = $1 new(field, :video_id => video_id, :provider => id).metadata else nil end end def metadata @attributes.update(download_metadata) end def to_html(options = {}) params = player_attributes(options) attributes = hash_to_attributes(params[:attr]) %() end def as_json(options = {}) player_attributes(options) end def player_attributes(options = {}) o = player_options(options) attributes = { :type => "text/html", :frameborder => "0", :width => o.delete(:width), :height => o.delete(:height) } make_query_options!(o) attributes[:src] = src_with_options(o) attributes.update(:webkitAllowFullScreen => "yes", :allowFullScreen => "yes") if o[:fullscreen] {:tagname => "iframe", :tag => "