Sha256: 7ce250593804ad205a1edb8c1bb0b0619c6ea55cb6e654ff71e811c18dea33ce

Contents?: true

Size: 1.04 KB

Versions: 34

Compression:

Stored size: 1.04 KB

Contents

module Onebox
  module Engine
    class YoukuOnebox
      include Engine
      include HTML

      matches_regexp(/^(https?:\/\/)?([\da-z\.-]+)(youku.com\/)(.)+\/?$/)

      # Try to get the video ID. Works for URLs of the form:
      # * http://v.youku.com/v_show/id_XNjM3MzAxNzc2.html
      # * http://v.youku.com/v_show/id_XMTQ5MjgyMjMyOA==.html?from=y1.3-tech-index3-232-10183.89969-89963.3-1
      def video_id
        match = uri.path.match(/\/v_show\/id_([a-zA-Z0-9_=\-]+)(\.html)?.*/)
        return match[1] if match && match[1]

        nil
      rescue
        return nil
      end

      def to_html
        "<embed width='570' height='360' src='https://players.youku.com/player.php/sid/#{video_id}/v.swf' wmode='transparent' allowFullScreen='true' quality='high' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash'></embed>"
      end

      def placeholder_html
        to_html
      end

      private

      # Note: May throw! Make sure to rescue.
      def uri
        @_uri ||= URI(@url)
      end

    end 
  end 
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
onebox-1.7.3 lib/onebox/engine/youku_onebox.rb
onebox-1.7.2 lib/onebox/engine/youku_onebox.rb
onebox-1.7.1 lib/onebox/engine/youku_onebox.rb
onebox-1.7.0 lib/onebox/engine/youku_onebox.rb
onebox-1.6.9 lib/onebox/engine/youku_onebox.rb
onebox-1.6.8 lib/onebox/engine/youku_onebox.rb
onebox-1.6.7 lib/onebox/engine/youku_onebox.rb
onebox-1.6.6 lib/onebox/engine/youku_onebox.rb
onebox-1.6.5 lib/onebox/engine/youku_onebox.rb
onebox-1.6.4 lib/onebox/engine/youku_onebox.rb
onebox-1.6.3 lib/onebox/engine/youku_onebox.rb
onebox-1.6.2 lib/onebox/engine/youku_onebox.rb
onebox-1.6.1 lib/onebox/engine/youku_onebox.rb
onebox-1.6.0 lib/onebox/engine/youku_onebox.rb
onebox-1.5.65 lib/onebox/engine/youku_onebox.rb
onebox-1.5.64 lib/onebox/engine/youku_onebox.rb
onebox-1.5.63 lib/onebox/engine/youku_onebox.rb
onebox-1.5.62 lib/onebox/engine/youku_onebox.rb
onebox-1.5.61 lib/onebox/engine/youku_onebox.rb
onebox-1.5.60 lib/onebox/engine/youku_onebox.rb