Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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