diff --git a/app/models/communication/block/template/video.rb b/app/models/communication/block/template/video.rb index c69e4f07cdac33db3f95ec17036f7f2887e7e293..aca2443ddc02b8da59c351b913e6f1f5e873237e 100644 --- a/app/models/communication/block/template/video.rb +++ b/app/models/communication/block/template/video.rb @@ -5,7 +5,12 @@ class Communication::Block::Template::Video < Communication::Block::Template::Ba has_component :transcription, :text def video_iframe - video_provider.iframe_tag(title: video_title) + video_provider.iframe_tag(title: video_iframe_title) + end + + def video_iframe_title + video_title.blank? ? 'Video' + : video_title end def video_platform @@ -24,6 +29,10 @@ class Communication::Block::Template::Video < Communication::Block::Template::Ba video_provider.embed end + def video_embed_with_defaults + video_provider.embed_with_defaults + end + protected def video_provider diff --git a/app/models/communication/website/with_security.rb b/app/models/communication/website/with_security.rb index d9aa9041dac34550347d6b6d985dc3bc6d396e40..94e4a3ea981928fc3cd4ef9e8624cbc8c1a57f77 100644 --- a/app/models/communication/website/with_security.rb +++ b/app/models/communication/website/with_security.rb @@ -34,7 +34,7 @@ module Communication::Website::WithSecurity blocks.where(template_kind: :video).each do |block| video_url = block.template.url next unless video_url.present? - list << Video::Provider.find(video_url).csp_domain + list.concat Video::Provider.find(video_url).csp_domains end list end diff --git a/app/services/video/provider/dailymotion.rb b/app/services/video/provider/dailymotion.rb index 1bd00d94096c4dd1c661711538fd62ab8208e15d..b88d1adcdab42553e66a9d1dff2dd2be519874b4 100644 --- a/app/services/video/provider/dailymotion.rb +++ b/app/services/video/provider/dailymotion.rb @@ -1,11 +1,19 @@ class Video::Provider::Dailymotion < Video::Provider::Default - DOMAINS = ['dailymotion.com', 'dai.ly'] + DOMAINS = [ + 'dailymotion.com', + 'www.dailymotion.com', + 'dai.ly' + ] def identifier video_url.include?('dai.ly') ? video_url.split('dai.ly/').last : video_url.split('video/').last end + def csp_domains + DOMAINS + end + # https://www.dailymotion.com/thumbnail/video/x8lyp39 def poster "https://www.dailymotion.com/thumbnail/video/#{identifier}" diff --git a/app/services/video/provider/default.rb b/app/services/video/provider/default.rb index d3e202b44cdb27a61a9539a22cde9586ddd94b62..cb8b7b3ec048b661d26e486cf966a60f0be48a3f 100644 --- a/app/services/video/provider/default.rb +++ b/app/services/video/provider/default.rb @@ -17,14 +17,18 @@ class Video::Provider::Default video_url end - def csp_domain - URI.parse(iframe_url).host + def csp_domains + [host] end def identifier '' end + def host + URI.parse(iframe_url).host + end + def poster '' end @@ -33,6 +37,10 @@ class Video::Provider::Default iframe_url end + def embed_with_defaults + embed + end + def iframe_tag(**iframe_options) content_tag(:iframe, nil, default_iframe_options.merge(iframe_options)) end @@ -43,7 +51,7 @@ class Video::Provider::Default def default_iframe_options { - class: (platform == :default ? nil : platform), + class: platform, loading: 'lazy', src: iframe_url } diff --git a/app/services/video/provider/peertube.rb b/app/services/video/provider/peertube.rb index af3b2ce744b0f0f392d0d60618fda3f52ae0a3cc..3c43e1c23db03a1b59a9faaf4e3acf81c61ac985 100644 --- a/app/services/video/provider/peertube.rb +++ b/app/services/video/provider/peertube.rb @@ -1,17 +1,15 @@ class Video::Provider::Peertube < Video::Provider::Default - DOMAINS = ['peertube.fr'] + DOMAINS = [ + 'peertube.fr' + ] def identifier video_url.split('/w/').last end - def host - video_url.split('/w/').first - end - # https://docs.joinpeertube.org/support/doc/api/embeds#quick-start def iframe_url - "#{host}/videos/embed/#{identifier}" + "#{instance}/videos/embed/#{identifier}" end def correct? @@ -20,6 +18,10 @@ class Video::Provider::Peertube < Video::Provider::Default protected + def instance + video_url.split('/w/').first + end + def url_looks_like_peertube? "/w/".in?(video_url) || "/videos/watch/".in?(video_url) end diff --git a/app/services/video/provider/vimeo.rb b/app/services/video/provider/vimeo.rb index 47e696cd18fdde9e5596891164015788a3c8a3c2..237714608c9e26e8a74644c7f5320530fb09028a 100644 --- a/app/services/video/provider/vimeo.rb +++ b/app/services/video/provider/vimeo.rb @@ -1,10 +1,18 @@ class Video::Provider::Vimeo < Video::Provider::Default - DOMAINS = ['vimeo.com'] + DOMAINS = [ + 'vimeo.com', + 'player.vimeo.com', + 'vumbnail.com' + ] def identifier video_url.chomp('/').split('/').last end + def csp_domains + DOMAINS + end + # https://vumbnail.com/621585396.jpg def poster "https://vumbnail.com/#{identifier}.jpg" diff --git a/app/services/video/provider/youtube.rb b/app/services/video/provider/youtube.rb index 4b1d9494934dc816d2b790aad71399f226111469..88c249d6eb97e8e99ff1bd30789e1ab8d32f1f7b 100644 --- a/app/services/video/provider/youtube.rb +++ b/app/services/video/provider/youtube.rb @@ -1,11 +1,20 @@ class Video::Provider::Youtube < Video::Provider::Default - DOMAINS = ['youtube.com', 'youtu.be'] + DOMAINS = [ + 'youtube.com', + 'www.youtube.com', + 'img.youtube.com', + 'youtu.be', + ] def identifier video_url.include?('youtu.be') ? identifier_path : identifier_param end + def csp_domains + DOMAINS + end + # https://img.youtube.com/vi/XEEUOiTgJL0/hqdefault.jpg def poster "https://img.youtube.com/vi/#{identifier}/hqdefault.jpg" @@ -16,6 +25,11 @@ class Video::Provider::Youtube < Video::Provider::Default "https://www.youtube.com/embed/#{identifier}" end + # L'autoplay est à 1 uniquement parce que l'iframe n'est pas chargée + def embed_with_defaults + "#{iframe_url}?autoplay=1&modestbranding=1&rel=0" + end + protected def identifier_path diff --git a/app/views/admin/communication/blocks/templates/video/_static.html.erb b/app/views/admin/communication/blocks/templates/video/_static.html.erb index e0a5e480b84ab0f15456e8c7ca27cc386736b4c4..e915bf01ceb33f4d9f8ecaab5b9dacbf7e54341e 100644 --- a/app/views/admin/communication/blocks/templates/video/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/video/_static.html.erb @@ -10,6 +10,8 @@ <%= block.template.video_poster %> embed: >- <%= block.template.video_embed %> + embed_with_defaults: >- + <%= block.template.video_embed_with_defaults %> iframe: >- <%= block.template.video_iframe %> <% end %> diff --git a/test/services/video/provider_test.rb b/test/services/video/provider_test.rb index c5d4ab978dffc3e9388181801f7cd0e3cfcead50..d9cbd9b0ae87a54f4f9ab713e2b69646a4d8b3af 100644 --- a/test/services/video/provider_test.rb +++ b/test/services/video/provider_test.rb @@ -10,33 +10,33 @@ class Video::ProviderTest < ActiveSupport::TestCase def test_vimeo provider = Video::Provider.find('https://vimeo.com/248482251') assert_equal Video::Provider::Vimeo, provider.class - assert_equal "player.vimeo.com", provider.csp_domain + assert "player.vimeo.com".in?(provider.csp_domains) end def test_youtube provider = Video::Provider.find('https://www.youtube.com/watch?v=sN8Cq5HEBug') assert_equal Video::Provider::Youtube, provider.class - assert_equal "www.youtube.com", provider.csp_domain + assert "www.youtube.com".in?(provider.csp_domains) provider = Video::Provider.find('https://youtu.be/sN8Cq5HEBug') assert_equal Video::Provider::Youtube, provider.class - assert_equal "www.youtube.com", provider.csp_domain + assert "www.youtube.com".in?(provider.csp_domains) end def test_dailymotion provider = Video::Provider.find('https://www.dailymotion.com/video/x35l6b8') assert_equal Video::Provider::Dailymotion, provider.class - assert_equal "www.dailymotion.com", provider.csp_domain + assert "www.dailymotion.com".in?(provider.csp_domains) provider = Video::Provider.find('https://dai.ly/x35l6b8') assert_equal Video::Provider::Dailymotion, provider.class - assert_equal "www.dailymotion.com", provider.csp_domain + assert "www.dailymotion.com".in?(provider.csp_domains) end def test_peertube provider = Video::Provider.find('https://peertube.fr/w/1i848Qvi7Q3ytW2uPY8AxG') assert_equal Video::Provider::Peertube, provider.class - assert_equal "peertube.fr", provider.csp_domain + assert "peertube.fr".in?(provider.csp_domains) provider = Video::Provider.find('https://peertube.my.noesya.coop/w/qBMwAAULLA9oadFgbtdyq8') assert_equal Video::Provider::Peertube, provider.class - assert_equal "peertube.my.noesya.coop", provider.csp_domain + assert "peertube.my.noesya.coop".in?(provider.csp_domains) end end \ No newline at end of file