diff --git a/lib/onebox/engine/youtube_onebox.rb b/lib/onebox/engine/youtube_onebox.rb index fed887f221c..128df9b1656 100644 --- a/lib/onebox/engine/youtube_onebox.rb +++ b/lib/onebox/engine/youtube_onebox.rb @@ -103,6 +103,11 @@ module Onebox id ||= uri.path[/\/embed\/([\w\-]+)/, 1] end + # https://www.youtube.com/shorts/wi2jAtpBl0Y + if uri.path["/shorts/"] + id ||= uri.path[/\/shorts\/([\w\-]+)/, 1] + end + # https://www.youtube.com/watch?v=Z0UISCEe52Y id ||= params['v'] diff --git a/spec/fixtures/onebox/youtube-shorts.response b/spec/fixtures/onebox/youtube-shorts.response new file mode 100644 index 00000000000..f6baa80a399 --- /dev/null +++ b/spec/fixtures/onebox/youtube-shorts.response @@ -0,0 +1,7 @@ +YouTube
\ No newline at end of file diff --git a/spec/lib/onebox/engine/youtube_onebox_spec.rb b/spec/lib/onebox/engine/youtube_onebox_spec.rb index 9a59e897fa1..ad56cb307ff 100644 --- a/spec/lib/onebox/engine/youtube_onebox_spec.rb +++ b/spec/lib/onebox/engine/youtube_onebox_spec.rb @@ -14,6 +14,8 @@ RSpec.describe Onebox::Engine::YoutubeOnebox do stub_request(:get, "https://www.youtube.com/playlist?list=PL5308B2E5749D1696").to_return(status: 200, body: onebox_response("youtube-playlist")) stub_request(:get, "https://www.youtube.com/embed/KCyIfcevExE").to_return(status: 200, body: onebox_response("youtube-embed")) + + stub_request(:get, "https://www.youtube.com/embed/VvoFuaLAslw").to_return(status: 200, body: onebox_response("youtube-shorts")) end it "adds wmode=opaque" do @@ -103,4 +105,10 @@ RSpec.describe Onebox::Engine::YoutubeOnebox do preview.to match(/Delvon/) preview.to match(/hqdefault/) end + + it "can parse youtube shorts results" do + preview = expect(Onebox.preview('https://youtube.com/shorts/VvoFuaLAslw').placeholder_html) + preview.to match(/POMBO/) + preview.to match(/hqdefault/) + end end