From 58ed790b248a2846a14917328455e83b00d5d5ad Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Thu, 25 Mar 2021 18:31:03 +0100 Subject: [PATCH] embed: Use youtube-nocookie.com 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 --- config/settings/base.py | 2 ++ mpicms/base/oembed.py | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 mpicms/base/oembed.py 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 @@ 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