A platform for community discussion. Free, open, simple.
FIX: Display a thumbnail for Youtube videos with the classic onebox (#35715)
Loïc Guitauteba1c8090c81
diff --git a/lib/onebox/engine/youtube_onebox.rb b/lib/onebox/engine/youtube_onebox.rbindex 0344b8a804e..10953c1706b 100644--- a/lib/onebox/engine/youtube_onebox.rb+++ b/lib/onebox/engine/youtube_onebox.rb@@ -46,7 +46,7 @@ module Oneboxreturnend- @parse_embed_response = { image: image, title: title }+ @parse_embed_response = { image:, title: }enddef placeholder_html@@ -63,6 +63,7 @@ module Oneboxdef to_htmlif video_id<<-HTML+ <img class="youtube-thumbnail onebox" style="display: none;" src="#{video_thumbnail_url}"><iframesrc="#{self.class.embed_url(video_id)}?#{embed_params}"width="#{WIDTH}"@@ -192,6 +193,10 @@ module Oneboxrescue StandardError{}end++ def video_thumbnail_url+ "https://img.youtube.com/vi/#{video_id}/maxresdefault.jpg"+ endendendenddiff --git a/spec/lib/onebox/engine/youtube_onebox_spec.rb b/spec/lib/onebox/engine/youtube_onebox_spec.rbindex 8c2fcd82449..21c07ca4d8c 100644--- a/spec/lib/onebox/engine/youtube_onebox_spec.rb+++ b/spec/lib/onebox/engine/youtube_onebox_spec.rb@@ -203,4 +203,8 @@ RSpec.describe Onebox::Engine::YoutubeOnebox dopreview.to match(/iframe/)preview.to include("embed/eJemwqO0SDw")end++ it "generates a thumbnail for videos" do+ expect(Onebox.preview("https://www.youtube.com/watch?v=21Lk4YiASMo").to_s).to match("<img")+ endend