Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
embed: Use youtube-nocookie.com
Browse files Browse the repository at this point in the history
YouTube supports embedding videos with "privacy enhanced mode" [1].
This is done by using https://www.youtube-nocookie.com/embed instead of
https://www.youtube.com/embed.

Override wagtails oembed finder to fixup the url we've got from YouTubes
oEmbed API.

We still load external content and need to trust Google, but it could be
verified, that no tracking cookies are sent around. This is even true,
when the video is actually played.

[1]: https://support.google.com/youtube/answer/171780

diff --git a/config/settings/base.py b/config/settings/base.py
index cd2857f..328b3c4 100644
--- a/config/settings/base.py
+++ b/config/settings/base.py
@@ -254,3 +254,5 @@ DOCS_ROOT = os.path.join(ROOT_DIR, 'docs/_build/html')
 WAGTAILAPI_LIMIT_MAX = 50

 DATA_UPLOAD_MAX_NUMBER_FIELDS=None
+
+WAGTAILEMBEDS_FINDERS = [ {  'class': 'mpicms.base.oembed' } ]
diff --git a/mpicms/base/oembed.py b/mpicms/base/oembed.py
new file mode 100644
index 0000000..db82820
--- /dev/null
+++ b/mpicms/base/oembed.py
@@ -0,0 +1,9 @@
+import wagtail.embeds.finders.oembed
+
+class OEmbedFinder(wagtail.embeds.finders.oembed.embed_finder_class):
+    def find_embed(self, url, max_width=None):
+        d = super().find_embed(url, max_width);
+        d['html'] = d['html'].replace('https://www.youtube.com/embed/', 'https://www.youtube-nocookie.com/embed/', 1)
+        return d
+
+embed_finder_class = OEmbedFinder
donald committed Mar 25, 2021
1 parent 73e2c78 commit f5cc5ad
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -254,3 +254,5 @@
WAGTAILAPI_LIMIT_MAX = 50

DATA_UPLOAD_MAX_NUMBER_FIELDS=None

WAGTAILEMBEDS_FINDERS = [ { 'class': 'mpicms.base.oembed' } ]
9 changes: 9 additions & 0 deletions mpicms/base/oembed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import wagtail.embeds.finders.oembed

class OEmbedFinder(wagtail.embeds.finders.oembed.embed_finder_class):
def find_embed(self, url, max_width=None):
d = super().find_embed(url, max_width);
d['html'] = d['html'].replace('https://www.youtube.com/embed/', 'https://www.youtube-nocookie.com/embed/', 1)
return d

embed_finder_class = OEmbedFinder

0 comments on commit f5cc5ad

Please sign in to comment.