Add Kaltura.com support (#395)

Add Kaltura.com support (#395)

  • Adds kaltura support using OpenGraph

  • Use normalized urls when building html and preview

diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb
index 4eb4675..7a17175 100644
--- a/lib/onebox/engine.rb
+++ b/lib/onebox/engine.rb
@@ -185,3 +185,4 @@ require_relative "engine/wistia_onebox"
 require_relative "engine/instagram_onebox"
 require_relative "engine/gitlab_blob_onebox"
 require_relative "engine/google_photos_onebox"
+require_relative "engine/kaltura_onebox"
diff --git a/lib/onebox/engine/kaltura_onebox.rb b/lib/onebox/engine/kaltura_onebox.rb
new file mode 100644
index 0000000..2d84527
--- /dev/null
+++ b/lib/onebox/engine/kaltura_onebox.rb
@@ -0,0 +1,33 @@
+module Onebox
+  module Engine
+    class KalturaOnebox
+      include Engine
+      include StandardEmbed
+
+      always_https
+      matches_regexp(/^https?:\/\/[a-z0-9]+\.kaltura\.com\/id\/[a-zA-Z0-9]+/)
+
+      def preview_html
+        og = get_opengraph
+        thumbnail_url = ::Onebox::Helpers.normalize_url_for_output(og[:image_secure_url])
+
+        <<~HTML
+          <img src="#{thumbnail_url}" width="#{og[:video_width]}" height="#{og[:video_height]}" >
+        HTML
+      end
+
+      def to_html
+        og = get_opengraph
+        embedded_video_url = ::Onebox::Helpers.normalize_url_for_output(og[:video_secure_url])
+
+        <<~HTML
+          <iframe src="#{embedded_video_url}"
+                  width="#{og[:video_width]}" height="#{og[:video_height]}"
+                  frameborder='0'
+                  allowfullscreen >
+          </iframe>
+        HTML
+      end
+    end
+  end
+end
diff --git a/spec/fixtures/kaltura.response b/spec/fixtures/kaltura.response
new file mode 100644
index 0000000..75483f4
--- /dev/null
+++ b/spec/fixtures/kaltura.response
@@ -0,0 +1,781 @@
+<!DOCTYPE html>
+
+
+
+<!--[if lte IE 7]> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="ie7"> <![endif]-->
+<!--[if IE 8]>     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="ie8"> <![endif]-->
+<!--[if IE 9]>     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="ie9"> <![endif]-->
+<!--[if !IE]><!--> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">             <!--<![endif]-->
+
+<head>
+    <link rel="search" type="application/opensearchdescription+xml" href="/osd">
+<meta http-equiv='X-UA-Compatible' content='requiresActiveX=true' /><!-- viewhook start modulesHeader -->
+ <meta name="google-site-verification" content="eCsPknr-P4BkdOLI61hdhotMYXlbop2K1pkdrBW0Rjc" /> 
+<!-- BEGIN FACEBOOK OPEN GRAPH TAGS -->
+    <meta property="og:title" content="Kaltura Overview" />
+    <meta property="og:url" content="https://videos.kaltura.com/media/Kaltura+Overview/0_e2ea6ygt" />
+
+    <meta property="og:description" content="Kaltura powers any video experience. Watch this video to get a quick glimpse into the breadth and depth of the Kaltura Video Platform and our market-leading video solutions." />
+    <meta property="og:type" content="video" />
+    <meta property="og:image" content="http://cdnapi.kaltura.com/p/811441/sp/81144100/thumbnail/entry_id/0_e2ea6ygt/width/534" />
+    <meta property="og:image:secure_url" content="https://cdnapisec.kaltura.com/p/811441/sp/81144100/thumbnail/entry_id/0_e2ea6ygt/width/534" />
+
+
+    <!-- direct asset ref -->
+    <meta property="og:video" content="https://cdnapisec.kaltura.com/p/811441/sp/81144100/playManifest/entryId/0_e2ea6ygt/flavorId/0_422v9u1n/format/url/protocol/http/a.mp4" />
+    <meta property="og:video:type" content="video/mp4" />
+    <meta property="og:site_name" content="Kaltura Videos" />
+    <!-- Facebook iframe embed -->
+    <meta property="og:video:url" content="https://cdnapisec.kaltura.com//p/811441/sp/81144100/embedIframeJs/uiconf_id/40430081/partner_id/811441?iframeembed=true&playerId=kaltura_player&entry_id=0_e2ea6ygt&widget_id=1_c6hc9mf5">
+    <meta property="og:video:secure_url" content="https://cdnapisec.kaltura.com//p/811441/sp/81144100/embedIframeJs/uiconf_id/40430081/partner_id/811441?iframeembed=true&playerId=kaltura_player&entry_id=0_e2ea6ygt&widget_id=1_c6hc9mf5">
+    <meta property="og:video:type" content="text/html">
+    <meta property="og:video:width" content="534">
+    <meta property="og:video:height" content="300">
+    <!-- legacy swf embed -->
+    <meta property="og:video:url" content="https://cdnapisec.kaltura.com/index.php/kwidget/wid/_811441/uiconf_id/40430081/entry_id/0_e2ea6ygt?widget_id=1_c6hc9mf5" />
+    <meta property="og:video:secure_url" content="https://cdnapisec.kaltura.com/index.php/kwidget/wid/_811441/uiconf_id/40430081/entry_id/0_e2ea6ygt?widget_id=1_c6hc9mf5" />
+    <meta property="og:video:type" content="application/x-shockwave-flash">
+    <meta property="og:video:width" content="534" />
+    <meta property="og:video:height" content="300" />
+
+<!-- END FACEBOOK OPEN GRAPH TAGS -->
+
+<!-- BEGIN TWITTER TAGS -->
+<meta name="twitter:card" content="player">
+<meta name="twitter:site" content="@kaltura">
+<meta name="twitter:title" content="Kaltura Overview">
+<meta name="twitter:description" content="Kaltura powers any video experience. Watch this video to get a quick glimpse into the breadth and depth of the Kaltura Video Platform and our market-leading video solutions.">
+<meta name="twitter:image" content="https://cdnapisec.kaltura.com/p/811441/sp/81144100/thumbnail/entry_id/0_e2ea6ygt/width/534">
+<meta name="twitter:player" content="https://cdnapisec.kaltura.com/p/811441/sp/81144100/embedIframeJs/uiconf_id/40430081/partner_id/811441?iframeembed=true&playerId=kaltura_player&entry_id=0_e2ea6ygt&widget_id=1_c6hc9mf5">
+<meta name="twitter:player:width" content="600">
+<meta name="twitter:player:height" content="370">
+<meta name="twitter:player:stream" content="https://cdnapisec.kaltura.com/p/811441/sp/81144100/playManifest/entryId/0_e2ea6ygt/flavorId/0_422v9u1n/format/url/protocol/http/a.mp4">
+<meta name="twitter:player:stream:content_type" content="video/mp4; codecs=&quot;avc1.42E01E1, mp4a.40.2&quot;">
+
+<!-- END TWITTER TAGS -->
+
+<!-- viewhook end modulesHeader --><meta name="xsrf-ajax-nonce" content="eyJpdiI6IkFPSkpzNWowb0ZcL0ROOVwvUHdISVBTUT09IiwidmFsdWUiOiIwRG11UGp5T3dsZEdUMXgramE2cUNtRmQrd1dkc0lUYkl4bWtFTERLaHgyQzJrK3JpQlwvNnR2d1dzeEZaN1hENDhjMG5RbjlOSDZvMHJXcXhjaTh3bG8xZmMyUXRtWXNOTXh3SGFtUzhneGo2c00xWUI0bTBUTUlHWnhoMitKXC9FIiwibWFjIjoiZWU3N2IwNDQyNGZhMmVjMWQwMmI4ZjI5ZWE4ZGMwMDU3YmM3ZTMzOTNjMTZiY2ExYTlmZDAxMDljOWE0MzMxMiJ9" />
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1.0" />
+<meta name="smartbanner:title" content="Kaltura MediaSpace Go" />
+<meta name="smartbanner:author" content=" " />
+<meta name="smartbanner:price" content="FREE" />
+<meta name="smartbanner:price-suffix-apple" content=" - On the App Store" />
+<meta name="smartbanner:price-suffix-google" content=" - In Google Play" />
+<meta name="smartbanner:icon-apple" content="https://kms-a.akamaihd.net/dc-0/5.82.16/public/build0/kmsapi/asset/kaltura_logo.png" />
+<meta name="smartbanner:icon-google" content="https://kms-a.akamaihd.net/dc-0/5.82.16/public/build0/kmsapi/asset/kaltura_logo.png" />
+<meta name="smartbanner:button" content="OPEN" />
+<meta name="smartbanner:button-url-apple" content="https://kmsgoapplication.page.link/?link=https%3A%2F%2Fvideos.kaltura.com%2Fid%2F0_e2ea6ygt%3Fwidth%3D400%26height%3D285%26playerId%3D32783592&amp;ibi=com.kaltura.kmsv2&amp;isi=1054967774" />
+<meta name="smartbanner:button-url-google" content="https://kmsgoapplication.page.link/?link=https%3A%2F%2Fvideos.kaltura.com%2Fid%2F0_e2ea6ygt%3Fwidth%3D400%26height%3D285%26playerId%3D32783592&amp;apn=com.kms.kaltura.kmsapplication" />
+<meta name="smartbanner:enabled-platforms" content="android,ios" />
+<meta name="smartbanner:hide-ttl" content="10000" />
+<meta name="smartbanner:custom-design-modifier" content="kmsapi" />
+<meta name="smartbanner:disable-positioning" content="true" /><title>Kaltura Overview - Kaltura Videos</title>
+

[... diff too long, it was truncated ...]

GitHub sha: 9d20c645

1 Like