From fc513c9cac7b955464bbcbcc8d00f802df5e6c08 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Wed, 11 Oct 2023 11:34:45 +0200
Subject: [PATCH] wip

---
 app/models/communication/block/template/video.rb       |  4 ++++
 app/services/video/provider/dailymotion.rb             |  1 +
 app/services/video/provider/default.rb                 |  4 ++++
 app/services/video/provider/peertube.rb                | 10 +++++-----
 app/services/video/provider/youtube.rb                 |  5 +++++
 .../blocks/templates/video/_static.html.erb            |  2 ++
 6 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/app/models/communication/block/template/video.rb b/app/models/communication/block/template/video.rb
index c69e4f07c..014131799 100644
--- a/app/models/communication/block/template/video.rb
+++ b/app/models/communication/block/template/video.rb
@@ -24,6 +24,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/services/video/provider/dailymotion.rb b/app/services/video/provider/dailymotion.rb
index aad0e19de..b88d1adcd 100644
--- a/app/services/video/provider/dailymotion.rb
+++ b/app/services/video/provider/dailymotion.rb
@@ -1,6 +1,7 @@
 class Video::Provider::Dailymotion < Video::Provider::Default
   DOMAINS = [
     'dailymotion.com', 
+    'www.dailymotion.com', 
     'dai.ly'
   ]
 
diff --git a/app/services/video/provider/default.rb b/app/services/video/provider/default.rb
index 2f28753fe..b36fc12dd 100644
--- a/app/services/video/provider/default.rb
+++ b/app/services/video/provider/default.rb
@@ -37,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
diff --git a/app/services/video/provider/peertube.rb b/app/services/video/provider/peertube.rb
index c170f54b2..3c43e1c23 100644
--- a/app/services/video/provider/peertube.rb
+++ b/app/services/video/provider/peertube.rb
@@ -7,13 +7,9 @@ class Video::Provider::Peertube < Video::Provider::Default
     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?
@@ -22,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/youtube.rb b/app/services/video/provider/youtube.rb
index b4e4e1a66..150978da2 100644
--- a/app/services/video/provider/youtube.rb
+++ b/app/services/video/provider/youtube.rb
@@ -24,4 +24,9 @@ class Video::Provider::Youtube < Video::Provider::Default
   def iframe_url
     "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}?autoplay=1"
+  end
 end
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 e0a5e480b..e915bf01c 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 %>
-- 
GitLab