FEATURE: reddit video onebox

FEATURE: reddit video onebox

diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb
index 4260664..7571148 100644
--- a/lib/onebox/engine.rb
+++ b/lib/onebox/engine.rb
@@ -176,5 +176,5 @@ require_relative "engine/instagram_onebox"
 require_relative "engine/gitlab_blob_onebox"
 require_relative "engine/google_photos_onebox"
 require_relative "engine/kaltura_onebox"
-require_relative "engine/reddit_image_onebox"
+require_relative "engine/reddit_media_onebox"
 require_relative "engine/google_drive_onebox"
diff --git a/lib/onebox/engine/reddit_image_onebox.rb b/lib/onebox/engine/reddit_image_onebox.rb
deleted file mode 100644
index ab19023..0000000
--- a/lib/onebox/engine/reddit_image_onebox.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-module Onebox
-  module Engine
-    class RedditImageOnebox
-      include Engine
-      include StandardEmbed
-
-      matches_regexp(/^https?:\/\/(www\.)?reddit\.com/)
-
-      def to_html
-        if raw[:type] == "image"
-          <<-HTML
-            <aside class="onebox reddit">
-              <header class="source">
-                <img src="#{raw[:favicon]}" class="site-icon" width="16" height="16">
-                <a href="#{raw[:url]}" target="_blank" rel="nofollow ugc noopener">#{raw[:site_name]}</a>
-              </header>
-              <article class="onebox-body">
-                <h3><a href="#{raw[:url]}" target="_blank" rel="nofollow ugc noopener">#{raw[:title]}</a></h3>
-                <div class="scale-images">
-                  <img src="#{raw[:image]}" class="scale-image"/>
-                </div>
-                <div class="description"><p>#{raw[:description]}</p></div>
-              </article>
-            </aside>
-          HTML
-        else
-          html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html
-          return if Onebox::Helpers.blank?(html)
-          html
-        end
-      end
-    end
-  end
-end
diff --git a/lib/onebox/engine/reddit_media_onebox.rb b/lib/onebox/engine/reddit_media_onebox.rb
new file mode 100644
index 0000000..9678c07
--- /dev/null
+++ b/lib/onebox/engine/reddit_media_onebox.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module Onebox
+  module Engine
+    class RedditMediaOnebox
+      include Engine
+      include StandardEmbed
+
+      matches_regexp(/^https?:\/\/(www\.)?reddit\.com/)
+
+      def to_html
+        if raw[:type] == "image"
+          <<-HTML
+            <aside class="onebox reddit">
+              <header class="source">
+                <img src="#{raw[:favicon]}" class="site-icon" width="16" height="16">
+                <a href="#{raw[:url]}" target="_blank" rel="nofollow ugc noopener">#{raw[:site_name]}</a>
+              </header>
+              <article class="onebox-body">
+                <h3><a href="#{raw[:url]}" target="_blank" rel="nofollow ugc noopener">#{raw[:title]}</a></h3>
+                <div class="scale-images">
+                  <img src="#{raw[:image]}" class="scale-image"/>
+                </div>
+                <div class="description"><p>#{raw[:description]}</p></div>
+              </article>
+            </aside>
+          HTML
+        elsif  raw[:type] =~ /^video[\/\.]/
+          <<-HTML
+            <aside class="onebox reddit">
+              <header class="source">
+                <img src="#{raw[:favicon]}" class="site-icon" width="16" height="16">
+                <a href="#{raw[:url]}" target="_blank" rel="nofollow ugc noopener">#{raw[:site_name]}</a>
+              </header>
+              <article class="onebox-body">
+                <h3><a href="#{raw[:url]}" target="_blank" rel="nofollow ugc noopener">#{raw[:title]}</a></h3>
+                <div class="aspect-image-full-size">
+                  <a href="#{raw[:url]}" target="_blank" rel="nofollow ugc noopener">
+                    <img src="#{raw[:image]}" class="scale-image"/>
+                    <span class="reddit-video-icon"></span>
+                  </a>
+                </div>
+                <div class="description"><p>#{raw[:description]}</p></div>
+              </article>
+            </aside>
+          HTML
+        else
+          html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @timeout).to_html
+          return if Onebox::Helpers.blank?(html)
+          html
+        end
+      end
+    end
+  end
+end
diff --git a/spec/lib/onebox/engine/reddit_image_spec.rb b/spec/lib/onebox/engine/reddit_image_spec.rb
deleted file mode 100644
index 4559871..0000000
--- a/spec/lib/onebox/engine/reddit_image_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-require "spec_helper"
-
-describe Onebox::Engine::RedditImageOnebox do
-  let(:link) { "https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition" }
-  let(:html) { described_class.new(link).to_html }
-
-  before do
-    fake(link, response("reddit_image"))
-  end
-
-  it "includes title" do
-    expect(html).to include('<a href="https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition/" target="_blank" rel="nofollow ugc noopener">reddit</a>')
-  end
-
-  it "includes image" do
-    expect(html).to include("https://preview.redd.it/vsg59iw0srn21.jpg")
-  end
-
-  it "includes description" do
-    expect(html).to include("Literally nothing black edition")
-  end
-end
diff --git a/spec/lib/onebox/engine/reddit_media_onebox.rb b/spec/lib/onebox/engine/reddit_media_onebox.rb
new file mode 100644
index 0000000..0b183cd
--- /dev/null
+++ b/spec/lib/onebox/engine/reddit_media_onebox.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+describe Onebox::Engine::RedditMediaOnebox do
+  let(:link) { "https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition" }
+  let(:html) { described_class.new(link).to_html }
+
+  before do
+    fake(link, response("reddit_image"))
+  end
+
+  it "includes title" do
+    expect(html).to include('<a href="https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition/" target="_blank" rel="nofollow ugc noopener">reddit</a>')
+  end
+
+  it "includes image" do
+    expect(html).to include("https://preview.redd.it/vsg59iw0srn21.jpg")
+  end
+
+  it "includes description" do
+    expect(html).to include("Literally nothing black edition")
+  end
+end

GitHub sha: 0d49811a

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/video-embeds-from-facebook-com-and-other-sites-fail/149366/28