mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 12:08:12 -05:00
FEATURE: Handle youtube live url format (#31673)
Meta: https://meta.discourse.org/t/youtube-autoembeds-for-live-streams/350920 This PR supports YouTube live URLs, such as: `https://www.youtube.com/live/eJemwqO0SDw`.  
This commit is contained in:
@@ -112,6 +112,9 @@ module Onebox
|
||||
# https://www.youtube.com/shorts/wi2jAtpBl0Y
|
||||
id ||= uri.path[%r{/shorts/([\w\-]+)}, 1] if uri.path["/shorts/"]
|
||||
|
||||
# https://www.youtube.com/live/eJemwqO0SDw
|
||||
id ||= uri.path[%r{/live/([\w\-]+)}, 1] if uri.path["/live/"]
|
||||
|
||||
# https://www.youtube.com/watch?v=Z0UISCEe52Y
|
||||
id ||= params["v"]
|
||||
|
||||
|
||||
@@ -22,6 +22,14 @@ RSpec.describe Onebox::Engine::YoutubeOnebox do
|
||||
status: 200,
|
||||
body: onebox_response("youtube"),
|
||||
)
|
||||
stub_request(:get, "https://www.youtube.com/live/eJemwqO0SDw").to_return(
|
||||
status: 200,
|
||||
body: onebox_response("youtube"),
|
||||
)
|
||||
stub_request(:get, "https://www.youtube.com/embed/eJemwqO0SDw").to_return(
|
||||
status: 200,
|
||||
body: onebox_response("youtube"),
|
||||
)
|
||||
|
||||
stub_request(:get, "https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ").to_return(
|
||||
status: 200,
|
||||
@@ -99,6 +107,9 @@ RSpec.describe Onebox::Engine::YoutubeOnebox do
|
||||
expect(Onebox.preview("https://www.youtube.com/watch?v=21Lk4YiASMo").placeholder_html).to match(
|
||||
/<img/,
|
||||
)
|
||||
expect(Onebox.preview("https://www.youtube.com/live/eJemwqO0SDw").placeholder_html).to match(
|
||||
/<img/,
|
||||
)
|
||||
expect(Onebox.preview("https://youtu.be/21Lk4YiASMo").placeholder_html).to match(/<img/)
|
||||
end
|
||||
|
||||
@@ -186,4 +197,10 @@ RSpec.describe Onebox::Engine::YoutubeOnebox do
|
||||
preview.to match(/POMBO/)
|
||||
preview.to match(/hqdefault/)
|
||||
end
|
||||
|
||||
it "can parse youtube live URLs" do
|
||||
preview = expect(Onebox.preview("https://www.youtube.com/live/eJemwqO0SDw").to_s)
|
||||
preview.to match(/iframe/)
|
||||
preview.to include("embed/eJemwqO0SDw")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user