FEATURE: Youtube Short onebox support (#19335)

* FEATURE: Youtube Shorts onebox support

Co-authored-by: Canapin <canapin@gmail.com>
This commit is contained in:
Rafael dos Santos Silva 2022-12-06 11:56:48 -03:00 committed by GitHub
parent 57fe57e7ce
commit d247e5d37c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -103,6 +103,11 @@ module Onebox
id ||= uri.path[/\/embed\/([\w\-]+)/, 1] id ||= uri.path[/\/embed\/([\w\-]+)/, 1]
end 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 # https://www.youtube.com/watch?v=Z0UISCEe52Y
id ||= params['v'] id ||= params['v']

File diff suppressed because one or more lines are too long

View File

@ -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/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/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 end
it "adds wmode=opaque" do it "adds wmode=opaque" do
@ -103,4 +105,10 @@ RSpec.describe Onebox::Engine::YoutubeOnebox do
preview.to match(/Delvon/) preview.to match(/Delvon/)
preview.to match(/hqdefault/) preview.to match(/hqdefault/)
end 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 end